PermissionUtils (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.util, class: PermissionUtils

# Class PermissionUtils

java.lang.Object
org.apache.tools.ant.util.PermissionUtils

public class PermissionUtils extends Object
Contains helper methods for dealing with `PosixFilePermission` or the traditional Unix mode representation of permissions.

Since:
  Ant 1.10.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `PermissionUtils.FileType`
  The supported types of files, maps to the `isFoo` methods in `BasicFileAttributes`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Set<PosixFilePermission>`
  `getPermissions(Resource r, boolean readFromLinkTarget, Function<Path, Set<PosixFilePermission>> posixNotSupportedFallback)`
  Reads permissions of a `Resource` - returns an empty set for unsupported resource types or file systems that don't support PosixFilePermissions and no fallback has been provided..
  `static Set<PosixFilePermission>`
  `getPermissions(Resource r, Function<Path, Set<PosixFilePermission>> posixNotSupportedFallback)`
  Reads permissions of a `Resource` - returns an empty set for unsupported resource types or file systems that don't support PosixFilePermissions and no fallback has been provided..
  `static int`
  `modeFromPermissions(Set<PosixFilePermission> permissions, PermissionUtils.FileType type)`
  Translates a set of permissions into a Unix stat(2) `st_mode` result.
  `static Set<PosixFilePermission>`
  `permissionsFromMode(int mode)`
  Translates a Unix stat(2) `st_mode` compatible value into a set of permissions.
  `static void`
  `setPermissions(Resource r, Set<PosixFilePermission> permissions, boolean actOnLinkTarget, Consumer<Path> posixNotSupportedCallback)`
  Sets permissions on a `Resource` - doesn't do anything for unsupported resource types.
  `static void`
  `setPermissions(Resource r, Set<PosixFilePermission> permissions, Consumer<Path> posixNotSupportedCallback)`
  Sets permissions on a `Resource` - doesn't do anything for unsupported resource types.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### modeFromPermissions

    public static int modeFromPermissions(Set<PosixFilePermission> permissions, PermissionUtils.FileType type)
    Translates a set of permissions into a Unix stat(2) `st_mode` result.
    Parameters:
      `permissions` - the permissions
      `type` - the file type
    Returns:
      the "mode"

  - ### permissionsFromMode

    public static Set<PosixFilePermission> permissionsFromMode(int mode)
    Translates a Unix stat(2) `st_mode` compatible value into a set of permissions.
    Parameters:
      `mode` - the "mode"
    Returns:
      set of permissions

  - ### setPermissions

    public static void setPermissions(Resource r, Set<PosixFilePermission> permissions, Consumer<Path> posixNotSupportedCallback) throws IOException
    Sets permissions on a `Resource` - doesn't do anything for unsupported resource types.

    Supported types are:

    - any `FileProvider`
    - `ArchiveResource`

    When applied to a `FileProvider` providing a symbolic link or Windows junction, the permission of the link target are set, not the permssions of the link itself.

    Parameters:
      `r` - the resource to set permissions for
      `permissions` - the permissions
      `posixNotSupportedCallback` - optional callback that is invoked for a file provider resource if the file-system holding the file doesn't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.
    Throws:
      `IOException` - if something goes wrong

  - ### setPermissions

    public static void setPermissions(Resource r, Set<PosixFilePermission> permissions, boolean actOnLinkTarget, Consumer<Path> posixNotSupportedCallback) throws IOException
    Sets permissions on a `Resource` - doesn't do anything for unsupported resource types.

    Supported types are:

    - any `FileProvider`
    - `ArchiveResource`
    Parameters:
      `r` - the resource to set permissions for
      `permissions` - the permissions
      `actOnLinkTarget` - whether to set the permissions on a symbolic link or Windows junction itself instead of the link's target. Only applies to resources that are `FileProvider`s.
      `posixNotSupportedCallback` - optional callback that is invoked for a file provider resource if the file-system holding the file doesn't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.
    Throws:
      `IOException` - if something goes wrong
    Since:
      Ant 1.10.16

  - ### getPermissions

    public static Set<PosixFilePermission> getPermissions(Resource r, Function<Path, Set<PosixFilePermission>> posixNotSupportedFallback) throws IOException
    Reads permissions of a `Resource` - returns an empty set for unsupported resource types or file systems that don't support PosixFilePermissions and no fallback has been provided..

    Supported types are:

    - any `FileProvider`
    - `ArchiveResource`

    When applied to a `FileProvider` providing a symbolic link or Windows junction, the permission of the link target are read, not the permssions of the link itself.

    Parameters:
      `r` - the resource to read permissions from
      `posixNotSupportedFallback` - optional fallback function to provide permissions for file system that don't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.
    Returns:
      the permissions
    Throws:
      `IOException` - if something goes wrong

  - ### getPermissions

    public static Set<PosixFilePermission> getPermissions(Resource r, boolean readFromLinkTarget, Function<Path, Set<PosixFilePermission>> posixNotSupportedFallback) throws IOException
    Reads permissions of a `Resource` - returns an empty set for unsupported resource types or file systems that don't support PosixFilePermissions and no fallback has been provided..

    Supported types are:

    - any `FileProvider`
    - `ArchiveResource`
    Parameters:
      `r` - the resource to read permissions from
      `readFromLinkTarget` - whether to read the permissions of a symbolic link or Windows junction itself instead of the link's target. Only applies to resources that are `FileProvider`s.
      `posixNotSupportedFallback` - optional fallback function to provide permissions for file system that don't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.
    Returns:
      the permissions
    Throws:
      `IOException` - if something goes wrong