Skip to content

Commit

Permalink
Merge pull request #16516 from iterate-ch/bugfix/GH-15489
Browse files Browse the repository at this point in the history
Review directory features requiring pseudo file based implementation
  • Loading branch information
ylangisc authored Nov 12, 2024
2 parents 9840c51 + 944c299 commit f553bee
Show file tree
Hide file tree
Showing 36 changed files with 40 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.InvalidFilenameException;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;

import java.text.MessageFormat;
Expand Down Expand Up @@ -53,11 +52,6 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
}
}

@Override
public Directory withWriter(final Write writer) {
return this;
}

@Override
public void preflight(final Path workdir, final String filename) throws BackgroundException {
if(!BoxTouchFeature.validate(filename)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import ch.cyberduck.core.brick.io.swagger.client.model.FileEntity;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -45,9 +44,4 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
throw new BrickExceptionMappingService().map("Cannot create folder {0}", e, folder);
}
}

@Override
public Directory<FileEntity> withWriter(final Write<FileEntity> writer) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import ch.cyberduck.core.brick.io.swagger.client.model.FileUploadPartEntity;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.Touch;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;

import java.io.IOException;
Expand Down Expand Up @@ -54,9 +53,4 @@ public Path touch(final Path file, final TransferStatus status) throws Backgroun
throw new DefaultIOExceptionMappingService().map("Cannot create {0}", e, file);
}
}

@Override
public Touch<FileEntity> withWriter(final Write<FileEntity> writer) {
return this;
}
}
4 changes: 3 additions & 1 deletion core/src/main/java/ch/cyberduck/core/features/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ default boolean isSupported(final Path workdir, final String filename) {
/**
* Retrieve write implementation for implementations using placeholder files for folders
*/
Directory<Reply> withWriter(Write<Reply> writer);
default Directory<Reply> withWriter(Write<Reply> writer) {
return this;
}

/**
* @throws AccessDeniedException Permission failure for target directory
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/ch/cyberduck/core/features/Touch.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ default boolean isSupported(final Path workdir, final String filename) {
}
}

Touch<Reply> withWriter(Write<Reply> writer);
default Touch<Reply> withWriter(Write<Reply> writer) {
return this;
}

/**
* @throws AccessDeniedException Permission failure for target directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@

import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;

public class NullDirectoryFeature implements Directory {
@Override
public Path mkdir(final Path folder, final TransferStatus status) throws BackgroundException {
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
}
10 changes: 2 additions & 8 deletions core/src/test/java/ch/cyberduck/core/worker/MoveWorkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Move;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.pool.SessionPool;
import ch.cyberduck.core.transfer.TransferStatus;

Expand Down Expand Up @@ -84,11 +83,6 @@ public boolean isRecursive() {
public Path mkdir(final Path folder, final TransferStatus status) {
return folder;
}

@Override
public Directory<Void> withWriter(final Write<Void> writer) {
return this;
}
};
}
if(type == Move.class) {
Expand Down Expand Up @@ -155,8 +149,8 @@ public AttributedList<Path> list(final Path file, final ListProgressListener lis
}
};
final MoveWorker worker = new MoveWorker(
Collections.singletonMap(new Path("/t", EnumSet.of(Path.Type.directory)), new Path("/t2", EnumSet.of(Path.Type.directory))),
new SessionPool.SingleSessionPool(session), PathCache.empty(), new DisabledProgressListener(), new DisabledLoginCallback());
Collections.singletonMap(new Path("/t", EnumSet.of(Path.Type.directory)), new Path("/t2", EnumSet.of(Path.Type.directory))),
new SessionPool.SingleSessionPool(session), PathCache.empty(), new DisabledProgressListener(), new DisabledLoginCallback());
final Collection<Path> targets = worker.run(session).values();
assertEquals(4, targets.size());
assertTrue(targets.contains(new Path("/t2", EnumSet.of(Path.Type.directory))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
log.debug("Write metadata {} for folder {}", directoryMetadataFile, folder);
new ContentWriter(session).write(directoryMetadataFile, directoryId.getBytes(StandardCharsets.UTF_8));
final Path intermediate = encrypt.getParent();
if(!find.find(intermediate)) {
delegate.mkdir(intermediate, new TransferStatus().withRegion(status.getRegion()));
if(!session._getFeature(Find.class).find(intermediate)) {
session._getFeature(Directory.class).mkdir(intermediate, new TransferStatus().withRegion(status.getRegion()));
}
// Write header
final FileHeader header = vault.getFileHeaderCryptor().create();
Expand All @@ -90,11 +90,6 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
delegate.preflight(workdir, filename);
}

@Override
public CryptoDirectoryV6Feature<Reply> withWriter(final Write<Reply> writer) {
return this;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CryptoDirectoryFeature{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
log.debug("Write metadata {} for folder {}", directoryMetadataFile, folder);
new ContentWriter(session).write(directoryMetadataFile, directoryId.getBytes(StandardCharsets.UTF_8));
final Path intermediate = encrypt.getParent();
if(!find.find(intermediate)) {
delegate.mkdir(intermediate, new TransferStatus().withRegion(status.getRegion()));
if(!session._getFeature(Find.class).find(intermediate)) {
session._getFeature(Directory.class).mkdir(intermediate, new TransferStatus().withRegion(status.getRegion()));
}
// Write header
final FileHeader header = vault.getFileHeaderCryptor().create();
Expand All @@ -96,11 +96,6 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
delegate.preflight(workdir, filename);
}

@Override
public CryptoDirectoryV7Feature<Reply> withWriter(final Write<Reply> writer) {
return this;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CryptoDirectoryFeature{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
proxy.preflight(workdir, filename);
}

@Override
public CryptoTouchFeature<Reply> withWriter(final Write<Reply> writer) {
return this;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CryptoTouchFeature{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import ch.cyberduck.core.cryptomator.features.CryptoChecksumCompute;
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.io.SHA256ChecksumCompute;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.core.vault.VaultCredentials;
Expand Down Expand Up @@ -52,11 +51,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(vault) || folder.isChild(vault));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand All @@ -72,11 +66,11 @@ public Directory withWriter(final Write writer) {
final RandomNonceGenerator nonces = new RandomNonceGenerator(cryptomator.getNonceSize());
assertNotNull(compute.compute(new NullInputStream(1025L), new TransferStatus().withLength(1025L).withHeader(header).withNonces(nonces)).hash);
assertNotEquals(compute.compute(new NullInputStream(1025L), new TransferStatus().withLength(1025L).withHeader(header).withNonces(nonces)),
compute.compute(new NullInputStream(1025L), new TransferStatus().withLength(1025L).withHeader(header).withNonces(nonces)));
compute.compute(new NullInputStream(1025L), new TransferStatus().withLength(1025L).withHeader(header).withNonces(nonces)));
assertNotNull(compute.compute(new NullInputStream(0L), new TransferStatus().withLength(0L).withHeader(header).withNonces(nonces)).hash);
assertEquals(compute.compute(new NullInputStream(0L), new TransferStatus().withHeader(header).withNonces(nonces)),
compute.compute(new NullInputStream(0L), new TransferStatus().withHeader(header).withNonces(nonces)));
assertNotEquals(compute.compute(new NullInputStream(0L), new TransferStatus().withHeader(header).withNonces(nonces)),
sha.compute(new NullInputStream(0L), new TransferStatus()));
sha.compute(new NullInputStream(0L), new TransferStatus()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import ch.cyberduck.core.TestProtocol;
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.core.vault.VaultCredentials;

Expand Down Expand Up @@ -54,11 +53,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Read;
import ch.cyberduck.core.features.Vault;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.preferences.PreferencesFactory;
import ch.cyberduck.core.serializer.PathDictionary;
import ch.cyberduck.core.transfer.TransferStatus;
Expand Down Expand Up @@ -424,11 +423,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand All @@ -453,11 +447,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down Expand Up @@ -503,11 +492,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down Expand Up @@ -558,11 +542,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
public boolean isSupported(final Path workdir, final String name) {
throw new UnsupportedOperationException();
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.TestProtocol;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.core.vault.VaultCredentials;

Expand Down Expand Up @@ -48,11 +47,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down Expand Up @@ -90,11 +84,6 @@ public Path mkdir(final Path folder, final TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import ch.cyberduck.core.features.Bulk;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.Transfer;
import ch.cyberduck.core.transfer.TransferItem;
import ch.cyberduck.core.transfer.TransferStatus;
Expand Down Expand Up @@ -59,11 +58,6 @@ public <T> T _getFeature(final Class<T> type) {
public Path mkdir(final Path folder, final TransferStatus status) {
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down Expand Up @@ -137,11 +131,6 @@ public <T> T _getFeature(final Class<T> type) {
public Path mkdir(final Path folder, final TransferStatus status) {
return folder;
}

@Override
public Directory withWriter(final Write writer) {
return this;
}
};
}
return super._getFeature(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.ConflictException;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.transfer.TransferStatus;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -90,11 +89,6 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
}
}

@Override
public Directory<VersionId> withWriter(final Write<VersionId> writer) {
return this;
}

@Override
public void preflight(final Path workdir, final String filename) throws BackgroundException {
if(workdir.isRoot() || (new DeepboxPathContainerService(session, fileid).isContainer(workdir) && !new DeepboxPathContainerService(session, fileid).isDocuments(workdir))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.InvalidFilenameException;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.preferences.HostPreferences;
import ch.cyberduck.core.sds.io.swagger.client.ApiException;
import ch.cyberduck.core.sds.io.swagger.client.api.NodesApi;
Expand Down Expand Up @@ -120,9 +119,4 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)).withFile(workdir);
}
}

@Override
public Directory<VersionId> withWriter(final Write<VersionId> writer) {
return this;
}
}
Loading

0 comments on commit f553bee

Please sign in to comment.