Skip to content

Commit 71c2740

Browse files
committed
Add writer as parameter to allow wrapping with encryption feature.
1 parent 5cf609e commit 71c2740

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+290
-270
lines changed

s3/src/main/java/ch/cyberduck/core/s3/S3DirectoryFeature.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ public class S3DirectoryFeature implements Directory<StorageObject> {
4242
private final S3AccessControlListFeature acl;
4343
private final PathContainerService containerService;
4444

45-
private Write<StorageObject> writer;
46-
47-
public S3DirectoryFeature(final S3Session session, final Write<StorageObject> writer, final S3AccessControlListFeature acl) {
45+
public S3DirectoryFeature(final S3Session session, final S3AccessControlListFeature acl) {
4846
this.session = session;
49-
this.writer = writer;
5047
this.containerService = session.getFeature(PathContainerService.class);
5148
this.acl = acl;
5249
}
5350

5451
@Override
55-
public Path mkdir(final Path folder, final TransferStatus status) throws BackgroundException {
52+
public Path mkdir(final Write<StorageObject> writer, final Path folder, final TransferStatus status) throws BackgroundException {
5653
if(containerService.isContainer(folder)) {
5754
final S3BucketCreateService service = new S3BucketCreateService(session);
5855
service.create(folder, StringUtils.isBlank(status.getRegion()) ?
@@ -62,7 +59,7 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
6259
else {
6360
final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType());
6461
type.add(Path.Type.placeholder);
65-
return new S3TouchFeature(session, acl).withWriter(writer).touch(folder
62+
return new S3TouchFeature(session, acl).touch(writer, folder
6663
.withType(type), status
6764
// Add placeholder object
6865
.setMime(MIMETYPE)
@@ -84,9 +81,4 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
8481
}
8582
}
8683

87-
@Override
88-
public S3DirectoryFeature withWriter(final Write<StorageObject> writer) {
89-
this.writer = writer;
90-
return this;
91-
}
9284
}

s3/src/main/java/ch/cyberduck/core/s3/S3MoveFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import ch.cyberduck.core.features.Delete;
2828
import ch.cyberduck.core.features.Directory;
2929
import ch.cyberduck.core.features.Move;
30+
import ch.cyberduck.core.features.Write;
3031
import ch.cyberduck.core.io.DisabledStreamListener;
3132
import ch.cyberduck.core.transfer.TransferStatus;
3233

@@ -89,7 +90,7 @@ public Path move(final Path source, final Path renamed, final TransferStatus sta
8990
catch(NotfoundException e) {
9091
if(source.getType().contains(Path.Type.placeholder)) {
9192
// No placeholder object to copy, create a new one at the target
92-
target = session.getFeature(Directory.class).mkdir(renamed, status);
93+
target = session.getFeature(Directory.class).mkdir(session.getFeature(Write.class), renamed, status);
9394
}
9495
else {
9596
throw e;

s3/src/main/java/ch/cyberduck/core/s3/S3Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public <T> T _getFeature(final Class<T> type) {
403403
return (T) new S3ThresholdUploadService(this, acl);
404404
}
405405
if(type == Directory.class) {
406-
return (T) new S3DirectoryFeature(this, new S3WriteFeature(this, acl), acl);
406+
return (T) new S3DirectoryFeature(this, acl);
407407
}
408408
if(type == Move.class) {
409409
return (T) new S3MoveFeature(this, acl);

s3/src/main/java/ch/cyberduck/core/s3/S3TouchFeature.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import ch.cyberduck.core.Path;
2323
import ch.cyberduck.core.exception.AccessDeniedException;
2424
import ch.cyberduck.core.exception.BackgroundException;
25+
import ch.cyberduck.core.features.Write;
2526
import ch.cyberduck.core.shared.DefaultTouchFeature;
2627
import ch.cyberduck.core.transfer.TransferStatus;
2728

@@ -36,13 +37,13 @@ public class S3TouchFeature extends DefaultTouchFeature<StorageObject> {
3637
private final S3Session session;
3738

3839
public S3TouchFeature(final S3Session session, final S3AccessControlListFeature acl) {
39-
super(new S3WriteFeature(session, acl));
40+
super(session);
4041
this.session = session;
4142
}
4243

4344
@Override
44-
public Path touch(final Path file, final TransferStatus status) throws BackgroundException {
45-
return super.touch(file, status.setChecksum(write.checksum(file, status).compute(new NullInputStream(0L), status)));
45+
public Path touch(final Write<StorageObject> writer, final Path file, final TransferStatus status) throws BackgroundException {
46+
return super.touch(writer, file, status.setChecksum(writer.checksum(file, status).compute(new NullInputStream(0L), status)));
4647
}
4748

4849
@Override

s3/src/test/java/ch/cyberduck/core/cryptomator/CopyWorkerTest.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import ch.cyberduck.core.cryptomator.features.CryptoWriteFeature;
2929
import ch.cyberduck.core.features.Directory;
3030
import ch.cyberduck.core.features.Find;
31+
import ch.cyberduck.core.features.Write;
3132
import ch.cyberduck.core.io.StreamCopier;
3233
import ch.cyberduck.core.pool.SessionPool;
3334
import ch.cyberduck.core.s3.AbstractS3Test;
@@ -107,10 +108,11 @@ public void testCopyToDifferentFolderCryptomator() throws Exception {
107108
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
108109
session.withRegistry(registry);
109110
final S3AccessControlListFeature acl = new S3AccessControlListFeature(session);
110-
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), new S3WriteFeature(session, acl), cryptomator).touch(source, new TransferStatus());
111+
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), cryptomator).touch(
112+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), source, new TransferStatus());
111113
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(source));
112-
113-
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, new S3WriteFeature(session, acl), acl)).mkdir(targetFolder, new TransferStatus());
114+
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, acl)).mkdir(
115+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), targetFolder, new TransferStatus());
114116
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(targetFolder));
115117
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new SessionPool.SingleSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
116118
worker.run(session);
@@ -132,9 +134,9 @@ public void testCopyToDifferentFolderLongFilenameCryptomator() throws Exception
132134
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
133135
session.withRegistry(registry);
134136
final S3AccessControlListFeature acl = new S3AccessControlListFeature(session);
135-
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), new S3WriteFeature(session, acl), cryptomator).touch(source, new TransferStatus());
137+
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), cryptomator).touch(new S3WriteFeature(session, new S3AccessControlListFeature(session)), source, new TransferStatus());
136138
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(source));
137-
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, new S3WriteFeature(session, acl), acl)).mkdir(targetFolder, new TransferStatus());
139+
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, acl)).mkdir(new S3WriteFeature(session, new S3AccessControlListFeature(session)), targetFolder, new TransferStatus());
138140
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(targetFolder));
139141
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new SessionPool.SingleSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
140142
worker.run(session);
@@ -154,9 +156,11 @@ public void testCopyFolder() throws Exception {
154156
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
155157
session.withRegistry(registry);
156158
final S3AccessControlListFeature acl = new S3AccessControlListFeature(session);
157-
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, new S3WriteFeature(session, acl), acl)).mkdir(folder, new TransferStatus());
159+
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, acl)).mkdir(
160+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), folder, new TransferStatus());
158161
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(folder));
159-
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), new S3WriteFeature(session, acl), cryptomator).touch(file, new TransferStatus());
162+
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), cryptomator).touch(
163+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), file, new TransferStatus());
160164
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(file));
161165
// copy file
162166
final Path fileRenamed = new Path(folder, "f1", EnumSet.of(Path.Type.file));
@@ -189,7 +193,8 @@ public void testCopyFileIntoVault() throws Exception {
189193
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
190194
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
191195
session.withRegistry(registry);
192-
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, new S3WriteFeature(session, acl), acl)).mkdir(encryptedFolder, new TransferStatus());
196+
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, acl)).mkdir(
197+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), encryptedFolder, new TransferStatus());
193198
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFolder));
194199
// copy file into vault
195200
final CopyWorker worker = new CopyWorker(Collections.singletonMap(cleartextFile, encryptedFile), new SessionPool.SingleSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
@@ -210,8 +215,8 @@ public void testCopyDirectoryIntoVault() throws Exception {
210215
final Path cleartextFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
211216
final Path cleartextFile = new Path(cleartextFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
212217
final S3AccessControlListFeature acl = new S3AccessControlListFeature(session);
213-
new S3DirectoryFeature(session, new S3WriteFeature(session, acl), acl).mkdir(cleartextFolder, new TransferStatus());
214-
new S3TouchFeature(session, acl).touch(cleartextFile, new TransferStatus());
218+
new S3DirectoryFeature(session, acl).mkdir(new S3WriteFeature(session, acl), cleartextFolder, new TransferStatus());
219+
new S3TouchFeature(session, acl).touch(new S3WriteFeature(session, acl), cleartextFile, new TransferStatus());
215220
assertTrue(new S3FindFeature(session, acl).find(cleartextFolder));
216221
assertTrue(new S3FindFeature(session, acl).find(cleartextFile));
217222
final CryptoVault cryptomator = new CryptoVault(vault);
@@ -237,17 +242,18 @@ public void testCopyFileOutsideVault() throws Exception {
237242
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
238243
final Path clearFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
239244
final S3AccessControlListFeature acl = new S3AccessControlListFeature(session);
240-
new S3DirectoryFeature(session, new S3WriteFeature(session, acl),
241-
acl).mkdir(clearFolder, new TransferStatus());
245+
new S3DirectoryFeature(session, acl).mkdir(new S3WriteFeature(session, acl), clearFolder, new TransferStatus());
242246
final Path encryptedFolder = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
243247
final Path encryptedFile = new Path(encryptedFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
244248
final CryptoVault cryptomator = new CryptoVault(vault);
245249
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
246250
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
247251
session.withRegistry(registry);
248-
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, new S3WriteFeature(session, acl), acl)).mkdir(encryptedFolder, new TransferStatus());
252+
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, acl)).mkdir(
253+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), encryptedFolder, new TransferStatus());
249254
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFolder));
250-
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), new S3WriteFeature(session, acl), cryptomator).touch(encryptedFile, new TransferStatus());
255+
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), cryptomator).touch(
256+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), encryptedFile, new TransferStatus());
251257
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFile));
252258
// move file outside vault
253259
final Path cleartextFile = new Path(clearFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
@@ -270,10 +276,10 @@ public void testCopyDirectoryOutsideVault() throws Exception {
270276
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
271277
session.withRegistry(registry);
272278
final S3AccessControlListFeature acl = new S3AccessControlListFeature(session);
273-
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, new S3WriteFeature(session, acl),
274-
acl)).mkdir(encryptedFolder, new TransferStatus());
279+
cryptomator.getFeature(session, Directory.class, new S3DirectoryFeature(session, acl)).mkdir(cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), encryptedFolder, new TransferStatus());
275280
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFolder));
276-
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), new S3WriteFeature(session, acl), cryptomator).touch(encryptedFile, new TransferStatus());
281+
new CryptoTouchFeature<>(session, new S3TouchFeature(session, acl), cryptomator).touch(
282+
cryptomator.getFeature(session, Write.class, new S3WriteFeature(session, acl)), encryptedFile, new TransferStatus());
277283
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFile));
278284
// copy directory outside vault
279285
final Path cleartextFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));

0 commit comments

Comments
 (0)