Search in sources :

Example 11 with PathAttributes

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;
}
Also used : Path(ch.cyberduck.core.Path) Write(ch.cyberduck.core.features.Write) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) LocalAccessDeniedException(ch.cyberduck.core.exception.LocalAccessDeniedException) LocalNotfoundException(ch.cyberduck.core.exception.LocalNotfoundException) NotfoundException(ch.cyberduck.core.exception.NotfoundException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) Redundancy(ch.cyberduck.core.features.Redundancy) Headers(ch.cyberduck.core.features.Headers) PathAttributes(ch.cyberduck.core.PathAttributes) Local(ch.cyberduck.core.Local) Encryption(ch.cyberduck.core.features.Encryption) Timestamp(ch.cyberduck.core.features.Timestamp) UnixPermission(ch.cyberduck.core.features.UnixPermission) ChecksumCompute(ch.cyberduck.core.io.ChecksumCompute) AclPermission(ch.cyberduck.core.features.AclPermission) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) MappingMimeTypeService(ch.cyberduck.core.MappingMimeTypeService) LocalAccessDeniedException(ch.cyberduck.core.exception.LocalAccessDeniedException)

Example 12 with PathAttributes

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;
}
Also used : ChecksumCompute(ch.cyberduck.core.io.ChecksumCompute) PathAttributes(ch.cyberduck.core.PathAttributes)

Example 13 with PathAttributes

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;
}
Also used : CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes)

Example 14 with PathAttributes

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) AttributedList(ch.cyberduck.core.AttributedList) PathAttributes(ch.cyberduck.core.PathAttributes) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Example 15 with PathAttributes

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());
}
Also used : PathAttributes(ch.cyberduck.core.PathAttributes) Test(org.junit.Test)

Aggregations

PathAttributes (ch.cyberduck.core.PathAttributes)291 Path (ch.cyberduck.core.Path)233 Test (org.junit.Test)200 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)176 IntegrationTest (ch.cyberduck.test.IntegrationTest)175 Delete (ch.cyberduck.core.features.Delete)153 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)143 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)139 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)74 ByteArrayInputStream (java.io.ByteArrayInputStream)55 StreamCopier (ch.cyberduck.core.io.StreamCopier)49 InputStream (java.io.InputStream)49 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)45 NotfoundException (ch.cyberduck.core.exception.NotfoundException)45 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)41 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)36 AttributedList (ch.cyberduck.core.AttributedList)34 Local (ch.cyberduck.core.Local)32 Host (ch.cyberduck.core.Host)31 OutputStream (java.io.OutputStream)31