use of ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver in project cyberduck by iterate-ch.
the class SynchronizationPathFilterTest method testAcceptDirectory.
@Test
public void testAcceptDirectory() throws Exception {
Session session = new NullSession(new Host(new TestProtocol()));
final SynchronizationPathFilter mirror = new SynchronizationPathFilter(new ComparePathFilter() {
@Override
public Comparison compare(Path file, Local local, final ProgressListener listener) {
return Comparison.equal;
}
}, new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.mirror);
assertTrue(mirror.accept(new Path("/p", EnumSet.of(Path.Type.directory)), null, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver in project cyberduck by iterate-ch.
the class SynchronizationPathFilterTest method testPrepare.
@Test
public void testPrepare() throws Exception {
final Path test = new Path("/t/a", EnumSet.of(Path.Type.file));
Session session = new NullSession(new Host(new TestProtocol()));
final NullLocal local = new NullLocal(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()) {
@Override
public boolean isSymbolicLink() {
return false;
}
@Override
public LocalAttributes attributes() {
return new LocalAttributes(this.getAbsolute()) {
@Override
public long getSize() {
return 1L;
}
};
}
@Override
public boolean isFile() {
return true;
}
@Override
public boolean exists() {
return true;
}
};
final SynchronizationPathFilter mirror = new SynchronizationPathFilter(new DefaultComparePathFilter(session, TimeZone.getDefault()), new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.mirror);
assertTrue(mirror.accept(test, local, new TransferStatus().exists(true)));
final TransferStatus status = mirror.prepare(test, local, new TransferStatus().exists(true), new DisabledProgressListener());
assertNotNull(status);
assertEquals(1L, status.getLength());
final SynchronizationPathFilter download = new SynchronizationPathFilter(new DefaultComparePathFilter(session, TimeZone.getDefault()), new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.download);
assertFalse(download.accept(test, local, new TransferStatus().exists(true)));
final SynchronizationPathFilter upload = new SynchronizationPathFilter(new DefaultComparePathFilter(session, TimeZone.getDefault()), new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.upload);
assertTrue(upload.accept(test, local, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver in project cyberduck by iterate-ch.
the class UploadTransfer method transfer.
@Override
public void transfer(final Session<?> source, final Session<?> destination, final Path file, final Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) throws BackgroundException {
if (log.isDebugEnabled()) {
log.debug(String.format("Transfer file %s with options %s", file, options));
}
if (local.isSymbolicLink()) {
final Symlink feature = source.getFeature(Symlink.class);
final UploadSymlinkResolver symlinkResolver = new UploadSymlinkResolver(feature, roots);
if (symlinkResolver.resolve(local)) {
// Make relative symbolic link
final String target = symlinkResolver.relativize(local.getAbsolute(), local.getSymlinkTarget().getAbsolute());
if (log.isDebugEnabled()) {
log.debug(String.format("Create symbolic link from %s to %s", file, target));
}
feature.symlink(file, target);
return;
}
}
if (file.isFile()) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Uploading {0}", "Status"), file.getName()));
// Transfer
final Upload upload = source.getFeature(Upload.class);
final Object reply = upload.upload(file, local, bandwidth, new UploadStreamListener(this, streamListener), segment, connectionCallback);
} else if (file.isDirectory()) {
if (!segment.isExists()) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Making directory {0}", "Status"), file.getName()));
final Directory feature = source.getFeature(Directory.class);
final AttributedList<Path> list = new AttributedList<>(cache.get(file.getParent()));
list.add(feature.mkdir(file, segment));
cache.put(file.getParent(), list);
segment.setComplete();
}
}
}
use of ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver in project cyberduck by iterate-ch.
the class UploadTransfer method filter.
@Override
public AbstractUploadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
if (log.isDebugEnabled()) {
log.debug(String.format("Filter transfer with action %s and options %s", action, options));
}
final Symlink symlink = source.getFeature(Symlink.class);
final UploadSymlinkResolver resolver = new UploadSymlinkResolver(symlink, roots);
if (options.temporary) {
options.withTemporary(source.getFeature(Write.class).temporary());
}
final Find find = new CachingFindFeature(cache, source.getFeature(Find.class, new DefaultFindFeature(source)));
final AttributesFinder attributes = new CachingAttributesFinderFeature(cache, source.getFeature(AttributesFinder.class, new DefaultAttributesFinderFeature(source)));
if (action.equals(TransferAction.resume)) {
return new ResumeFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
}
if (action.equals(TransferAction.rename)) {
return new RenameFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
}
if (action.equals(TransferAction.renameexisting)) {
return new RenameExistingFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
}
if (action.equals(TransferAction.skip)) {
return new SkipFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
}
if (action.equals(TransferAction.comparison)) {
return new CompareFilter(resolver, source, options, listener).withFinder(find).withAttributes(attributes);
}
return new OverwriteFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
}
Aggregations