Skip to content

Commit

Permalink
Merge pull request #16541 from iterate-ch/feature/MD-22410-features
Browse files Browse the repository at this point in the history
Refactor file transfer filters to require features on instantiation
  • Loading branch information
dkocher authored Nov 18, 2024
2 parents 40249a7 + 42998e3 commit 3a7bdf6
Show file tree
Hide file tree
Showing 56 changed files with 555 additions and 600 deletions.
12 changes: 3 additions & 9 deletions core/src/main/java/ch/cyberduck/core/editor/EditSaveWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import ch.cyberduck.core.transfer.TransferPrompt;
import ch.cyberduck.core.transfer.TransferSpeedometer;
import ch.cyberduck.core.transfer.UploadTransfer;
import ch.cyberduck.core.transfer.upload.AbstractUploadFilter;
import ch.cyberduck.core.transfer.upload.UploadFilterOptions;
import ch.cyberduck.core.worker.SingleTransferWorker;
import ch.cyberduck.core.worker.Worker;
Expand Down Expand Up @@ -73,14 +72,9 @@ public TransferAction action(final Session<?> source,
final TransferPrompt prompt, final ListProgressListener listener) {
return TransferAction.overwrite;
}

@Override
public AbstractUploadFilter filter(final Session<?> session, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
return super.filter(session, destination, action, listener).withOptions(new UploadFilterOptions(host)
.withVersioning(PreferencesFactory.get().getBoolean("editor.upload.file.versioning"))
.withPermission(PreferencesFactory.get().getBoolean("editor.upload.permissions.change")));
}
};
}.withOptions(new UploadFilterOptions(bookmark)
.withVersioning(PreferencesFactory.get().getBoolean("editor.upload.file.versioning"))
.withPermission(PreferencesFactory.get().getBoolean("editor.upload.permissions.change")));
this.listener = listener;
}

Expand Down
15 changes: 0 additions & 15 deletions core/src/main/java/ch/cyberduck/core/features/UnixPermission.java
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.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Permission;
import ch.cyberduck.core.exception.BackgroundException;
Expand Down Expand Up @@ -57,18 +56,4 @@ default Permission getDefault(final EnumSet<Path.Type> type) {
}
return Permission.EMPTY;
}

/**
* @param file File on local disk
* @return Default mask to set for file
*/
default Permission getDefault(final Local file) {
if(preferences.getBoolean("queue.upload.permissions.default")) {
return this.getDefault(file.getType());
}
else {
// Read permissions from local file
return file.attributes().getPermission();
}
}
}
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
Loading

0 comments on commit 3a7bdf6

Please sign in to comment.