use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class CryptoAttributesFeature method find.
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
final PathAttributes attributes = new PathAttributes(delegate.find(vault.encrypt(session, file, true), listener));
if (file.isFile()) {
attributes.setSize(vault.toCleartextSize(0L, attributes.getSize()));
}
if (file.isDirectory()) {
attributes.setSize(-1L);
}
if (attributes.getVersions().isEmpty()) {
return attributes;
}
final AttributedList<Path> versions = new AttributedList<>();
for (Path version : attributes.getVersions()) {
versions.add(vault.decrypt(session, version));
}
return new PathAttributes(attributes).withVersions(versions);
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class SingleTransferWorkerTest method testDownloadPrepareOverride.
@Test
public void testDownloadPrepareOverride() throws Exception {
final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
final NullLocal local = new NullLocal("l") {
@Override
public boolean exists() {
return true;
}
@Override
public boolean isDirectory() {
return true;
}
@Override
public boolean isFile() {
return false;
}
@Override
public AttributedList<Local> list() {
return AttributedList.emptyList();
}
};
final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), root, local) {
@Override
public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
if (file.equals(root)) {
assertTrue(segment.isExists());
} else {
assertFalse(segment.isExists());
}
}
@Override
public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
return super.filter(source, destination, action, listener).withAttributes(new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
});
}
};
final NullSession session = new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
final AttributedList<Path> children = new AttributedList<Path>();
children.add(child);
return children;
}
};
final SingleTransferWorker worker = new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
@Override
public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
if (item.remote.equals(root)) {
assertTrue(this.getCache().isCached(new TransferItem(root, local)));
}
super.transfer(new TransferItem(item.remote, new NullLocal("l")), action);
if (item.remote.equals(root)) {
assertFalse(this.getCache().isCached(new TransferItem(root, local)));
}
return null;
}
};
worker.run(session);
assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
assertTrue(worker.getCache().isEmpty());
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testTemporaryDirectoryUpload.
@Test
public void testTemporaryDirectoryUpload() throws Exception {
final Path file = new Path("/t", EnumSet.of(Path.Type.directory));
final AtomicBoolean found = new AtomicBoolean();
final AtomicBoolean moved = new AtomicBoolean();
final Find find = new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
if (f.equals(file)) {
found.set(true);
return true;
}
return false;
}
};
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
final Host host = new Host(new TestProtocol());
final NullSession session = new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Move.class)) {
return (T) new Move() {
@Override
public Path move(final Path f, final Path renamed, TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
assertFalse(moved.get());
assertEquals(file, f);
moved.set(true);
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
};
}
if (type.equals(Write.class)) {
return (T) new Write<Void>() {
@Override
public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
fail();
return null;
}
@Override
public Append append(final Path file, final TransferStatus status) {
fail();
return new Append(false);
}
};
}
return null;
}
};
final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, new UploadFilterOptions(host).withTemporary(true));
f.withFinder(find).withAttributes(attributes);
final TransferStatus status = f.prepare(file, new NullLocal("/t") {
@Override
public boolean isDirectory() {
return true;
}
@Override
public boolean isFile() {
return false;
}
}, new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(found.get());
assertNull(status.getRename().remote);
assertNull(status.getRename().local);
assertFalse(moved.get());
f.apply(file, new NullLocal("/t") {
@Override
public boolean isDirectory() {
return true;
}
}, new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(moved.get());
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class ResumeFilterTest method testAppendSmallerSize.
@Test
public void testAppendSmallerSize() throws Exception {
final Host host = new Host(new TestProtocol());
final NullSession session = new NullSession(host) {
@Override
public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws BackgroundException {
final AttributedList<Path> list = new AttributedList<>(Collections.singletonList(new Path(folder, "t", EnumSet.of(Path.Type.file)).withAttributes(new PathAttributes().withSize(2L))));
listener.chunk(folder, list);
return list;
}
};
final ResumeFilter f = new ResumeFilter(new DisabledUploadSymlinkResolver(), session, new UploadFilterOptions(host).withTemporary(true), new DefaultUploadFeature<>(new NullWriteFeature(session)));
final long size = 3L;
final Path t = new Path("t", EnumSet.of(Path.Type.file));
final NullLocal l = new NullLocal("t") {
@Override
public LocalAttributes attributes() {
return new LocalAttributes("t") {
@Override
public long getSize() {
return size;
}
};
}
@Override
public boolean isFile() {
return true;
}
@Override
public boolean exists() {
return true;
}
};
assertTrue(f.accept(t, l, new TransferStatus().exists(true)));
// Remaining length to transfer is 1
assertEquals(1L, f.prepare(t, l, new TransferStatus().exists(true), new DisabledProgressListener()).getLength());
// Skip first 2 bytes
assertEquals(2L, f.prepare(t, l, new TransferStatus().exists(true), new DisabledProgressListener()).getOffset());
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class SkipFilterTest method testNotFound.
@Test(expected = NotfoundException.class)
public void testNotFound() throws Exception {
SkipFilter f = new SkipFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
return AttributedList.emptyList();
}
});
f.withAttributes(new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
});
assertFalse(f.accept(new Path("a", EnumSet.of(Path.Type.file)), new NullLocal("a") {
@Override
public boolean exists() {
return false;
}
}, new TransferStatus().exists(true)));
}
Aggregations