/** * @return i.e. rwxrwxrwx (777) */ @Override public String toString() { return String.format("%s (%s)", this.getSymbol(), this.getMode()); }
public void setPermission(final Permission permission) throws AccessDeniedException { if(FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { try { Files.setPosixFilePermissions(Paths.get(path), PosixFilePermissions.fromString(permission.getSymbol())); } catch(IllegalArgumentException | IOException e) { throw new LocalAccessDeniedException(String.format("Cannot change permissions of %s", path), e); } } }
@Override public <T> T serialize(final Serializer dict) { dict.setStringForKey(this.getSymbol(), "Mask"); return dict.getSerialized(); }
@Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { try { Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(permission.getSymbol())); } catch(IllegalArgumentException e) { throw new LocalExceptionMappingService().map("Failure to write attributes of {0}", new IOException(e), file); } catch(IOException e) { throw new LocalExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }
@Override public void visit(final AttributedList<Path> list, final int index, final Path file) { if(l) { if(file.isSymbolicLink()) { console.printf("%n%sl%s\t%s\t%s -> %s%s", Ansi.ansi().bold(), file.attributes().getPermission().getSymbol(), formatter.getMediumFormat( file.attributes().getModificationDate()), file.getName(), file.getSymlinkTarget().getAbsolute(), Ansi.ansi().reset()); } else { console.printf("%n%s%s%s\t%s\t%s\t%s%s", Ansi.ansi().bold(), file.isDirectory() ? "d" : "-", file.attributes().getPermission().getSymbol(), formatter.getMediumFormat( file.attributes().getModificationDate()), StringUtils.isNotBlank(file.attributes().getRegion()) ? file.attributes().getRegion() : StringUtils.EMPTY, file.getName(), Ansi.ansi().reset()); } } else { console.printf("%n%s%s%s", Ansi.ansi().bold(), file.getName(), Ansi.ansi().reset()); } }