in sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpFileSystemProvider.java [1238:1301]
public void setAttribute(Path path, String view, String attr, Object value, LinkOption... options) throws IOException {
SftpPath p = toSftpPath(path);
SftpFileSystem fs = p.getFileSystem();
Collection<String> views = fs.supportedFileAttributeViews();
if (GenericUtils.isEmpty(views) || (!views.contains(view))) {
throw new UnsupportedOperationException(
"setAttribute(" + path + ")[" + view + ":" + attr + "=" + value + "] view " + view + " not supported: "
+ views);
}
SftpClient.Attributes attributes = new SftpClient.Attributes();
switch (attr) {
case IoUtils.LASTMOD_TIME_VIEW_ATTR:
attributes.modifyTime((int) ((FileTime) value).to(TimeUnit.SECONDS));
break;
case IoUtils.LASTACC_TIME_VIEW_ATTR:
attributes.accessTime((int) ((FileTime) value).to(TimeUnit.SECONDS));
break;
case IoUtils.CREATE_TIME_VIEW_ATTR:
attributes.createTime((int) ((FileTime) value).to(TimeUnit.SECONDS));
break;
case IoUtils.SIZE_VIEW_ATTR:
attributes.size(((Number) value).longValue());
break;
case IoUtils.PERMISSIONS_VIEW_ATTR: {
@SuppressWarnings("unchecked")
Set<PosixFilePermission> attrSet = (Set<PosixFilePermission>) value;
attributes.perms(attributesToPermissions(path, attrSet));
break;
}
case IoUtils.OWNER_VIEW_ATTR:
attributes.owner(((UserPrincipal) value).getName());
break;
case IoUtils.GROUP_VIEW_ATTR:
attributes.group(((GroupPrincipal) value).getName());
break;
case IoUtils.ACL_VIEW_ATTR: {
ValidateUtils.checkTrue("acl".equalsIgnoreCase(view), "ACL cannot be set via view=%s", view);
@SuppressWarnings("unchecked")
List<AclEntry> acl = (List<AclEntry>) value;
attributes.acl(acl);
break;
}
case IoUtils.REGFILE_VIEW_ATTR:
case IoUtils.DIRECTORY_VIEW_ATTR:
case IoUtils.SYMLINK_VIEW_ATTR:
case IoUtils.OTHERFILE_VIEW_ATTR:
case IoUtils.FILEKEY_VIEW_ATTR:
throw new UnsupportedOperationException(
"setAttribute(" + path + ")[" + view + ":" + attr + "=" + value + "] modification N/A");
default:
if (log.isTraceEnabled()) {
log.trace("setAttribute({})[{}] ignore {}:{}={}", fs, path, view, attr, value);
}
}
if (log.isDebugEnabled()) {
log.debug("setAttribute({}) {}: {}", fs, path, attributes);
}
try (SftpClient client = fs.getClient()) {
client.setStat(p.toString(), attributes);
}
}