/** * @return i.e. rwxrwxrwx (777) */ @Override public String toString() { return String.format("%s (%s)", this.getSymbol(), this.getMode()); }
@Override public Permission getPermission() { return new FinderLocalPermission(super.getPermission().getMode()); }
public TerminalPreferences withDefaults(final CommandLine input) { if(input.hasOption(TerminalOptionsBuilder.Params.chmod.name())) { final Permission permission = new Permission(input.getOptionValue(TerminalOptionsBuilder.Params.chmod.name())); this.setDefault("queue.upload.permissions.change", String.valueOf(true)); this.setDefault("queue.upload.permissions.default", String.valueOf(true)); this.setDefault("queue.upload.permissions.file.default", permission.getMode()); } return this; }
@Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { if(failure != null) { if(log.isDebugEnabled()) { log.debug(String.format("Skip setting permission for %s due to previous failure %s", file, failure.getMessage())); } throw failure; } try { if(!session.getClient().sendSiteCommand(String.format("CHMOD %s %s", permission.getMode(), file.getAbsolute()))) { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } } catch(IOException e) { throw failure = new FTPExceptionMappingService().map("Cannot change permissions of {0}", e, file); } } }
@Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { final FileAttributes attr = new FileAttributes.Builder() .withPermissions(Integer.parseInt(permission.getMode(), 8)) .build(); try { session.sftp().setAttributes(file.getAbsolute(), attr); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }
copy.append(","); if(Permission.EMPTY != next.attributes().getPermission()) { copy.append(next.attributes().getPermission().getMode());
@Override protected int compareFirst(final Path p1, final Path p2) { if(Permission.EMPTY.equals(p1.attributes().getPermission()) && Permission.EMPTY.equals(p2.attributes().getPermission())) { return 0; } if(Permission.EMPTY.equals(p1.attributes().getPermission())) { return -1; } if(Permission.EMPTY.equals(p2.attributes().getPermission())) { return 1; } Integer perm1 = Integer.valueOf(p1.attributes().getPermission().getMode()); Integer perm2 = Integer.valueOf(p2.attributes().getPermission().getMode()); if(perm1 > perm2) { return ascending ? 1 : -1; } else if(perm1 < perm2) { return ascending ? -1 : 1; } return 0; } }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } session.sftp().makeDir(folder.getAbsolute(), attrs); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create folder {0}", e, folder); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new SFTPAttributesFinderFeature(session).find(folder)); }
private void setPermissions(final PermissionOverwrite permissions) { this.updateCheckbox(ownerr, permissions.user.read); this.updateCheckbox(ownerw, permissions.user.write); this.updateCheckbox(ownerx, permissions.user.execute); this.updateCheckbox(groupr, permissions.group.read); this.updateCheckbox(groupw, permissions.group.write); this.updateCheckbox(groupx, permissions.group.execute); this.updateCheckbox(otherr, permissions.other.read); this.updateCheckbox(otherw, permissions.other.write); this.updateCheckbox(otherx, permissions.other.execute); if(this.numberOfFiles() > 1) { permissionsField.setStringValue(permissions.toString()); octalField.setStringValue(permissions.getMode()); } else { final Permission permission = permissions.resolve(Permission.EMPTY); permissionsField.setStringValue(permission.toString()); octalField.setStringValue(permission.getMode()); } }