Java Code Examples for java.nio.file.attribute.PosixFilePermissions#toString()

The following examples show how to use java.nio.file.attribute.PosixFilePermissions#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalAttributes.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Permission getPermission() {
    if(FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
        final BasicFileAttributes attributes;
        try {
            return new LocalPermission(PosixFilePermissions.toString(Files.readAttributes(Paths.get(path), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).permissions()));
        }
        catch(IOException e) {
            return Permission.EMPTY;
        }
    }
    return Permission.EMPTY;
}
 
Example 2
Source File: RawLocalFileSystem.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void loadPermissionInfoByNonNativeIO() {
  IOException e = null;
  try {
    java.nio.file.Path path = Paths.get(getPath().toUri());
    String permission = '-' + PosixFilePermissions.toString(Files.getPosixFilePermissions(path));
    setPermission(FsPermission.valueOf(permission));

    String owner = Files.getOwner(path).getName();
    String group = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).group().getName();
    // If on windows domain, token format is DOMAIN\\user and we want to
    // extract only the user name
    // same as to the group name
    if (Shell.WINDOWS) {
      owner = removeDomain(owner);
      group = removeDomain(group);
    }
    setOwner(owner);
    setGroup(group);
  } catch (IOException ioe) {
    e = ioe;
  } finally {
    if (e != null) {
      throw new RuntimeException("Error while running command to get " +
          "file permissions : " +
          StringUtils.stringifyException(e));
    }
  }
}
 
Example 3
Source File: Dir.java    From mdw with Apache License 2.0 5 votes vote down vote up
private void addDetails() throws IOException {
    Path path = Paths.get(this.path);
    this.absolutePath = path.toAbsolutePath().toString().replace('\\', '/');
    if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
        PosixFileAttributes attrs = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes();
        permissions = PosixFilePermissions.toString(attrs.permissions());
        UserPrincipal ownerPrincipal = attrs.owner();
        owner = ownerPrincipal.toString();
        UserPrincipal groupPrincipal = attrs.group();
        group = groupPrincipal.toString();
        size = path.toFile().length();
        numLinks = path.toFile().list().length + 2;
    }
}
 
Example 4
Source File: FileInfo.java    From mdw with Apache License 2.0 5 votes vote down vote up
private void addDetails() throws IOException {
    if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
        Path path = Paths.get(this.path);
        PosixFileAttributes attrs = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes();
        permissions = PosixFilePermissions.toString(attrs.permissions());
        UserPrincipal ownerPrincipal = attrs.owner();
        owner = ownerPrincipal.toString();
        UserPrincipal groupPrincipal = attrs.group();
        group = groupPrincipal.toString();
    }
}
 
Example 5
Source File: UnixSshFileSystemProvider.java    From jsch-nio with MIT License 5 votes vote down vote up
private String toMode( Set<PosixFilePermission> permissions ) {
    int[] values = new int[] { 4, 2, 1 };
    int[] sections = new int[3];

    String permissionsString = PosixFilePermissions.toString( permissions );
    for ( int i = 0; i < 9; i++ ) {
        if ( permissionsString.charAt( i ) != '-' ) {
            sections[i / 3] += values[i % 3];
        }
    }

    return "" + sections[0] + sections[1] + sections[2];
}
 
Example 6
Source File: LocalLocation.java    From twill with Apache License 2.0 4 votes vote down vote up
@Override
public String getPermissions() throws IOException {
  return PosixFilePermissions.toString(Files.getPosixFilePermissions(file.toPath()));
}
 
Example 7
Source File: ExtractPermissionsTest.java    From jarchivelib with Apache License 2.0 4 votes vote down vote up
private String getPosixPermissionsString(File file) throws IOException {
    return PosixFilePermissions.toString(Files.getPosixFilePermissions(file.toPath()));
}
 
Example 8
Source File: FileAttributes.java    From vespa with Apache License 2.0 votes vote down vote up
public String permissions() { return PosixFilePermissions.toString(attributes.permissions()); }