use of ch.cyberduck.core.PathAttributes 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.PathAttributes in project cyberduck by iterate-ch.
the class ResumeFilter method accept.
@Override
public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException {
if (super.accept(file, local, parent)) {
if (local.isFile()) {
if (parent.isExists()) {
if (find.find(file)) {
final PathAttributes attributes = attribute.find(file);
if (attributes.getSize() == local.attributes().getSize()) {
if (Checksum.NONE != attributes.getChecksum()) {
final ChecksumCompute compute = ChecksumComputeFactory.get(attributes.getChecksum().algorithm);
if (compute.compute(local.getInputStream(), parent).equals(attributes.getChecksum())) {
if (log.isInfoEnabled()) {
log.info(String.format("Skip file %s with checksum %s", file, local.attributes().getChecksum()));
}
return false;
}
log.warn(String.format("Checksum mismatch for %s and %s", file, local));
} else {
if (log.isInfoEnabled()) {
log.info(String.format("Skip file %s with remote size %d", file, attributes.getSize()));
}
// No need to resume completed transfers
return false;
}
}
}
}
}
return true;
}
return false;
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class AttributesWorker method run.
@Override
public PathAttributes run(final Session<?> session) throws BackgroundException {
if (log.isDebugEnabled()) {
log.debug(String.format("Read latest attributes for file %s", file));
}
final AttributesFinder find = new CachingAttributesFinderFeature(cache, session.getFeature(AttributesFinder.class));
final PathAttributes attr = find.find(file);
if (log.isDebugEnabled()) {
log.debug(String.format("Return %s for file %s", attr, file));
}
return attr;
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class DecryptingListProgressListener method visit.
@Override
public void visit(final AttributedList<Path> list, final int index, final Path f) {
try {
f.getType().add(Path.Type.encrypted);
if (f.attributes().getVersions().isEmpty()) {
list.set(index, vault.decrypt(session, f));
} else {
final AttributedList<Path> versions = new AttributedList<>();
for (Path version : f.attributes().getVersions()) {
versions.add(vault.decrypt(session, version));
}
list.set(index, vault.decrypt(session, f).withAttributes(new PathAttributes(f.attributes()).withVersions(versions)));
}
} catch (BackgroundException e) {
log.error(String.format("Failure %s decrypting %s", e, f));
list.remove(index);
}
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class PathAttributesDictionaryTest method testSerialize.
@Test
public void testSerialize() {
PathAttributes attributes = new PathAttributes();
PathAttributes clone = new PathAttributesDictionary().deserialize(attributes.serialize(SerializerFactory.get()));
assertEquals(clone.getPermission(), attributes.getPermission());
assertEquals(clone.getModificationDate(), attributes.getModificationDate());
}
Aggregations