use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.
the class TerminalTransferFactory method create.
public Transfer create(final CommandLine input, final Host host, final Path remote, final List<TransferItem> items) throws BackgroundException {
final Transfer transfer;
final TerminalAction type = TerminalActionFinder.get(input);
if (null == type) {
throw new BackgroundException(LocaleFactory.localizedString("Unknown"), "Unknown transfer type");
}
switch(type) {
case download:
if (StringUtils.containsAny(remote.getName(), '*')) {
transfer = new DownloadTransfer(host, items, new DownloadGlobFilter(remote.getName()));
} else {
transfer = new DownloadTransfer(host, items);
}
if (input.hasOption(TerminalOptionsBuilder.Params.nochecksum.name())) {
final DownloadFilterOptions options = new DownloadFilterOptions(host);
options.checksum = Boolean.parseBoolean(input.getOptionValue(TerminalOptionsBuilder.Params.nochecksum.name()));
((DownloadTransfer) transfer).withOptions(options);
}
break;
case upload:
transfer = new UploadTransfer(host, items);
if (input.hasOption(TerminalOptionsBuilder.Params.nochecksum.name())) {
final UploadFilterOptions options = new UploadFilterOptions(host);
options.checksum = Boolean.parseBoolean(input.getOptionValue(TerminalOptionsBuilder.Params.nochecksum.name()));
((UploadTransfer) transfer).withOptions(options);
}
break;
case synchronize:
transfer = new SyncTransfer(host, items.iterator().next());
break;
default:
throw new BackgroundException(LocaleFactory.localizedString("Unknown"), String.format("Unknown transfer type %s", type.name()));
}
if (input.hasOption(TerminalOptionsBuilder.Params.throttle.name())) {
try {
transfer.setBandwidth(Float.parseFloat(input.getOptionValue(TerminalOptionsBuilder.Params.throttle.name())));
} catch (NumberFormatException ignore) {
//
}
}
return transfer;
}
use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.
the class OverwriteFilterTest method testComplete.
@Test
public void testComplete() throws Exception {
final HashMap<Path, Path> files = new HashMap<Path, Path>();
final Path source = new Path("a", EnumSet.of(Path.Type.file));
source.attributes().setSize(1L);
source.attributes().setPermission(new Permission(777));
final Long time = System.currentTimeMillis();
source.attributes().setModificationDate(time);
final boolean[] timestampWrite = new boolean[1];
final boolean[] permissionWrite = new boolean[1];
final Path target = new Path("a", EnumSet.of(Path.Type.file));
files.put(source, target);
final Host host = new Host(new TestProtocol());
OverwriteFilter f = new OverwriteFilter(new NullTransferSession(host), new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Timestamp.class)) {
return (T) new DefaultTimestampFeature() {
@Override
public void setTimestamp(final Path file, final TransferStatus status) {
assertEquals(time, status.getTimestamp());
timestampWrite[0] = true;
}
};
}
if (type.equals(UnixPermission.class)) {
return (T) new DefaultUnixPermissionFeature() {
@Override
public void setUnixOwner(final Path file, final String owner) {
throw new UnsupportedOperationException();
}
@Override
public void setUnixGroup(final Path file, final String group) {
throw new UnsupportedOperationException();
}
@Override
public Permission getUnixPermission(final Path file) {
throw new UnsupportedOperationException();
}
@Override
public void setUnixPermission(final Path file, final Permission permission) {
assertEquals(new Permission(777), permission);
permissionWrite[0] = true;
}
};
}
return super._getFeature(type);
}
}, files, new UploadFilterOptions(host).withPermission(true).withTimestamp(true));
final TransferStatus status = f.prepare(source, null, new TransferStatus(), new DisabledProgressListener());
f.complete(source, null, new TransferOptions(), status, new DisabledProgressListener());
assertFalse(permissionWrite[0]);
assertFalse(timestampWrite[0]);
status.setComplete();
f.complete(source, null, new TransferOptions(), status, new DisabledProgressListener());
assertTrue(permissionWrite[0]);
assertTrue(timestampWrite[0]);
}
use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.
the class UploadTransferTest method testUploadTemporaryName.
@Test
public void testUploadTemporaryName() throws Exception {
final Path test = new Path("/f", EnumSet.of(Path.Type.file));
final AtomicBoolean moved = new AtomicBoolean();
final Host host = new Host(new TestProtocol());
final Session session = new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Find.class)) {
return (T) new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
return true;
}
};
}
if (type.equals(Move.class)) {
return (T) new Move() {
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
assertEquals(test, renamed);
moved.set(true);
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
@Override
public boolean isSupported(final Path source, final Path target) {
return true;
}
};
}
if (type.equals(AttributesFinder.class)) {
return (T) new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
}
if (type.equals(Write.class)) {
return (T) new Write() {
@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 Write.Append(false);
}
};
}
return super._getFeature(type);
}
};
final AtomicBoolean set = new AtomicBoolean();
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
LocalTouchFactory.get().touch(local);
final Transfer transfer = new UploadTransfer(host, test, 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) {
segment.setComplete();
set.set(true);
}
@Override
public AbstractUploadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
return super.filter(source, destination, action, listener).withOptions(new UploadFilterOptions(host).withTemporary(true));
}
};
final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
fail();
return null;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
@Override
public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
return super.transfer(item, action);
}
};
worker.prepare(test, local, new TransferStatus().exists(true), TransferAction.overwrite);
assertNotNull(worker.getStatus().get(new TransferItem(test, local)));
assertNotNull(worker.getStatus().get(new TransferItem(test, local)).getRename());
worker.transfer(new TransferItem(test, local), TransferAction.overwrite);
assertTrue(set.get());
assertTrue(moved.get());
}
use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.
the class CryptoSFTPSingleTransferWorkerTest method testUpload.
@Test
public void testUpload() throws Exception {
final Path home = new SFTPHomeDirectoryService(session).find();
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
StringBuilder directoryname = new StringBuilder();
for (int i = 0; i < 10; i++) {
directoryname.append(new AlphanumericRandomStringService().random());
}
final Path dir1 = new Path(vault, directoryname.toString(), EnumSet.of(Path.Type.directory));
final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), directoryname.toString());
new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
final byte[] content = RandomUtils.nextBytes(62768);
final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile1 = new Local(localDirectory1, file1.getName());
final OutputStream out1 = localFile1.getOutputStream(false);
IOUtils.write(content, out1);
out1.close();
localFile1.attributes().setModificationDate(1513092263154L);
final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile2 = new Local(localDirectory1, file2.getName());
final OutputStream out2 = localFile2.getOutputStream(false);
IOUtils.write(content, out2);
out2.close();
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback() {
@Override
public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
return new VaultCredentials("test");
}
}));
PreferencesFactory.get().setProperty("factory.vault.class", CryptoVault.class.getName());
final Host host = new Host(new TestProtocol());
final Transfer t = new UploadTransfer(host, Collections.singletonList(new TransferItem(dir1, localDirectory1)), new NullFilter<>()).withOptions(new UploadFilterOptions(host).withTimestamp(true));
assertTrue(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()) {
}.run(session));
assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(dir1));
final PathAttributes attributes1 = new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(file1);
assertEquals(1513092263000L, attributes1.getModificationDate());
assertEquals(1513092263000L, new CryptoListService(session, new SFTPListService(session), cryptomator).list(dir1, new DisabledListProgressListener()).get(file1).attributes().getModificationDate());
assertEquals(content.length, attributes1.getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
final PathAttributes attributes2 = new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(file2);
assertEquals(content.length, attributes2.getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile1.delete();
localFile2.delete();
localDirectory1.delete();
}
Aggregations