Skip to content

Commit 5cf609e

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

26 files changed

+132
-114
lines changed

onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphDirectoryFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import ch.cyberduck.core.exception.AccessDeniedException;
2323
import ch.cyberduck.core.exception.BackgroundException;
2424
import ch.cyberduck.core.features.Directory;
25+
import ch.cyberduck.core.features.Write;
2526
import ch.cyberduck.core.onedrive.GraphExceptionMappingService;
2627
import ch.cyberduck.core.onedrive.GraphSession;
2728
import ch.cyberduck.core.transfer.TransferStatus;
@@ -46,7 +47,7 @@ public GraphDirectoryFeature(final GraphSession session, final GraphFileIdProvid
4647
}
4748

4849
@Override
49-
public Path mkdir(final Path directory, final TransferStatus status) throws BackgroundException {
50+
public Path mkdir(final Write<DriveItem.Metadata> writer, final Path directory, final TransferStatus status) throws BackgroundException {
5051
final DriveItem folder = session.getItem(directory.getParent());
5152
try {
5253
final DriveItem.Metadata metadata = Files.createFolder(folder, directory.getName());

onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphTouchFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import ch.cyberduck.core.exception.AccessDeniedException;
2525
import ch.cyberduck.core.exception.BackgroundException;
2626
import ch.cyberduck.core.features.Touch;
27+
import ch.cyberduck.core.features.Write;
2728
import ch.cyberduck.core.onedrive.GraphExceptionMappingService;
2829
import ch.cyberduck.core.onedrive.GraphSession;
2930
import ch.cyberduck.core.transfer.TransferStatus;
@@ -47,7 +48,7 @@ public GraphTouchFeature(final GraphSession session, final GraphFileIdProvider f
4748
}
4849

4950
@Override
50-
public Path touch(final Path file, final TransferStatus status) throws BackgroundException {
51+
public Path touch(final Write<DriveItem.Metadata> writer, final Path file, final TransferStatus status) throws BackgroundException {
5152
try {
5253
final DriveItem folder = session.getItem(file.getParent());
5354
final DriveItem.Metadata metadata = Files.createFile(folder, URIEncoder.encode(file.getName()),

onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphWriteFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void close() throws IOException {
161161
log.warn("Abort upload session {} with no completed parts", upload);
162162
// Use touch feature for empty file upload
163163
upload.cancelUpload();
164-
new GraphTouchFeature(session, fileid).touch(file, overall);
164+
new GraphTouchFeature(session, fileid).touch(GraphWriteFeature.this, file, overall);
165165
}
166166
}
167167
catch(BackgroundException e) {

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.junit.experimental.categories.Category;
5757
import org.junit.runner.RunWith;
5858
import org.junit.runners.Parameterized;
59+
import org.nuxeo.onedrive.client.types.DriveItem;
5960

6061
import java.io.ByteArrayInputStream;
6162
import java.io.ByteArrayOutputStream;
@@ -107,10 +108,10 @@ public void testCopyToDifferentFolderCryptomator() throws Exception {
107108
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
108109
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
109110
session.withRegistry(registry);
110-
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
111-
), new GraphWriteFeature(session, fileid), cryptomator).touch(source, new TransferStatus());
111+
new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(
112+
session), cryptomator).touch(new GraphWriteFeature(session, fileid), source, new TransferStatus());
112113
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(source));
113-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(targetFolder, new TransferStatus());
114+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), targetFolder, new TransferStatus());
114115
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(targetFolder));
115116
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new SessionPool.SingleSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
116117
worker.run(session);
@@ -131,10 +132,10 @@ public void testCopyToDifferentFolderLongFilenameCryptomator() throws Exception
131132
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
132133
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
133134
session.withRegistry(registry);
134-
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
135-
), new GraphWriteFeature(session, fileid), cryptomator).touch(source, new TransferStatus());
135+
new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(
136+
session), cryptomator).touch(new GraphWriteFeature(session, fileid), source, new TransferStatus());
136137
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(source));
137-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(targetFolder, new TransferStatus());
138+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), targetFolder, new TransferStatus());
138139
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(targetFolder));
139140
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new SessionPool.SingleSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
140141
worker.run(session);
@@ -153,10 +154,10 @@ public void testCopyFolder() throws Exception {
153154
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
154155
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
155156
session.withRegistry(registry);
156-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(folder, new TransferStatus());
157+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), folder, new TransferStatus());
157158
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(folder));
158-
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
159-
), new GraphWriteFeature(session, fileid), cryptomator).touch(file, new TransferStatus());
159+
new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(
160+
session), cryptomator).touch(new GraphWriteFeature(session, fileid), file, new TransferStatus());
160161
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(file));
161162
// copy file
162163
final Path fileRenamed = new Path(folder, "f1", EnumSet.of(Path.Type.file));
@@ -189,7 +190,7 @@ public void testCopyFileIntoVault() throws Exception {
189190
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
190191
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
191192
session.withRegistry(registry);
192-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(encryptedFolder, new TransferStatus());
193+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), encryptedFolder, new TransferStatus());
193194
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFolder));
194195
// copy file into vault
195196
final CopyWorker worker = new CopyWorker(Collections.singletonMap(cleartextFile, encryptedFile), new SessionPool.SingleSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
@@ -210,9 +211,9 @@ public void testCopyDirectoryIntoVault() throws Exception {
210211
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
211212
final Path cleartextFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
212213
final Path cleartextFile = new Path(cleartextFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
213-
new GraphDirectoryFeature(session, fileid).mkdir(cleartextFolder, new TransferStatus());
214-
new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
215-
).touch(cleartextFile, new TransferStatus());
214+
new GraphDirectoryFeature(session, fileid).mkdir(new GraphWriteFeature(session, fileid), cleartextFolder, new TransferStatus());
215+
new DefaultTouchFeature<DriveItem.Metadata>(
216+
session).touch(new GraphWriteFeature(session, fileid), cleartextFile, new TransferStatus());
216217
assertTrue(new GraphFindFeature(session, fileid).find(cleartextFolder));
217218
assertTrue(new GraphFindFeature(session, fileid).find(cleartextFile));
218219
final CryptoVault cryptomator = new CryptoVault(vault);
@@ -237,17 +238,17 @@ public void testCopyFileOutsideVault() throws Exception {
237238
final Path home = new OneDriveHomeFinderService().find();
238239
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
239240
final Path clearFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
240-
new GraphDirectoryFeature(session, fileid).mkdir(clearFolder, new TransferStatus());
241+
new GraphDirectoryFeature(session, fileid).mkdir(new GraphWriteFeature(session, fileid), clearFolder, new TransferStatus());
241242
final Path encryptedFolder = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
242243
final Path encryptedFile = new Path(encryptedFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
243244
final CryptoVault cryptomator = new CryptoVault(vault);
244245
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
245246
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
246247
session.withRegistry(registry);
247-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(encryptedFolder, new TransferStatus());
248+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), encryptedFolder, new TransferStatus());
248249
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFolder));
249-
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
250-
), new GraphWriteFeature(session, fileid), cryptomator).touch(encryptedFile, new TransferStatus());
250+
new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(
251+
session), cryptomator).touch(new GraphWriteFeature(session, fileid), encryptedFile, new TransferStatus());
251252
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFile));
252253
// move file outside vault
253254
final Path cleartextFile = new Path(clearFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
@@ -269,10 +270,10 @@ public void testCopyDirectoryOutsideVault() throws Exception {
269270
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
270271
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator);
271272
session.withRegistry(registry);
272-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(encryptedFolder, new TransferStatus());
273+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), encryptedFolder, new TransferStatus());
273274
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFolder));
274-
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
275-
), new GraphWriteFeature(session, fileid), cryptomator).touch(encryptedFile, new TransferStatus());
275+
new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(
276+
session), cryptomator).touch(new GraphWriteFeature(session, fileid), encryptedFile, new TransferStatus());
276277
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(encryptedFile));
277278
// copy directory outside vault
278279
final Path cleartextFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));

onedrive/src/test/java/ch/cyberduck/core/cryptomator/GraphDirectoryFeatureTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import ch.cyberduck.core.onedrive.features.GraphDeleteFeature;
3434
import ch.cyberduck.core.onedrive.features.GraphDirectoryFeature;
3535
import ch.cyberduck.core.onedrive.features.GraphFindFeature;
36+
import ch.cyberduck.core.onedrive.features.GraphWriteFeature;
3637
import ch.cyberduck.core.shared.DefaultAttributesFinderFeature;
3738
import ch.cyberduck.core.shared.DefaultFindFeature;
3839
import ch.cyberduck.core.transfer.TransferStatus;
@@ -65,7 +66,7 @@ public void testMakeDirectoryEncrypted() throws Exception {
6566
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
6667
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator));
6768
final Path test = cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(
68-
new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
69+
new GraphWriteFeature(session, fileid), new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
6970
assertNotNull(test.attributes().getVault());
7071
final String id = test.attributes().getFileId();
7172
final long timestamp = test.attributes().getModificationDate();
@@ -90,7 +91,7 @@ public void testMakeDirectoryLongFilenameEncrypted() throws Exception {
9091
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
9192
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator));
9293
final Path test = cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(
93-
new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
94+
new GraphWriteFeature(session, fileid), new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
9495
assertNotNull(test.attributes().getVault());
9596
final String id = test.attributes().getFileId();
9697
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(test));

onedrive/src/test/java/ch/cyberduck/core/cryptomator/GraphMoveFeatureTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.junit.experimental.categories.Category;
4646
import org.junit.runner.RunWith;
4747
import org.junit.runners.Parameterized;
48+
import org.nuxeo.onedrive.client.types.DriveItem;
4849

4950
import java.util.Arrays;
5051
import java.util.EnumSet;
@@ -63,11 +64,11 @@ public void testMove() throws Exception {
6364
final CryptoVault cryptomator = new CryptoVault(vault);
6465
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
6566
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator));
66-
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(folder, new TransferStatus());
67+
cryptomator.getFeature(session, Directory.class, new GraphDirectoryFeature(session, fileid)).mkdir(new GraphWriteFeature(session, fileid), folder, new TransferStatus());
6768
final String filename = new AlphanumericRandomStringService().random();
68-
final Path file = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)
69-
), new GraphWriteFeature(session, fileid), cryptomator).touch(
70-
new Path(folder, filename, EnumSet.of(Path.Type.file)), new TransferStatus());
69+
final Path file = new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(
70+
session), cryptomator).touch(
71+
new GraphWriteFeature(session, fileid), new Path(folder, filename, EnumSet.of(Path.Type.file)), new TransferStatus());
7172
assertTrue(cryptomator.getFeature(session, Find.class, new DefaultFindFeature(session)).find(file));
7273
final Move move = cryptomator.getFeature(session, Move.class, new GraphMoveFeature(session, fileid));
7374
// rename file

onedrive/src/test/java/ch/cyberduck/core/cryptomator/GraphTouchFeatureTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.junit.experimental.categories.Category;
4242
import org.junit.runner.RunWith;
4343
import org.junit.runners.Parameterized;
44+
import org.nuxeo.onedrive.client.types.DriveItem;
4445

4546
import java.util.Arrays;
4647
import java.util.EnumSet;
@@ -61,8 +62,8 @@ public void testTouchLongFilenameEncrypted() throws Exception {
6162
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
6263
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator));
6364
final TransferStatus status = new TransferStatus();
64-
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)), new GraphWriteFeature(session, fileid), cryptomator).touch(
65-
new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file)), status);
65+
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(session), cryptomator).touch(
66+
new GraphWriteFeature(session, fileid), new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file)), status);
6667
assertEquals(0L, test.attributes().getSize());
6768
assertEquals(0L, status.getResponse().getSize());
6869
assertNotNull(test.attributes().getVault());
@@ -82,8 +83,8 @@ public void testTouchLongFilenameEncryptedDefaultFeature() throws Exception {
8283
cryptomator.create(session, new VaultCredentials("test"), vaultVersion);
8384
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordCallback(), cryptomator));
8485
final TransferStatus status = new TransferStatus();
85-
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new GraphWriteFeature(session, fileid)), new GraphWriteFeature(session, fileid), cryptomator).touch(
86-
new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file)), status);
86+
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<DriveItem.Metadata>(session), cryptomator).touch(
87+
new GraphWriteFeature(session, fileid), new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file)), status);
8788
assertEquals(0L, test.attributes().getSize());
8889
assertEquals(0L, status.getResponse().getSize());
8990
assertNotNull(test.attributes().getVault());

0 commit comments

Comments
 (0)