use of ch.cyberduck.core.features.AclPermission in project cyberduck by iterate-ch.
the class AbstractUploadFilter method complete.
@Override
public void complete(final Path file, final Local local, final TransferOptions options, final TransferStatus status, final ProgressListener listener) throws BackgroundException {
if (log.isDebugEnabled()) {
log.debug(String.format("Complete %s with status %s", file.getAbsolute(), status));
}
if (status.isComplete()) {
if (!Permission.EMPTY.equals(status.getPermission())) {
final UnixPermission feature = session.getFeature(UnixPermission.class);
if (feature != null) {
try {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing permission of {0} to {1}", "Status"), file.getName(), status.getPermission()));
feature.setUnixPermission(file, status.getPermission());
} catch (BackgroundException e) {
// Ignore
log.warn(e.getMessage());
}
}
}
if (!Acl.EMPTY.equals(status.getAcl())) {
final AclPermission feature = session.getFeature(AclPermission.class);
if (feature != null) {
try {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing permission of {0} to {1}", "Status"), file.getName(), status.getAcl()));
feature.setPermission(file, status.getAcl());
} catch (BackgroundException e) {
// Ignore
log.warn(e.getMessage());
}
}
}
if (status.getTimestamp() != null) {
if (!session.getFeature(Write.class).timestamp()) {
final Timestamp feature = session.getFeature(Timestamp.class);
if (feature != null) {
try {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing timestamp of {0} to {1}", "Status"), file.getName(), UserDateFormatterFactory.get().getShortFormat(status.getTimestamp())));
feature.setTimestamp(file, status);
} catch (BackgroundException e) {
// Ignore
log.warn(e.getMessage());
}
}
}
}
if (file.isFile()) {
if (status.getDisplayname().remote != null) {
final Move move = session.getFeature(Move.class);
if (log.isInfoEnabled()) {
log.info(String.format("Rename file %s to %s", file, status.getDisplayname().remote));
}
move.move(file, status.getDisplayname().remote, status, new Delete.DisabledCallback(), new DisabledConnectionCallback());
}
}
}
}
use of ch.cyberduck.core.features.AclPermission in project cyberduck by iterate-ch.
the class AbstractUploadFilter method prepare.
@Override
public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException {
if (log.isDebugEnabled()) {
log.debug(String.format("Prepare %s", file));
}
final TransferStatus status = new TransferStatus().hidden(!hidden.accept(file)).withLockId(parent.getLockId());
// Read remote attributes first
if (parent.isExists()) {
if (find.find(file)) {
status.setExists(true);
// Read remote attributes
final PathAttributes attributes = attribute.find(file);
status.setRemote(attributes);
} else {
// Look if there is directory or file that clashes with this upload
if (file.getType().contains(Path.Type.file)) {
if (find.find(new Path(file.getAbsolute(), EnumSet.of(Path.Type.directory)))) {
throw new AccessDeniedException(String.format("Cannot replace folder %s with file %s", file.getAbsolute(), local.getName()));
}
}
if (file.getType().contains(Path.Type.directory)) {
if (find.find(new Path(file.getAbsolute(), EnumSet.of(Path.Type.file)))) {
throw new AccessDeniedException(String.format("Cannot replace file %s with folder %s", file.getAbsolute(), local.getName()));
}
}
}
}
if (file.isFile()) {
// Set content length from local file
if (local.isSymbolicLink()) {
if (!symlinkResolver.resolve(local)) {
// Will resolve the symbolic link when the file is requested.
final Local target = local.getSymlinkTarget();
status.setLength(target.attributes().getSize());
}
// No file size increase for symbolic link to be created on the server
} else {
// Read file size from filesystem
status.setLength(local.attributes().getSize());
}
if (options.temporary) {
final Move feature = session.getFeature(Move.class);
final Path renamed = new Path(file.getParent(), MessageFormat.format(preferences.getProperty("queue.upload.file.temporary.format"), file.getName(), new AlphanumericRandomStringService().random()), file.getType());
if (feature.isSupported(file, renamed)) {
if (log.isDebugEnabled()) {
log.debug(String.format("Set temporary filename %s", renamed));
}
status.temporary(renamed, file);
}
}
status.withMime(new MappingMimeTypeService().getMime(file.getName()));
}
if (file.isDirectory()) {
status.setLength(0L);
}
if (options.permissions) {
final UnixPermission feature = session.getFeature(UnixPermission.class);
if (feature != null) {
if (status.isExists()) {
// Already set when reading attributes of file
status.setPermission(status.getRemote().getPermission());
} else {
status.setPermission(feature.getDefault(local));
}
} else {
// Setting target UNIX permissions in transfer status
status.setPermission(Permission.EMPTY);
}
}
if (options.acl) {
final AclPermission feature = session.getFeature(AclPermission.class);
if (feature != null) {
if (status.isExists()) {
progress.message(MessageFormat.format(LocaleFactory.localizedString("Getting permission of {0}", "Status"), file.getName()));
try {
status.setAcl(feature.getPermission(file));
} catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
status.setAcl(feature.getDefault(file, local));
}
} else {
status.setAcl(feature.getDefault(file, local));
}
} else {
// Setting target ACL in transfer status
status.setAcl(Acl.EMPTY);
}
}
if (options.timestamp) {
final Timestamp feature = session.getFeature(Timestamp.class);
if (feature != null) {
// Read timestamps from local file
status.setTimestamp(feature.getDefault(local));
} else {
if (1L != local.attributes().getModificationDate()) {
status.setTimestamp(local.attributes().getModificationDate());
}
}
}
if (options.metadata) {
final Headers feature = session.getFeature(Headers.class);
if (feature != null) {
if (status.isExists()) {
progress.message(MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), file.getName()));
try {
status.setMetadata(feature.getMetadata(file));
} catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
status.setMetadata(feature.getDefault(local));
}
} else {
status.setMetadata(feature.getDefault(local));
}
}
}
if (options.encryption) {
final Encryption feature = session.getFeature(Encryption.class);
if (feature != null) {
if (status.isExists()) {
progress.message(MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), file.getName()));
try {
status.setEncryption(feature.getEncryption(file));
} catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
status.setEncryption(feature.getDefault(file));
}
} else {
status.setEncryption(feature.getDefault(file));
}
}
}
if (options.redundancy) {
if (file.isFile()) {
final Redundancy feature = session.getFeature(Redundancy.class);
if (feature != null) {
if (status.isExists()) {
progress.message(MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), file.getName()));
try {
status.setStorageClass(feature.getClass(file));
} catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
status.setStorageClass(feature.getDefault());
}
} else {
status.setStorageClass(feature.getDefault());
}
}
}
}
if (options.checksum) {
if (file.isFile()) {
final ChecksumCompute feature = session.getFeature(Write.class).checksum(file, status);
if (feature != null) {
progress.message(MessageFormat.format(LocaleFactory.localizedString("Calculate checksum for {0}", "Status"), file.getName()));
try {
status.setChecksum(feature.compute(local.getInputStream(), status));
} catch (LocalAccessDeniedException e) {
// Ignore failure reading file when in sandbox when we miss a security scoped access bookmark.
// Lock for files is obtained only later in Transfer#pre
log.warn(e.getMessage());
}
}
}
}
return status;
}
use of ch.cyberduck.core.features.AclPermission in project cyberduck by iterate-ch.
the class ReadAclWorker method run.
@Override
public List<Acl.UserAndRole> run(final Session<?> session) throws BackgroundException {
final AclPermission feature = session.getFeature(AclPermission.class);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
final List<Acl.UserAndRole> updated = new ArrayList<>();
for (Path next : files) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
if (Acl.EMPTY == next.attributes().getAcl()) {
next.attributes().setAcl(feature.getPermission(next));
}
for (Acl.UserAndRole acl : next.attributes().getAcl().asList()) {
if (updated.contains(acl)) {
continue;
}
updated.add(acl);
}
}
return updated;
}
use of ch.cyberduck.core.features.AclPermission in project cyberduck by iterate-ch.
the class InfoController method initAcl.
/**
* Read grants in the background
*/
private void initAcl() {
this.setAcl(Collections.emptyList());
if (this.toggleAclSettings(false)) {
final AclPermission feature = session.getFeature(AclPermission.class);
aclAddButton.removeAllItems();
this.aclAddButton.addItemWithTitle(StringUtils.EMPTY);
this.aclAddButton.lastItem().setImage(IconCacheFactory.<NSImage>get().iconNamed("NSActionTemplate"));
for (Acl.User user : feature.getAvailableAclUsers()) {
this.aclAddButton.addItemWithTitle(user.getPlaceholder());
this.aclAddButton.lastItem().setAction(Foundation.selector("aclAddButtonClicked:"));
this.aclAddButton.lastItem().setTarget(this.id());
this.aclAddButton.lastItem().setRepresentedObject(user.getPlaceholder());
}
aclPermissionCellPrototype.removeAllItems();
for (Acl.Role permission : feature.getAvailableAclRoles(files)) {
aclPermissionCellPrototype.addItemWithObjectValue(NSString.stringWithString(permission.getName()));
}
this.background(new WorkerBackgroundAction<>(controller, session, new ReadAclWorker(files) {
@Override
public void cleanup(final List<Acl.UserAndRole> updated) {
if (updated != null) {
setAcl(updated);
}
toggleAclSettings(true);
}
}));
}
}
use of ch.cyberduck.core.features.AclPermission in project cyberduck by iterate-ch.
the class AbstractCopyFilter method complete.
@Override
public void complete(final Path source, final Local n, final TransferOptions options, final TransferStatus status, final ProgressListener listener) {
if (log.isDebugEnabled()) {
log.debug(String.format("Complete %s with status %s", source.getAbsolute(), status));
}
if (status.isComplete()) {
final Path target = files.get(source);
if (!Permission.EMPTY.equals(status.getPermission())) {
final UnixPermission feature = targetSession.getFeature(UnixPermission.class);
if (feature != null) {
if (!Permission.EMPTY.equals(status.getPermission())) {
try {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing permission of {0} to {1}", "Status"), target.getName(), status.getPermission()));
feature.setUnixPermission(target, status.getPermission());
} catch (BackgroundException e) {
// Ignore
log.warn(e.getMessage());
}
}
}
}
if (!Acl.EMPTY.equals(status.getAcl())) {
final AclPermission feature = targetSession.getFeature(AclPermission.class);
if (feature != null) {
try {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing permission of {0} to {1}", "Status"), target.getName(), status.getAcl()));
feature.setPermission(target, status.getAcl());
} catch (BackgroundException e) {
// Ignore
log.warn(e.getMessage());
}
}
}
if (status.getTimestamp() != null) {
final Timestamp timestamp = targetSession.getFeature(Timestamp.class);
if (timestamp != null) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing timestamp of {0} to {1}", "Status"), target.getName(), UserDateFormatterFactory.get().getShortFormat(status.getTimestamp())));
try {
timestamp.setTimestamp(target, status);
} catch (BackgroundException e) {
// Ignore
log.warn(e.getMessage());
}
}
}
}
}
Aggregations