throw new CloudsyncException("Can't set create, modify and access time of " + item.getTypeName() + " '" + item.getPath() + "'", e);
}
if (permissionType.equals(PermissionType.SET) || permissionType.equals(PermissionType.TRY)) {
final UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
Map<String, String[]> attributes = item.getAttributes();
for (String type : attributes.keySet()) {
GroupPrincipal group;
UserPrincipal principal;
try {
String[] values = attributes.get(type);
switch (type) {
case Item.ATTRIBUTE_POSIX:
PosixFileAttributeView posixView = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (posixView != null) {
group = lookupService.lookupPrincipalByGroupName(values[0]);
posixView.setGroup(group);
principal = lookupService.lookupPrincipalByName(values[1]);
posixView.setOwner(principal);
if (values.length > 2)
posixView.setPermissions(toPermissions(Integer.parseInt(values[2])));
} else {
String msg = "Can't restore 'posix' permissions on '" + item.getPath() + "'. They are not supported.";
if (permissionType.equals(PermissionType.TRY))
LOGGER.log(Level.WARNING, msg);
else
throw new CloudsyncException(msg + "\n try to run with '--permissions try'");
}
break;
case Item.ATTRIBUTE_DOS:
DosFileAttributeView dosView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (dosView != null) {
dosView.setArchive(Boolean.parseBoolean(values[0]));
dosView.setHidden(Boolean.parseBoolean(values[1]));
dosView.setReadOnly(Boolean.parseBoolean(values[2]));
dosView.setSystem(Boolean.parseBoolean(values[3]));
} else {
String msg = "Can't restore 'dos' permissions on '" + item.getPath() + "'. They are not supported.";
if (permissionType.equals(PermissionType.TRY))
LOGGER.log(Level.WARNING, msg);
else
throw new CloudsyncException(msg + "\n try to run with '--permissions try'");
}
break;
case Item.ATTRIBUTE_ACL:
AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (aclView != null) {
List<AclEntry> acls = aclView.getAcl();
for (int i = 0; i < values.length; i = i + 4) {
Builder aclEntryBuilder = AclEntry.newBuilder();
aclEntryBuilder.setType(AclEntryType.valueOf(values[i]));
aclEntryBuilder.setPrincipal(lookupService.lookupPrincipalByName(values[i + 1]));
Set<AclEntryFlag> flags = new HashSet<AclEntryFlag>();
for (String flag : StringUtils.splitPreserveAllTokens(values[i + 2], ",")) {
flags.add(AclEntryFlag.valueOf(flag));
}
if (flags.size() > 0)
aclEntryBuilder.setFlags(flags);
Set<AclEntryPermission> aclPermissions = new HashSet<AclEntryPermission>();
for (String flag : StringUtils.splitPreserveAllTokens(values[i + 3], ",")) {
aclPermissions.add(AclEntryPermission.valueOf(flag));
}
if (aclPermissions.size() > 0)
aclEntryBuilder.setPermissions(aclPermissions);
acls.add(aclEntryBuilder.build());
}
aclView.setAcl(acls);
} else {
String msg = "Can't restore 'acl' permissions on '" + item.getPath() + "'. They are not supported.";
if (permissionType.equals(PermissionType.TRY))
LOGGER.log(Level.WARNING, msg);
else
throw new CloudsyncException(msg + "\n try to run with '--permissions try'");
}
break;
case Item.ATTRIBUTE_OWNER:
FileOwnerAttributeView ownerView = Files.getFileAttributeView(path, FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (ownerView != null) {
principal = lookupService.lookupPrincipalByName(values[0]);
ownerView.setOwner(principal);
} else {
String msg = "Can't restore 'owner' permissions on '" + item.getPath() + "'. They are not supported.";
if (permissionType.equals(PermissionType.TRY))
LOGGER.log(Level.WARNING, msg);