Skip to content

Commit

Permalink
Move files matching versioning criteria instead of delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Mar 29, 2023
1 parent 8c8fd05 commit 2f8e7af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public AttributedList<Path> list(final Path file, final ListProgressListener lis
* @param file File to edit
* @return Directory to save previous versions of file
*/
public static Path getVersionedFolder(final Path file) {
private static Path getVersionedFolder(final Path file) {
return new Path(file.getParent(), DIRECTORY_SUFFIX, EnumSet.of(Path.Type.directory));
}

Expand Down
51 changes: 37 additions & 14 deletions core/src/main/java/ch/cyberduck/core/worker/DeleteWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import ch.cyberduck.core.Filter;
import ch.cyberduck.core.Host;
import ch.cyberduck.core.ListProgressListener;
import ch.cyberduck.core.ListService;
import ch.cyberduck.core.LocaleFactory;
Expand All @@ -32,7 +31,9 @@
import ch.cyberduck.core.exception.ConnectionCanceledException;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Trash;
import ch.cyberduck.core.features.Versioning;
import ch.cyberduck.core.preferences.PreferencesFactory;
import ch.cyberduck.core.transfer.TransferAction;
import ch.cyberduck.core.transfer.TransferStatus;

import org.apache.logging.log4j.LogManager;
Expand All @@ -41,6 +42,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -112,28 +114,49 @@ public List<Path> run(final Session<?> session) throws BackgroundException {
if(this.isCanceled()) {
throw new ConnectionCanceledException();
}
recursive.putAll(this.compile(session.getHost(), delete, list, new WorkerListProgressListener(this, listener), file));
recursive.putAll(this.compile(delete, list, new WorkerListProgressListener(this, listener), file));
}
// Iterate again to delete any files that can be omitted when recursive operation is supported
if(delete.isRecursive()) {
recursive.keySet().removeIf(f -> recursive.keySet().stream().anyMatch(f::isChild));
}
delete.delete(recursive, prompt, new Delete.Callback() {
@Override
public void delete(final Path file) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Deleting {0}", "Status"), file.getName()));
callback.delete(file);
if(file.isDirectory()) {
if(delete.isRecursive()) {
files.stream().filter(f -> f.isChild(file)).forEach(callback::delete);
switch(session.getHost().getProtocol().getVersioningMode()) {
case custom:
if(TransferAction.versioning == TransferAction.forName(PreferencesFactory.get().getProperty("queue.upload.action"))) {
if(log.isDebugEnabled()) {
log.debug(String.format("Delete disabled using %s", TransferAction.versioning));
}
final Versioning versioning = session.getFeature(Versioning.class);
for(Iterator<Path> iter = recursive.keySet().iterator(); iter.hasNext(); ) {
final Path f = iter.next();
if(versioning.save(f)) {
if(log.isDebugEnabled()) {
log.debug(String.format("Skip deleting %s", f));
}
iter.remove();
}
}
break;
}
}
});
}
if(!recursive.isEmpty()) {
delete.delete(recursive, prompt, new Delete.Callback() {
@Override
public void delete(final Path file) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Deleting {0}", "Status"), file.getName()));
callback.delete(file);
if(file.isDirectory()) {
if(delete.isRecursive()) {
files.stream().filter(f -> f.isChild(file)).forEach(callback::delete);
}
}
}
});
}
return new ArrayList<>(recursive.keySet());
}

protected Map<Path, TransferStatus> compile(final Host host, final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException {
protected Map<Path, TransferStatus> compile(final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException {
// Compile recursive list
final Map<Path, TransferStatus> recursive = new LinkedHashMap<>();
if(file.isFile() || file.isSymbolicLink()) {
Expand Down Expand Up @@ -161,7 +184,7 @@ else if(file.isDirectory()) {
if(this.isCanceled()) {
throw new ConnectionCanceledException();
}
recursive.putAll(this.compile(host, delete, list, listener, child));
recursive.putAll(this.compile(delete, list, listener, child));
}
}
// Add parent after children
Expand Down

0 comments on commit 2f8e7af

Please sign in to comment.