Skip to content

Commit

Permalink
Require features on instantiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Nov 13, 2024
1 parent 386cde5 commit 9e5b071
Show file tree
Hide file tree
Showing 51 changed files with 556 additions and 539 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.DisabledProgressListener;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.LocalFactory;
import ch.cyberduck.core.ProtocolFactory;
Expand Down Expand Up @@ -55,7 +54,7 @@ public ProfilesSynchronizeWorker(final ProfilesFinder.Visitor visitor) {
*/
public ProfilesSynchronizeWorker(final ProtocolFactory registry, final ProfilesFinder.Visitor visitor) {
this(registry, LocalFactory.get(SupportDirectoryFinderFactory.get().find(),
PreferencesFactory.get().getProperty("profiles.folder.name")), visitor);
PreferencesFactory.get().getProperty("profiles.folder.name")), visitor);
}

public ProfilesSynchronizeWorker(final ProtocolFactory registry, final Local directory, final ProfilesFinder.Visitor visitor) {
Expand Down Expand Up @@ -127,6 +126,6 @@ public Set<ProfileDescription> run(final Session<?> session) throws BackgroundEx
}

protected CompareFilter filter(final Session<?> session) {
return new CompareFilter(new DisabledDownloadSymlinkResolver(), session, new DisabledProgressListener());
return new CompareFilter(new DisabledDownloadSymlinkResolver(), session);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
import ch.cyberduck.core.DisabledListProgressListener;
import ch.cyberduck.core.DisabledProgressListener;
import ch.cyberduck.core.Filter;
import ch.cyberduck.core.ListProgressListener;
import ch.cyberduck.core.ListService;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.PathAttributes;
import ch.cyberduck.core.ProtocolFactory;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Find;
import ch.cyberduck.core.features.Read;
import ch.cyberduck.core.local.TemporaryFileService;
import ch.cyberduck.core.local.TemporaryFileServiceFactory;
Expand Down Expand Up @@ -66,7 +63,7 @@ public RemoteProfilesFinder(final Session<?> session) {
}

public RemoteProfilesFinder(final ProtocolFactory protocols, final Session<?> session) {
this(protocols, session, new CompareFilter(new DisabledDownloadSymlinkResolver(), session, new DisabledProgressListener()));
this(protocols, session, new CompareFilter(new DisabledDownloadSymlinkResolver(), session));
}

public RemoteProfilesFinder(final ProtocolFactory protocols, final Session<?> session, final TransferPathFilter comparison) {
Expand All @@ -87,20 +84,7 @@ public Set<ProfileDescription> find(final Visitor visitor) throws BackgroundExce
protected Local initialize() throws ConcurrentException {
try {
final Local local = temp.create("profiles", file);
final TransferPathFilter filter = comparison
.withFinder(new Find() {
@Override
public boolean find(final Path file, final ListProgressListener listener) {
return true;
}
})
.withAttributes(new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
});
if(filter.accept(file, local, new TransferStatus().exists(true))) {
if(comparison.accept(file, local, new TransferStatus().exists(true), new DisabledProgressListener())) {
final Read read = session.getFeature(Read.class);
log.info("Download profile {}", file);
// Read latest version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.ProgressListener;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Find;
import ch.cyberduck.core.transfer.TransferItem;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collections;
import java.util.Map;

public class CachingComparePathFilter implements ComparePathFilter {
private static final Logger log = LogManager.getLogger(CachingComparePathFilter.class);

private Map<TransferItem, Comparison> cache = Collections.emptyMap();

private final Map<TransferItem, Comparison> cache;
private final DefaultComparePathFilter delegate;

public CachingComparePathFilter(final DefaultComparePathFilter delegate) {
public CachingComparePathFilter(final Map<TransferItem, Comparison> cache, final DefaultComparePathFilter delegate) {
this.cache = cache;
this.delegate = delegate;
}

Expand All @@ -60,26 +57,4 @@ public Comparison get(final TransferItem item) {
}
return Comparison.unknown;
}

public void reset() {
cache.clear();
}

@Override
public CachingComparePathFilter withFinder(final Find finder) {
delegate.withFinder(finder);
return this;
}

@Override
public CachingComparePathFilter withAttributes(final AttributesFinder attribute) {
delegate.withAttributes(attribute);
return this;
}

@Override
public CachingComparePathFilter withCache(final Map<TransferItem, Comparison> cache) {
this.cache = cache;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,7 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.ProgressListener;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Find;
import ch.cyberduck.core.transfer.TransferItem;

import java.util.Map;

public interface ComparePathFilter {
Comparison compare(Path file, Local local, ProgressListener listener) throws BackgroundException;

default ComparePathFilter withFinder(Find finder) {
return this;
}

default ComparePathFilter withAttributes(AttributesFinder attribute) {
return this;
}

default ComparePathFilter withCache(Map<TransferItem, Comparison> cache) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,32 @@
import ch.cyberduck.core.io.Checksum;
import ch.cyberduck.core.io.ChecksumComputeFactory;
import ch.cyberduck.core.io.HashAlgorithm;
import ch.cyberduck.core.shared.DefaultAttributesFinderFeature;
import ch.cyberduck.core.shared.DefaultFindFeature;
import ch.cyberduck.core.transfer.TransferItem;
import ch.cyberduck.core.transfer.TransferStatus;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.MessageFormat;
import java.util.Map;

public class DefaultComparePathFilter implements ComparePathFilter {
private static final Logger log = LogManager.getLogger(DefaultComparePathFilter.class);

private Find finder;
private AttributesFinder attribute;

private final Find finder;
private final AttributesFinder attribute;
private final ComparisonService comparison;

public DefaultComparePathFilter(final Session<?> session) {
this.finder = session.getFeature(Find.class, new DefaultFindFeature(session));
this.attribute = session.getFeature(AttributesFinder.class, new DefaultAttributesFinderFeature(session));
this.comparison = session.getFeature(ComparisonService.class);
this(session, session.getFeature(Find.class), session.getFeature(AttributesFinder.class));
}

@Override
public ComparePathFilter withFinder(final Find finder) {
this.finder = finder;
return this;
public DefaultComparePathFilter(final Session<?> session, final Find finder, final AttributesFinder attribute) {
this(finder, attribute, session.getFeature(ComparisonService.class));
}

@Override
public ComparePathFilter withAttributes(final AttributesFinder attribute) {
public DefaultComparePathFilter(final Find finder, final AttributesFinder attribute, final ComparisonService comparison) {
this.finder = finder;
this.attribute = attribute;
return this;
}

@Override
public ComparePathFilter withCache(final Map<TransferItem, Comparison> cache) {
return this;
this.comparison = comparison;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ public TransferAction action(final Session<?> source, final Session<?> destinati
public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
final DownloadFilterOptions options = new DownloadFilterOptions(session.getHost());
options.segments = false;
return new CompareFilter(new DisabledDownloadSymlinkResolver(), source, options, listener, new DefaultComparePathFilter(source) {
return new CompareFilter(new DisabledDownloadSymlinkResolver(), source, new Find() {
@Override
public boolean find(final Path file, final ListProgressListener listener) {
return true;
}
}, new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
}, new DefaultComparePathFilter(source) {
@Override
public Comparison compare(final Path file, final Local local, final ProgressListener listener) throws BackgroundException {
switch(super.compare(file, local, listener)) {
Expand All @@ -98,17 +108,7 @@ public Comparison compare(final Path file, final Local local, final ProgressList
// Comparison may return local when no checksum to compare is avavailable
return Comparison.remote;
}
}).withFinder(new Find() {
@Override
public boolean find(final Path file, final ListProgressListener listener) {
return true;
}
}).withAttributes(new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
});
}, options);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public TransferPathFilter filter(final Session<?> source, final Session<?> desti
final AttributesFinder attributes = new CachingAttributesFinderFeature(destination, cache,
destination.getFeature(AttributesFinder.class, new DefaultAttributesFinderFeature(destination)));
if(action.equals(TransferAction.comparison)) {
return new ChecksumFilter(source, destination, mapping).withFinder(find).withAttributes(attributes);
return new ChecksumFilter(source, destination, mapping, find, attributes);
}
return new OverwriteFilter(source, destination, mapping).withFinder(find).withAttributes(attributes);
return new OverwriteFilter(source, destination, mapping, find, attributes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Bulk;
import ch.cyberduck.core.features.Download;
import ch.cyberduck.core.features.Find;
import ch.cyberduck.core.filter.DownloadDuplicateFilter;
import ch.cyberduck.core.filter.DownloadRegexFilter;
import ch.cyberduck.core.io.BandwidthThrottle;
Expand All @@ -34,7 +33,6 @@
import ch.cyberduck.core.local.features.Symlink;
import ch.cyberduck.core.preferences.PreferencesFactory;
import ch.cyberduck.core.shared.DefaultAttributesFinderFeature;
import ch.cyberduck.core.shared.DefaultFindFeature;
import ch.cyberduck.core.transfer.download.AbstractDownloadFilter;
import ch.cyberduck.core.transfer.download.CompareFilter;
import ch.cyberduck.core.transfer.download.DownloadFilterOptions;
Expand Down Expand Up @@ -144,36 +142,33 @@ && new DownloadSymlinkResolver(roots).resolve(directory)) {
public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
log.debug("Filter transfer with action {} and options {}", action, options);
final DownloadSymlinkResolver resolver = new DownloadSymlinkResolver(roots);
final Find find;
final AttributesFinder attributes;
if(roots.size() > 1 || roots.stream().filter(item -> item.remote.isDirectory()).findAny().isPresent()) {
find = new CachingFindFeature(source, cache, source.getFeature(Find.class, new DefaultFindFeature(source)));
attributes = new CachingAttributesFinderFeature(source, cache, source.getFeature(AttributesFinder.class, new DefaultAttributesFinderFeature(source)));
}
else {
find = new CachingFindFeature(source, cache, source.getFeature(Find.class));
attributes = new CachingAttributesFinderFeature(source, cache, source.getFeature(AttributesFinder.class));
}
log.debug("Determined features {} and {}", find, attributes);
log.debug("Determined feature {}", attributes);
if(action.equals(TransferAction.resume)) {
return new ResumeFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
return new ResumeFilter(resolver, source, attributes, options);
}
if(action.equals(TransferAction.rename)) {
return new RenameFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
return new RenameFilter(resolver, source, attributes, options);
}
if(action.equals(TransferAction.renameexisting)) {
return new RenameExistingFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
return new RenameExistingFilter(resolver, source, attributes, options);
}
if(action.equals(TransferAction.skip)) {
return new SkipFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
return new SkipFilter(resolver, source, attributes, options);
}
if(action.equals(TransferAction.trash)) {
return new TrashFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
return new TrashFilter(resolver, source, attributes, options);
}
if(action.equals(TransferAction.comparison)) {
return new CompareFilter(resolver, source, options, listener).withFinder(find).withAttributes(attributes);
return new CompareFilter(resolver, source, options);
}
return new OverwriteFilter(resolver, source, options).withFinder(find).withAttributes(attributes);
return new OverwriteFilter(resolver, source, attributes, options);
}

@Override
Expand Down
27 changes: 10 additions & 17 deletions core/src/main/java/ch/cyberduck/core/transfer/SyncTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ public class SyncTransfer extends Transfer {
private TransferAction action;

private Cache<Path> cache
= new PathCache(PreferencesFactory.get().getInteger("transfer.cache.size"));
= new PathCache(PreferencesFactory.get().getInteger("transfer.cache.size"));

private final Map<TransferItem, Comparison> comparisons = Collections.synchronizedMap(new LRUMap<>(
PreferencesFactory.get().getInteger("transfer.cache.size")));
PreferencesFactory.get().getInteger("transfer.cache.size")));

public SyncTransfer(final Host host, final TransferItem item) {
this(host, item, TransferAction.callback);
}

public SyncTransfer(final Host host, final TransferItem item, final TransferAction action) {
super(host, Collections.singletonList(item),
new BandwidthThrottle(PreferencesFactory.get().getFloat("queue.upload.bandwidth.bytes")));
new BandwidthThrottle(PreferencesFactory.get().getFloat("queue.upload.bandwidth.bytes")));
this.upload = new UploadTransfer(host, roots).withCache(cache);
this.download = new DownloadTransfer(host, roots).withCache(cache);
this.item = item;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void setBandwidth(float bytesPerSecond) {
@Override
public String getName() {
return this.getRoot().remote.getName()
+ " \u2194 " /*left-right arrow*/ + this.getRoot().local.getName();
+ " \u2194 " /*left-right arrow*/ + this.getRoot().local.getName();
}

@Override
Expand All @@ -149,22 +149,15 @@ public Long getTransferred() {
public TransferPathFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
log.debug("Filter transfer with action {}", action);
final Find find = new CachingFindFeature(source, cache,
source.getFeature(Find.class, new DefaultFindFeature(source)));
source.getFeature(Find.class, new DefaultFindFeature(source)));
final AttributesFinder attributes = new CachingAttributesFinderFeature(source, cache,
source.getFeature(AttributesFinder.class, new DefaultAttributesFinderFeature(source)));
source.getFeature(AttributesFinder.class, new DefaultAttributesFinderFeature(source)));
// Set chosen action (upload, download, mirror) from prompt
comparison = new CachingComparePathFilter(new DefaultComparePathFilter(source))
.withCache(comparisons)
.withAttributes(attributes)
.withFinder(find);
comparison = new CachingComparePathFilter(comparisons, new DefaultComparePathFilter(source, find, attributes));
return new SynchronizationPathFilter(comparison,
download.filter(source, destination, TransferAction.overwrite, listener)
.withAttributes(attributes)
.withFinder(find),
upload.filter(source, destination, TransferAction.overwrite, listener)
.withAttributes(attributes)
.withFinder(find),
action
download.filter(source, destination, TransferAction.overwrite, listener),
upload.filter(source, destination, TransferAction.overwrite, listener),
action
);
}

Expand Down
Loading

0 comments on commit 9e5b071

Please sign in to comment.