in sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java [2689:2757]
protected void setFileAttributes(
Path file, Map<String, ?> attributes, LinkOption... options)
throws IOException {
Set<String> unsupported = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
// Cannot use forEach because of the potential IOException being thrown
for (Map.Entry<String, ?> ae : attributes.entrySet()) {
String attribute = ae.getKey();
Object value = ae.getValue();
String view = null;
switch (attribute) {
case IoUtils.SIZE_VIEW_ATTR: {
long newSize = ((Number) value).longValue();
SftpFileSystemAccessor accessor = getFileSystemAccessor();
Set<OpenOption> openOptions = new HashSet<>();
openOptions.add(StandardOpenOption.WRITE);
if (!IoUtils.followLinks(options)) {
openOptions.add(LinkOption.NOFOLLOW_LINKS);
}
try (SeekableByteChannel channel = accessor.openFile(this, null, file, null, openOptions)) {
channel.truncate(newSize);
accessor.closeFile(this, null, file, null, channel, openOptions);
}
continue;
}
case IoUtils.USERID_VIEW_ATTR:
view = "unix";
break;
case IoUtils.GROUPID_VIEW_ATTR:
view = "unix";
break;
case IoUtils.OWNER_VIEW_ATTR:
view = "posix";
value = toUser(file, (UserPrincipal) value);
break;
case IoUtils.GROUP_VIEW_ATTR:
view = "posix";
value = toGroup(file, (GroupPrincipal) value);
break;
case IoUtils.PERMISSIONS_VIEW_ATTR:
view = "posix";
break;
case IoUtils.ACL_VIEW_ATTR:
view = "acl";
break;
case IoUtils.CREATE_TIME_VIEW_ATTR:
view = "basic";
break;
case IoUtils.LASTMOD_TIME_VIEW_ATTR:
view = "basic";
break;
case IoUtils.LASTACC_TIME_VIEW_ATTR:
view = "basic";
break;
case IoUtils.EXTENDED_VIEW_ATTR:
view = "extended";
break;
default: // ignored
}
if ((GenericUtils.length(view) > 0) && (value != null)) {
try {
setFileAttribute(file, view, attribute, value, options);
} catch (Exception e) {
handleSetFileAttributeFailure(file, view, attribute, value, unsupported, e);
}
}
}
handleUnsupportedAttributes(unsupported);
}