From 5c305237775c39056c5ce2d3b52af4a7e983119b Mon Sep 17 00:00:00 2001 From: David Kocher Date: Fri, 8 May 2026 11:39:16 +0200 Subject: [PATCH] Make filename argument optional instead of using empty string. --- .../core/azure/AzureDirectoryFeature.java | 33 ++++++------- .../core/azure/AzureTouchFeature.java | 3 +- .../core/azure/AzureDirectoryFeatureTest.java | 5 +- .../core/azure/AzureTouchFeatureTest.java | 9 ++-- .../cyberduck/core/b2/B2DirectoryFeature.java | 13 ++--- .../ch/cyberduck/core/b2/B2TouchFeature.java | 3 +- .../core/b2/B2DirectoryFeatureTest.java | 5 +- .../core/box/BoxDirectoryFeature.java | 9 ++-- .../cyberduck/core/box/BoxTouchFeature.java | 9 ++-- .../core/box/BoxDirectoryFeatureTest.java | 13 ++--- .../core/box/BoxTouchFeatureTest.java | 4 +- .../ch/cyberduck/core/features/Directory.java | 7 +-- .../ch/cyberduck/core/features/Touch.java | 4 +- .../VaultRegistryDirectoryFeature.java | 4 +- .../registry/VaultRegistryTouchFeature.java | 4 +- .../features/CryptoDirectoryV6Feature.java | 6 ++- .../features/CryptoDirectoryV7Feature.java | 5 +- .../legacy/features/CryptoTouchFeature.java | 9 ++-- .../legacy/CryptomatorVaultTest.java | 6 --- .../features/CryptoDirectoryFeature.java | 7 +-- .../features/CryptoTouchFeature.java | 9 ++-- .../impl/v8/CryptomatorVaultTest.java | 5 -- .../core/ctera/CteraDirectoryFeature.java | 11 +++-- .../core/ctera/CteraTouchFeature.java | 9 ++-- .../core/ctera/CteraDirectoryFeatureTest.java | 7 +-- .../core/ctera/CteraTouchFeatureTest.java | 15 +++--- .../core/deepbox/DeepboxDirectoryFeature.java | 3 +- .../core/deepbox/DeepboxTouchFeature.java | 4 +- .../deepbox/DeepboxDirectoryFeatureTest.java | 19 ++++---- .../core/deepbox/DeepboxTouchFeatureTest.java | 47 ++++++++++--------- .../core/sds/SDSDelegatingWriteFeature.java | 3 +- .../core/sds/SDSDirectoryFeature.java | 10 ++-- .../cyberduck/core/sds/SDSTouchFeature.java | 9 ++-- .../core/sds/SDSTouchFeatureTest.java | 20 ++++---- .../core/dropbox/DropboxDirectoryFeature.java | 9 ++-- .../core/dropbox/DropboxTouchFeature.java | 9 ++-- .../core/dropbox/DropboxTouchFeatureTest.java | 3 +- .../core/eue/EueDirectoryFeature.java | 9 ++-- .../cyberduck/core/eue/EueTouchFeature.java | 9 ++-- .../core/eue/EueTouchFeatureTest.java | 9 ++-- .../core/ftp/FTPDirectoryFeature.java | 3 +- .../cyberduck/core/ftp/FTPTouchFeature.java | 4 +- .../googledrive/DriveDirectoryFeature.java | 4 +- .../core/googledrive/DriveTouchFeature.java | 3 +- .../GoogleStorageDirectoryFeature.java | 12 ++--- .../GoogleStorageTouchFeature.java | 3 +- .../core/irods/IRODSTouchFeature.java | 9 +--- .../core/manta/MantaDirectoryFeature.java | 7 +-- .../core/manta/MantaTouchFeature.java | 3 +- .../features/GraphDirectoryFeature.java | 3 +- .../onedrive/features/GraphTouchFeature.java | 3 +- ...OfflineGraphDirectoryTouchFeatureTest.java | 5 +- .../core/openstack/SwiftTouchFeature.java | 3 +- .../core/openstack/SwiftTouchFeatureTest.java | 6 +-- .../cocoa/controller/BrowserController.java | 3 +- .../datasource/BrowserTableDataSource.java | 2 +- .../toolbar/BrowserToolbarValidator.java | 9 ++-- .../cyberduck/core/s3/S3DirectoryFeature.java | 7 +-- .../ch/cyberduck/core/s3/S3TouchFeature.java | 3 +- .../core/s3/S3DirectoryFeatureTest.java | 11 +++-- .../cyberduck/core/s3/S3TouchFeatureTest.java | 16 +++---- .../core/spectra/SpectraTouchFeature.java | 3 +- .../core/spectra/SpectraTouchFeatureTest.java | 6 +-- .../storegate/StoregateDirectoryFeature.java | 3 +- .../core/storegate/StoregateTouchFeature.java | 3 +- .../ui/controller/BrowserController.cs | 12 ++--- 66 files changed, 293 insertions(+), 230 deletions(-) diff --git a/azure/src/main/java/ch/cyberduck/core/azure/AzureDirectoryFeature.java b/azure/src/main/java/ch/cyberduck/core/azure/AzureDirectoryFeature.java index 6507acf7e0..e680026ac6 100644 --- a/azure/src/main/java/ch/cyberduck/core/azure/AzureDirectoryFeature.java +++ b/azure/src/main/java/ch/cyberduck/core/azure/AzureDirectoryFeature.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import java.text.MessageFormat; import java.util.EnumSet; +import java.util.Optional; import com.azure.core.exception.HttpResponseException; @@ -69,28 +70,28 @@ public class AzureDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + } } + // Empty argument if not known in validation } } public static boolean validate(final String filename) { - // Empty argument if not known in validation - if(StringUtils.isNotBlank(filename)) { - // Container names must be lowercase, between 3-63 characters long and must start with a letter or - // number. Container names may contain only letters, numbers, and the dash (-) character. - if(StringUtils.length(filename) > 63) { - return false; - } - if(StringUtils.length(filename) < 3) { - return false; - } - if(!StringUtils.isAlphanumeric(RegExUtils.removeAll(filename, "-"))) { - return false; - } + // Container names must be lowercase, between 3-63 characters long and must start with a letter or + // number. Container names may contain only letters, numbers, and the dash (-) character. + if(StringUtils.length(filename) > 63) { + return false; + } + if(StringUtils.length(filename) < 3) { + return false; + } + if(!StringUtils.isAlphanumeric(RegExUtils.removeAll(filename, "-"))) { + return false; } return true; } diff --git a/azure/src/main/java/ch/cyberduck/core/azure/AzureTouchFeature.java b/azure/src/main/java/ch/cyberduck/core/azure/AzureTouchFeature.java index 11869f59a4..5691bc96d4 100644 --- a/azure/src/main/java/ch/cyberduck/core/azure/AzureTouchFeature.java +++ b/azure/src/main/java/ch/cyberduck/core/azure/AzureTouchFeature.java @@ -26,6 +26,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import org.apache.commons.io.input.NullInputStream; import java.text.MessageFormat; +import java.util.Optional; public class AzureTouchFeature extends DefaultTouchFeature { @@ -34,7 +35,7 @@ public class AzureTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); } diff --git a/azure/src/test/java/ch/cyberduck/core/azure/AzureDirectoryFeatureTest.java b/azure/src/test/java/ch/cyberduck/core/azure/AzureDirectoryFeatureTest.java index 5cf1f1d3fb..1f2a7f897e 100644 --- a/azure/src/test/java/ch/cyberduck/core/azure/AzureDirectoryFeatureTest.java +++ b/azure/src/test/java/ch/cyberduck/core/azure/AzureDirectoryFeatureTest.java @@ -16,6 +16,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -38,8 +39,8 @@ public class AzureDirectoryFeatureTest extends AbstractAzureTest { public void testCreateContainerInvalidName() throws Exception { final Path container = new Path("untitled folder", EnumSet.of(Path.Type.directory)); final AzureDirectoryFeature feature = new AzureDirectoryFeature(session); - assertFalse(feature.isSupported(container.getParent(), container.getName())); - assertThrows(InvalidFilenameException.class, () -> feature.preflight(container.getParent(), container.getName())); + assertFalse(feature.isSupported(container.getParent(), Optional.of(container.getName()))); + assertThrows(InvalidFilenameException.class, () -> feature.preflight(container.getParent(), Optional.of(container.getName()))); feature.mkdir(new AzureWriteFeature(session), container, new TransferStatus()); assertTrue(new AzureFindFeature(session).find(container)); new AzureDeleteFeature(session).delete(Collections.singletonList(container), LoginCallback.noop, new Delete.DisabledCallback()); diff --git a/azure/src/test/java/ch/cyberduck/core/azure/AzureTouchFeatureTest.java b/azure/src/test/java/ch/cyberduck/core/azure/AzureTouchFeatureTest.java index 7258582352..f8ebe51ebd 100644 --- a/azure/src/test/java/ch/cyberduck/core/azure/AzureTouchFeatureTest.java +++ b/azure/src/test/java/ch/cyberduck/core/azure/AzureTouchFeatureTest.java @@ -28,6 +28,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; @Category(IntegrationTest.class) public class AzureTouchFeatureTest extends AbstractAzureTest { @@ -44,9 +45,9 @@ public class AzureTouchFeatureTest extends AbstractAzureTest { public void testPreflightFilename() throws Exception { final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final AzureTouchFeature feature = new AzureTouchFeature(session); - feature.preflight(container, new AsciiRandomStringService().random()); - feature.preflight(container, new AlphanumericRandomStringService().random()); - feature.preflight(container, String.format("%s.suffix", new AlphanumericRandomStringService().random())); - feature.preflight(container, "?"); + feature.preflight(container, Optional.of(new AsciiRandomStringService().random())); + feature.preflight(container, Optional.of(new AlphanumericRandomStringService().random())); + feature.preflight(container, Optional.of(String.format("%s.suffix", new AlphanumericRandomStringService().random()))); + feature.preflight(container, Optional.of("?")); } } diff --git a/backblaze/src/main/java/ch/cyberduck/core/b2/B2DirectoryFeature.java b/backblaze/src/main/java/ch/cyberduck/core/b2/B2DirectoryFeature.java index 5dfa61b2b7..13e33948e2 100644 --- a/backblaze/src/main/java/ch/cyberduck/core/b2/B2DirectoryFeature.java +++ b/backblaze/src/main/java/ch/cyberduck/core/b2/B2DirectoryFeature.java @@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.text.MessageFormat; import java.util.EnumSet; +import java.util.Optional; import synapticloop.b2.BucketType; import synapticloop.b2.exception.B2ApiException; @@ -79,23 +80,23 @@ public class B2DirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { // Empty argument if not known in validation - if(StringUtils.isNotBlank(filename)) { + if(filename.isPresent()) { // Bucket names must be a minimum of 6 and a maximum of 50 characters long, and must be globally unique; // two different B2 accounts cannot have buckets with the name name. Bucket names can consist of: letters, // digits, and "-". Bucket names cannot start with "b2-"; these are reserved for internal Backblaze use. - if(StringUtils.startsWith(filename, "b2-")) { + if(StringUtils.startsWith(filename.get(), "b2-")) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } - if(StringUtils.length(filename) > 50) { + if(StringUtils.length(filename.get()) > 50) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } - if(StringUtils.length(filename) < 6) { + if(StringUtils.length(filename.get()) < 6) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } - if(!StringUtils.isAlphanumeric(RegExUtils.removeAll(filename, "-"))) { + if(!StringUtils.isAlphanumeric(RegExUtils.removeAll(filename.get(), "-"))) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } } diff --git a/backblaze/src/main/java/ch/cyberduck/core/b2/B2TouchFeature.java b/backblaze/src/main/java/ch/cyberduck/core/b2/B2TouchFeature.java index f20a84a429..73209898bd 100644 --- a/backblaze/src/main/java/ch/cyberduck/core/b2/B2TouchFeature.java +++ b/backblaze/src/main/java/ch/cyberduck/core/b2/B2TouchFeature.java @@ -26,6 +26,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import org.apache.commons.io.input.NullInputStream; import java.text.MessageFormat; +import java.util.Optional; import synapticloop.b2.response.BaseB2Response; @@ -41,7 +42,7 @@ public class B2TouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { // Creating files is only possible inside a bucket. if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); diff --git a/backblaze/src/test/java/ch/cyberduck/core/b2/B2DirectoryFeatureTest.java b/backblaze/src/test/java/ch/cyberduck/core/b2/B2DirectoryFeatureTest.java index fd8ade66c6..727a078399 100644 --- a/backblaze/src/test/java/ch/cyberduck/core/b2/B2DirectoryFeatureTest.java +++ b/backblaze/src/test/java/ch/cyberduck/core/b2/B2DirectoryFeatureTest.java @@ -31,6 +31,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -42,7 +43,7 @@ public class B2DirectoryFeatureTest extends AbstractB2Test { final Path bucket = new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)); final B2VersionIdProvider fileid = new B2VersionIdProvider(session); final B2DirectoryFeature feature = new B2DirectoryFeature(session, fileid); - assertTrue(feature.isSupported(bucket.getParent(), bucket.getName())); + assertTrue(feature.isSupported(bucket.getParent(), Optional.of(bucket.getName()))); feature.mkdir(new B2WriteFeature(session, fileid), bucket, new TransferStatus()); assertThrows(ConflictException.class, () -> feature.mkdir(new B2WriteFeature(session, fileid), bucket, new TransferStatus())); new B2DeleteFeature(session, fileid).delete(Collections.singletonList(bucket), LoginCallback.noop, new Delete.DisabledCallback()); @@ -65,7 +66,7 @@ public class B2DirectoryFeatureTest extends AbstractB2Test { public void testBucketInvalidCharacter() throws Exception { final Path bucket = new Path("untitled folder", EnumSet.of(Path.Type.directory, Path.Type.volume)); final B2VersionIdProvider fileid = new B2VersionIdProvider(session); - assertFalse(new B2DirectoryFeature(session, fileid).isSupported(bucket.getParent(), bucket.getName())); + assertFalse(new B2DirectoryFeature(session, fileid).isSupported(bucket.getParent(), Optional.of(bucket.getName()))); try { new B2DirectoryFeature(session, fileid).mkdir(new B2WriteFeature(session, fileid), bucket, new TransferStatus()); } diff --git a/box/src/main/java/ch/cyberduck/core/box/BoxDirectoryFeature.java b/box/src/main/java/ch/cyberduck/core/box/BoxDirectoryFeature.java index faa6cce946..114914fd82 100644 --- a/box/src/main/java/ch/cyberduck/core/box/BoxDirectoryFeature.java +++ b/box/src/main/java/ch/cyberduck/core/box/BoxDirectoryFeature.java @@ -30,6 +30,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import java.text.MessageFormat; import java.util.Collections; +import java.util.Optional; public class BoxDirectoryFeature implements Directory { @@ -55,9 +56,11 @@ public class BoxDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!BoxTouchFeature.validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!BoxTouchFeature.validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + } } } } diff --git a/box/src/main/java/ch/cyberduck/core/box/BoxTouchFeature.java b/box/src/main/java/ch/cyberduck/core/box/BoxTouchFeature.java index daff6bda08..9d6970d479 100644 --- a/box/src/main/java/ch/cyberduck/core/box/BoxTouchFeature.java +++ b/box/src/main/java/ch/cyberduck/core/box/BoxTouchFeature.java @@ -25,6 +25,7 @@ import ch.cyberduck.core.shared.DefaultTouchFeature; import org.apache.commons.lang3.StringUtils; import java.text.MessageFormat; +import java.util.Optional; public class BoxTouchFeature extends DefaultTouchFeature { @@ -33,9 +34,11 @@ public class BoxTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } } diff --git a/box/src/test/java/ch/cyberduck/core/box/BoxDirectoryFeatureTest.java b/box/src/test/java/ch/cyberduck/core/box/BoxDirectoryFeatureTest.java index 4d819ce1ae..6afcf93a9e 100644 --- a/box/src/test/java/ch/cyberduck/core/box/BoxDirectoryFeatureTest.java +++ b/box/src/test/java/ch/cyberduck/core/box/BoxDirectoryFeatureTest.java @@ -30,6 +30,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -53,11 +54,11 @@ public class BoxDirectoryFeatureTest extends AbstractBoxTest { @Test public void isSupported() { final BoxFileidProvider fileid = new BoxFileidProvider(session); - assertTrue(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), new AlphanumericRandomStringService().random())); - assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), String.format("%s ", new AlphanumericRandomStringService().random()))); - assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), String.format("%s\\", new AlphanumericRandomStringService().random()))); - assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), String.format("%s/", new AlphanumericRandomStringService().random()))); - assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), ".")); - assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), "..")); + assertTrue(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), Optional.of(new AlphanumericRandomStringService().random()))); + assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), Optional.of(String.format("%s ", new AlphanumericRandomStringService().random())))); + assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), Optional.of(String.format("%s\\", new AlphanumericRandomStringService().random())))); + assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), Optional.of(String.format("%s/", new AlphanumericRandomStringService().random())))); + assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), Optional.of("."))); + assertFalse(new BoxDirectoryFeature(session, fileid).isSupported(Home.root(), Optional.of(".."))); } } \ No newline at end of file diff --git a/box/src/test/java/ch/cyberduck/core/box/BoxTouchFeatureTest.java b/box/src/test/java/ch/cyberduck/core/box/BoxTouchFeatureTest.java index 9d7b4d4df0..ad57d9ed76 100644 --- a/box/src/test/java/ch/cyberduck/core/box/BoxTouchFeatureTest.java +++ b/box/src/test/java/ch/cyberduck/core/box/BoxTouchFeatureTest.java @@ -21,6 +21,8 @@ import ch.cyberduck.test.IntegrationTest; import org.junit.Test; import org.junit.experimental.categories.Category; +import java.util.Optional; + import static org.junit.Assert.assertTrue; @Category(IntegrationTest.class) @@ -29,6 +31,6 @@ public class BoxTouchFeatureTest extends AbstractBoxTest { @Test public void testSupported() { final BoxFileidProvider fileid = new BoxFileidProvider(session); - assertTrue(new BoxTouchFeature(session, fileid).isSupported(Home.root(), "xacjivli-éf")); + assertTrue(new BoxTouchFeature(session, fileid).isSupported(Home.root(), Optional.of("xacjivli-éf"))); } } \ No newline at end of file diff --git a/core/src/main/java/ch/cyberduck/core/features/Directory.java b/core/src/main/java/ch/cyberduck/core/features/Directory.java index ae81df8ee1..72c61bb514 100644 --- a/core/src/main/java/ch/cyberduck/core/features/Directory.java +++ b/core/src/main/java/ch/cyberduck/core/features/Directory.java @@ -22,6 +22,7 @@ import ch.cyberduck.core.exception.BackgroundException; import ch.cyberduck.core.transfer.TransferStatus; import java.text.MessageFormat; +import java.util.Optional; /** * Create new folder on server @@ -43,10 +44,10 @@ public interface Directory { /** * @param workdir Working directory in browser - * @param filename Folder name or null if unknown + * @param filename Folder name if known * @return True if creating directory is supported in the working directory */ - default boolean isSupported(final Path workdir, final String filename) { + default boolean isSupported(final Path workdir, final Optional filename) { try { this.preflight(workdir, filename); return true; @@ -59,7 +60,7 @@ public interface Directory { /** * @throws AccessDeniedException Permission failure for target directory */ - default void preflight(final Path workdir, final String filename) throws BackgroundException { + default void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(!workdir.attributes().getPermission().isWritable()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString( "Cannot create folder {0}", "Error"), filename)).withFile(workdir); diff --git a/core/src/main/java/ch/cyberduck/core/features/Touch.java b/core/src/main/java/ch/cyberduck/core/features/Touch.java index 655a1584fd..c646d12523 100644 --- a/core/src/main/java/ch/cyberduck/core/features/Touch.java +++ b/core/src/main/java/ch/cyberduck/core/features/Touch.java @@ -40,7 +40,7 @@ public interface Touch { * @param filename Relative filename * @return True if creating an empty file is possible. */ - default boolean isSupported(final Path workdir, final String filename) { + default boolean isSupported(final Path workdir, final java.util.Optional filename) { try { this.preflight(workdir, filename); return true; @@ -53,7 +53,7 @@ public interface Touch { /** * @throws AccessDeniedException Permission failure for target directory */ - default void preflight(final Path workdir, final String filename) throws BackgroundException { + default void preflight(final Path workdir, final java.util.Optional filename) throws BackgroundException { if(!workdir.attributes().getPermission().isWritable()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString( "Cannot create {0}", "Error"), filename)).withFile(workdir); diff --git a/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryDirectoryFeature.java b/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryDirectoryFeature.java index 03278447e5..79b2619e26 100644 --- a/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryDirectoryFeature.java +++ b/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryDirectoryFeature.java @@ -24,6 +24,8 @@ import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.core.vault.VaultRegistry; import ch.cyberduck.core.vault.VaultUnlockCancelException; +import java.util.Optional; + public class VaultRegistryDirectoryFeature implements Directory { private final Session session; @@ -42,7 +44,7 @@ public class VaultRegistryDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { try { registry.find(session, workdir, false).getFeature(session, Directory.class, proxy).preflight(workdir, filename); } diff --git a/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryTouchFeature.java b/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryTouchFeature.java index 00c27982ea..70b52dbf45 100644 --- a/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryTouchFeature.java +++ b/core/src/main/java/ch/cyberduck/core/vault/registry/VaultRegistryTouchFeature.java @@ -24,6 +24,8 @@ import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.core.vault.VaultRegistry; import ch.cyberduck.core.vault.VaultUnlockCancelException; +import java.util.Optional; + public class VaultRegistryTouchFeature implements Touch { private final Session session; @@ -42,7 +44,7 @@ public class VaultRegistryTouchFeature implements Touch { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { try { registry.find(session, workdir, false).getFeature(session, Touch.class, proxy).preflight(workdir, filename); } diff --git a/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV6Feature.java b/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV6Feature.java index 3952a97c6b..dfd8013c26 100644 --- a/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV6Feature.java +++ b/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV6Feature.java @@ -28,6 +28,8 @@ import ch.cyberduck.core.transfer.TransferStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Optional; + public class CryptoDirectoryV6Feature implements Directory { private static final Logger log = LogManager.getLogger(CryptoDirectoryV6Feature.class); @@ -65,12 +67,12 @@ public class CryptoDirectoryV6Feature implements Directory { } @Override - public boolean isSupported(final Path workdir, final String name) { + public boolean isSupported(final Path workdir, final Optional name) { return delegate.isSupported(workdir, name); } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { delegate.preflight(cryptomator.encrypt(session, workdir), filename); } diff --git a/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV7Feature.java b/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV7Feature.java index 6b051b4830..660b15a7a3 100644 --- a/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV7Feature.java +++ b/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoDirectoryV7Feature.java @@ -30,6 +30,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.EnumSet; +import java.util.Optional; public class CryptoDirectoryV7Feature implements Directory { private static final Logger log = LogManager.getLogger(CryptoDirectoryV7Feature.class); @@ -73,12 +74,12 @@ public class CryptoDirectoryV7Feature implements Directory { } @Override - public boolean isSupported(final Path workdir, final String name) { + public boolean isSupported(final Path workdir, final Optional name) { return delegate.isSupported(workdir, name); } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { delegate.preflight(cryptomator.encrypt(session, workdir), filename); } diff --git a/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoTouchFeature.java b/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoTouchFeature.java index e023df3557..4488a43791 100644 --- a/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoTouchFeature.java +++ b/cryptomator/legacy/src/main/java/ch/cyberduck/core/cryptomator/legacy/features/CryptoTouchFeature.java @@ -31,6 +31,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import org.cryptomator.cryptolib.api.FileHeader; import java.text.MessageFormat; +import java.util.Optional; public class CryptoTouchFeature implements Touch { @@ -65,9 +66,11 @@ public class CryptoTouchFeature implements Touch { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!cryptomator.getFilenameProvider().isValid(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!cryptomator.getFilenameProvider().isValid(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } proxy.preflight(cryptomator.encrypt(session, workdir), filename); } diff --git a/cryptomator/legacy/src/test/java/ch/cyberduck/core/cryptomator/legacy/CryptomatorVaultTest.java b/cryptomator/legacy/src/test/java/ch/cyberduck/core/cryptomator/legacy/CryptomatorVaultTest.java index 80d9ae463f..139c3e9972 100644 --- a/cryptomator/legacy/src/test/java/ch/cyberduck/core/cryptomator/legacy/CryptomatorVaultTest.java +++ b/cryptomator/legacy/src/test/java/ch/cyberduck/core/cryptomator/legacy/CryptomatorVaultTest.java @@ -401,17 +401,11 @@ public class CryptomatorVaultTest { public T _getFeature(final Class type) { if(type == Directory.class) { return (T) new Directory() { - @Override public Path mkdir(final Write writer, final Path folder, final TransferStatus status) { assertTrue(folder.equals(home) || folder.isChild(home)); return folder; } - - @Override - public boolean isSupported(final Path workdir, final String name) { - throw new UnsupportedOperationException(); - } }; } return super._getFeature(type); diff --git a/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryFeature.java b/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryFeature.java index c1045b6d29..8c89b5c66f 100644 --- a/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryFeature.java +++ b/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryFeature.java @@ -31,6 +31,7 @@ import org.apache.logging.log4j.Logger; import org.cryptomator.cryptolib.api.DirectoryMetadata; import java.util.EnumSet; +import java.util.Optional; public class CryptoDirectoryFeature implements Directory { private static final Logger log = LogManager.getLogger(CryptoDirectoryFeature.class); @@ -87,13 +88,13 @@ public class CryptoDirectoryFeature implements Directory { } @Override - public boolean isSupported(final Path workdir, final String name) { + public boolean isSupported(final Path workdir, final Optional name) { return delegate.isSupported(workdir, name); } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - vault.getDirectoryProvider().createDirectoryId(new Path(workdir, filename, EnumSet.of(Path.Type.directory))); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + filename.ifPresent(s -> vault.getDirectoryProvider().createDirectoryId(new Path(workdir, s, EnumSet.of(Path.Type.directory)))); delegate.preflight(vault.encrypt(session, workdir), filename); } diff --git a/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoTouchFeature.java b/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoTouchFeature.java index 3678b3a7eb..7e3b9eabcb 100644 --- a/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoTouchFeature.java +++ b/cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoTouchFeature.java @@ -31,6 +31,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import org.cryptomator.cryptolib.api.FileHeader; import java.text.MessageFormat; +import java.util.Optional; public class CryptoTouchFeature implements Touch { @@ -65,9 +66,11 @@ public class CryptoTouchFeature implements Touch { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!vault.getFilenameProvider().isValid(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!vault.getFilenameProvider().isValid(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } proxy.preflight(vault.encrypt(session, workdir), filename); } diff --git a/cryptomator/src/test/java/ch/cyberduck/core/cryptomator/impl/v8/CryptomatorVaultTest.java b/cryptomator/src/test/java/ch/cyberduck/core/cryptomator/impl/v8/CryptomatorVaultTest.java index 3d8cdbff9c..b81d207b74 100644 --- a/cryptomator/src/test/java/ch/cyberduck/core/cryptomator/impl/v8/CryptomatorVaultTest.java +++ b/cryptomator/src/test/java/ch/cyberduck/core/cryptomator/impl/v8/CryptomatorVaultTest.java @@ -354,11 +354,6 @@ public class CryptomatorVaultTest { assertTrue(folder.equals(home) || folder.isChild(home)); return folder; } - - @Override - public boolean isSupported(final Path workdir, final String name) { - throw new UnsupportedOperationException(); - } }; } return super._getFeature(type); diff --git a/ctera/src/main/java/ch/cyberduck/core/ctera/CteraDirectoryFeature.java b/ctera/src/main/java/ch/cyberduck/core/ctera/CteraDirectoryFeature.java index 002247f084..014bb30493 100644 --- a/ctera/src/main/java/ch/cyberduck/core/ctera/CteraDirectoryFeature.java +++ b/ctera/src/main/java/ch/cyberduck/core/ctera/CteraDirectoryFeature.java @@ -22,6 +22,7 @@ import ch.cyberduck.core.exception.BackgroundException; import ch.cyberduck.core.exception.InvalidFilenameException; import java.text.MessageFormat; +import java.util.Optional; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.CREATEDIRECTORIESPERMISSION; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.assumeRole; @@ -34,10 +35,12 @@ public class CteraDirectoryFeature extends DAVDirectoryFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + } + assumeRole(workdir, filename.get(), CREATEDIRECTORIESPERMISSION); } - assumeRole(workdir, filename, CREATEDIRECTORIESPERMISSION); } } diff --git a/ctera/src/main/java/ch/cyberduck/core/ctera/CteraTouchFeature.java b/ctera/src/main/java/ch/cyberduck/core/ctera/CteraTouchFeature.java index a46bb64b93..63277b45ab 100644 --- a/ctera/src/main/java/ch/cyberduck/core/ctera/CteraTouchFeature.java +++ b/ctera/src/main/java/ch/cyberduck/core/ctera/CteraTouchFeature.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.text.MessageFormat; +import java.util.Optional; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.*; @@ -39,9 +40,11 @@ public class CteraTouchFeature extends DAVTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } // File/directory creation summary: diff --git a/ctera/src/test/java/ch/cyberduck/core/ctera/CteraDirectoryFeatureTest.java b/ctera/src/test/java/ch/cyberduck/core/ctera/CteraDirectoryFeatureTest.java index 2bcf015cf7..a8bb981b2e 100644 --- a/ctera/src/test/java/ch/cyberduck/core/ctera/CteraDirectoryFeatureTest.java +++ b/ctera/src/test/java/ch/cyberduck/core/ctera/CteraDirectoryFeatureTest.java @@ -32,6 +32,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.CREATEDIRECTORIESPERMISSION; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.READPERMISSION; @@ -54,21 +55,21 @@ public class CteraDirectoryFeatureTest extends AbstractCteraTest { public void testPreflightFileMissingCustomProps() throws Exception { final Path workdir = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); workdir.setAttributes(workdir.attributes().setAcl(Acl.EMPTY)); - new CteraDirectoryFeature(session).preflight(workdir, new AlphanumericRandomStringService().random()); + new CteraDirectoryFeature(session).preflight(workdir, Optional.of(new AlphanumericRandomStringService().random())); } @Test public void testPreflightFileAccessDeniedCustomProps() throws Exception { final Path workdir = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); workdir.setAttributes(workdir.attributes().setAcl(new Acl(new Acl.CanonicalUser(), READPERMISSION))); - assertThrows(AccessDeniedException.class, () -> new CteraDirectoryFeature(session).preflight(workdir, new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new CteraDirectoryFeature(session).preflight(workdir, Optional.of(new AlphanumericRandomStringService().random()))); } @Test public void testPreflightFileAccessGrantedCustomProps() throws Exception { final Path workdir = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); workdir.setAttributes(workdir.attributes().setAcl(new Acl(new Acl.CanonicalUser(), CREATEDIRECTORIESPERMISSION))); - new CteraDirectoryFeature(session).preflight(workdir, new AlphanumericRandomStringService().random()); + new CteraDirectoryFeature(session).preflight(workdir, Optional.of(new AlphanumericRandomStringService().random())); // assert no fail } } \ No newline at end of file diff --git a/ctera/src/test/java/ch/cyberduck/core/ctera/CteraTouchFeatureTest.java b/ctera/src/test/java/ch/cyberduck/core/ctera/CteraTouchFeatureTest.java index afe311c1c7..050ed111dc 100644 --- a/ctera/src/test/java/ch/cyberduck/core/ctera/CteraTouchFeatureTest.java +++ b/ctera/src/test/java/ch/cyberduck/core/ctera/CteraTouchFeatureTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import java.util.EnumSet; +import java.util.Optional; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.CREATEDIRECTORIESPERMISSION; import static ch.cyberduck.core.ctera.CteraAttributesFinderFeature.WRITEPERMISSION; @@ -38,28 +39,28 @@ public class CteraTouchFeatureTest extends AbstractCteraTest { public void testPreflightFileMissingCustomProps() throws Exception { final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); file.setAttributes(file.attributes().setAcl(Acl.EMPTY)); - new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random()); + new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random())); } @Test public void testPreflightReadPermission() throws Exception { final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); file.setAttributes(file.attributes().setAcl(new Acl(new Acl.CanonicalUser(), CteraAttributesFinderFeature.READPERMISSION))); - assertThrows(AccessDeniedException.class, () -> new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random()))); } @Test public void testPreflightNoPermissions() throws Exception { final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); file.setAttributes(file.attributes().setAcl(new Acl(new Acl.CanonicalUser()))); - assertThrows(AccessDeniedException.class, () -> new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random()))); } @Test public void testPreflightWritePermission() throws Exception { final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); file.setAttributes(file.attributes().setAcl(new Acl(new Acl.CanonicalUser(), CteraAttributesFinderFeature.WRITEPERMISSION))); - new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random()); + new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random())); // assert no fail } @@ -67,7 +68,7 @@ public class CteraTouchFeatureTest extends AbstractCteraTest { public void testPreflightCreateDirectoriesPermission() throws Exception { final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); file.setAttributes(file.attributes().setAcl(new Acl(new Acl.CanonicalUser(), CteraAttributesFinderFeature.CREATEDIRECTORIESPERMISSION))); - new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random()); + new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random())); // assert no fail } @@ -79,14 +80,14 @@ public class CteraTouchFeatureTest extends AbstractCteraTest { new Acl.UserAndRole(new Acl.CanonicalUser(), WRITEPERMISSION), new Acl.UserAndRole(new Acl.CanonicalUser(), CREATEDIRECTORIESPERMISSION) ))); - new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random()); + new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random())); // assert no fail } @Test public void testPreflightFileAccessGrantedCustomProps() throws Exception { final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random()); + new CteraTouchFeature(session).preflight(file, Optional.of(new AlphanumericRandomStringService().random())); // assert no fail } } \ No newline at end of file diff --git a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeature.java b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeature.java index 8cca83fab6..195359c6e2 100644 --- a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeature.java +++ b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeature.java @@ -34,6 +34,7 @@ import org.apache.logging.log4j.Logger; import java.util.Collections; import java.util.List; +import java.util.Optional; public class DeepboxDirectoryFeature implements Directory { private static final Logger log = LogManager.getLogger(DeepboxDirectoryFeature.class); @@ -89,7 +90,7 @@ public class DeepboxDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(containerService.isInbox(workdir)) { throw new AccessDeniedException(LocaleFactory.localizedString("Adding folders is not permitted in the inbox", "Deepbox")).withFile(workdir); } diff --git a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxTouchFeature.java b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxTouchFeature.java index 15c5d5b835..8b3cc99c54 100644 --- a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxTouchFeature.java +++ b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxTouchFeature.java @@ -26,6 +26,8 @@ import ch.cyberduck.core.shared.DefaultTouchFeature; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Optional; + import static ch.cyberduck.core.deepbox.DeepboxAttributesFinderFeature.CANADDCHILDREN; public class DeepboxTouchFeature extends DefaultTouchFeature { @@ -39,7 +41,7 @@ public class DeepboxTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted at the organisation level", "Deepbox")).withFile(workdir); } diff --git a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java index e74508acbf..774102451e 100644 --- a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java +++ b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java @@ -33,6 +33,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -45,7 +46,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path("/", EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(NotfoundException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -55,7 +56,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path("/ORG 4 - DeepBox Desktop App/", EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(NotfoundException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -65,7 +66,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(NotfoundException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -75,7 +76,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1", EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(AccessDeniedException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -85,7 +86,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(AccessDeniedException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -95,7 +96,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1/Inbox", EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(InteroperabilityException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -105,7 +106,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)/Inbox", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(InteroperabilityException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -115,7 +116,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); final Path parent = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1/Trash", EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, Optional.of(folder.getName()))); assertThrows(AccessDeniedException.class, () -> directory.mkdir(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -150,7 +151,7 @@ public class DeepboxDirectoryFeatureTest extends AbstractDeepboxTest { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); final Path documents = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1/Documents/", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new DeepboxDirectoryFeature(session, nodeid).mkdir(new DeepboxWriteFeature(session, nodeid), new Path(documents, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus()); - new DeepboxDirectoryFeature(session, nodeid).preflight(documents.withAttributes(new DeepboxAttributesFinderFeature(session, nodeid).find(documents)), test.getName()); + new DeepboxDirectoryFeature(session, nodeid).preflight(documents.withAttributes(new DeepboxAttributesFinderFeature(session, nodeid).find(documents)), Optional.of(test.getName())); assertTrue(new DeepboxFindFeature(session, nodeid).find(test)); new DeepboxDeleteFeature(session, nodeid).delete(Collections.singletonList(test), LoginCallback.noop, new Delete.DisabledCallback()); } diff --git a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxTouchFeatureTest.java b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxTouchFeatureTest.java index 14ac166f3a..c9594a6bc5 100644 --- a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxTouchFeatureTest.java +++ b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxTouchFeatureTest.java @@ -34,6 +34,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static ch.cyberduck.core.deepbox.DeepboxAttributesFinderFeature.CANADDCHILDREN; import static org.junit.Assert.*; @@ -44,7 +45,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { @Test public void testTouchRoot() throws Exception { final DeepboxIdProvider fileid = new DeepboxIdProvider(session); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, fileid).preflight(Home.root(), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, fileid).preflight(Home.root(), Optional.of(new AlphanumericRandomStringService().random()))); assertThrows(NotfoundException.class, () -> new DeepboxTouchFeature(session, fileid).touch(new DeepboxWriteFeature(session, fileid), new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus())); } @@ -53,7 +54,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final DeepboxIdProvider fileid = new DeepboxIdProvider(session); final Path documents = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1/Documents/", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new DeepboxTouchFeature(session, fileid).touch(new DeepboxWriteFeature(session, fileid), new Path(documents, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); - new DeepboxTouchFeature(session, fileid).preflight(documents.withAttributes(new DeepboxAttributesFinderFeature(session, fileid).find(documents)), test.getName()); + new DeepboxTouchFeature(session, fileid).preflight(documents.withAttributes(new DeepboxAttributesFinderFeature(session, fileid).find(documents)), Optional.of(test.getName())); assertTrue(new DeepboxFindFeature(session, fileid).find(test)); new DeepboxDeleteFeature(session, fileid).delete(Collections.singletonList(test), LoginCallback.noop, new Delete.DisabledCallback()); } @@ -73,7 +74,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final Path folder = new Path("/ORG 4 - DeepBox Desktop App/", EnumSet.of(Path.Type.directory, Path.Type.volume)); final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertEquals(Acl.EMPTY, attributes.getAcl()); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -82,7 +83,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final Path folder = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/", EnumSet.of(Path.Type.directory, Path.Type.volume)); final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertEquals(Acl.EMPTY, attributes.getAcl()); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -91,7 +92,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final Path folder = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1", EnumSet.of(Path.Type.directory, Path.Type.volume)); final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertEquals(Acl.EMPTY, attributes.getAcl()); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -102,9 +103,9 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { assertTrue(new BoxRestControllerApi(session.getClient()).getBox(ORG4_DEEPBOX4, ORG4_DEEPBOX4_BOX1).getBoxPolicy().isCanAddQueue()); assertTrue(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); // assert no fail - new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()); + new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random())); // DeepBox inbox is flat - assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -114,8 +115,8 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertFalse(new BoxRestControllerApi(session.getClient()).getBox(ORG1_DEEPBOX1, ORG1_DEEPBOX1_BOX1).getBoxPolicy().isCanAddQueue()); assertFalse(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); - assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); + assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -126,9 +127,9 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { assertTrue(new BoxRestControllerApi(session.getClient()).getBox(ORG4_DEEPBOX4, ORG4_DEEPBOX4_BOX1).getBoxPolicy().isCanAddFilesRoot()); assertTrue(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); // assert no fail - new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()); + new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random())); // assert no fail - new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()); + new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random())); } @Test @@ -138,8 +139,8 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertFalse(new BoxRestControllerApi(session.getClient()).getBox(ORG1_DEEPBOX1, ORG1_DEEPBOX1_BOX1).getBoxPolicy().isCanAddFilesRoot()); assertFalse(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); - assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); + assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -148,8 +149,8 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final Path folder = new Path("/ORG 1 - DeepBox Desktop App/ORG 1 - DeepBox Desktop App/ORG1:Box1/Trash/", EnumSet.of(Path.Type.directory, Path.Type.volume)); final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertFalse(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); - assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); + assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -160,9 +161,9 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { assertTrue(new CoreRestControllerApi(session.getClient()).getNodeInfo(attributes.getFileId(), null, null, null).getNode().getPolicy().isCanAddChildren()); assertTrue(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); // assert no fail - new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()); + new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random())); // assert no fail - new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()); + new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random())); } @Test @@ -172,8 +173,8 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertFalse(new CoreRestControllerApi(session.getClient()).getNodeInfo(attributes.getFileId(), null, null, null).getNode().getPolicy().isCanAddChildren()); assertFalse(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); - assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); + assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -183,8 +184,8 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final PathAttributes attributes = new DeepboxAttributesFinderFeature(session, nodeid).find(folder); assertFalse(new CoreRestControllerApi(session.getClient()).getNodeInfo(attributes.getFileId(), null, null, null).getNode().getPolicy().isCanAddChildren()); assertFalse(attributes.getAcl().get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); - assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); + assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), Optional.of(new AlphanumericRandomStringService().random()))); } @Test @@ -192,7 +193,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); final Path parent = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1/Trash", EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(parent, folder.getName())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(parent, Optional.of(folder.getName()))); assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).touch(new DeepboxWriteFeature(session, nodeid), folder, new TransferStatus())); } @@ -201,7 +202,7 @@ public class DeepboxTouchFeatureTest extends AbstractDeepboxTest { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); final Path file = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); - assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(parent, file.getName())); + assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(parent, Optional.of(file.getName()))); assertThrows(NotfoundException.class, () -> new DeepboxTouchFeature(session, nodeid).touch(new DeepboxWriteFeature(session, nodeid), file, new TransferStatus())); } } \ No newline at end of file diff --git a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDelegatingWriteFeature.java b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDelegatingWriteFeature.java index 22418432af..6096d6675d 100644 --- a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDelegatingWriteFeature.java +++ b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDelegatingWriteFeature.java @@ -31,6 +31,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.EnumSet; +import java.util.Optional; public class SDSDelegatingWriteFeature implements MultipartWrite { private static final Logger log = LogManager.getLogger(SDSDelegatingWriteFeature.class); @@ -68,7 +69,7 @@ public class SDSDelegatingWriteFeature implements MultipartWrite { @Override public void preflight(final Path file) throws BackgroundException { - new SDSTouchFeature(session, nodeid).preflight(file.getParent(), file.getName()); + new SDSTouchFeature(session, nodeid).preflight(file.getParent(), Optional.of(file.getName())); } @Override diff --git a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDirectoryFeature.java b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDirectoryFeature.java index 3acc2e1eb6..5c0f8b56f8 100644 --- a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDirectoryFeature.java +++ b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSDirectoryFeature.java @@ -32,12 +32,12 @@ import ch.cyberduck.core.sds.io.swagger.client.model.EncryptRoomRequest; import ch.cyberduck.core.sds.io.swagger.client.model.Node; import ch.cyberduck.core.transfer.TransferStatus; -import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.text.MessageFormat; import java.util.EnumSet; +import java.util.Optional; public class SDSDirectoryFeature implements Directory { private static final Logger log = LogManager.getLogger(SDSDirectoryFeature.class); @@ -102,15 +102,17 @@ public class SDSDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { if(!HostPreferencesFactory.get(session.getHost()).getBoolean("sds.create.dataroom.enable")) { log.warn("Disallow creating new top level data room {}", filename); throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)).withFile(workdir); } } - if(!SDSTouchFeature.validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + if(filename.isPresent()) { + if(!SDSTouchFeature.validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + } } final SDSPermissionsFeature permissions = new SDSPermissionsFeature(session, nodeid); if(!permissions.containsRole(workdir, SDSPermissionsFeature.CREATE_ROLE)) { diff --git a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSTouchFeature.java b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSTouchFeature.java index 9b858c142d..2d865152be 100644 --- a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSTouchFeature.java +++ b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSTouchFeature.java @@ -33,6 +33,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.text.MessageFormat; +import java.util.Optional; public class SDSTouchFeature extends DefaultTouchFeature { private static final Logger log = LogManager.getLogger(SDSTouchFeature.class); @@ -59,12 +60,14 @@ public class SDSTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); } - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } final SDSPermissionsFeature permissions = new SDSPermissionsFeature(session, nodeid); if(!permissions.containsRole(workdir, SDSPermissionsFeature.CREATE_ROLE) diff --git a/dracoon/src/test/java/ch/cyberduck/core/sds/SDSTouchFeatureTest.java b/dracoon/src/test/java/ch/cyberduck/core/sds/SDSTouchFeatureTest.java index 6ab91ae30a..f309a3db0e 100644 --- a/dracoon/src/test/java/ch/cyberduck/core/sds/SDSTouchFeatureTest.java +++ b/dracoon/src/test/java/ch/cyberduck/core/sds/SDSTouchFeatureTest.java @@ -35,7 +35,6 @@ import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.test.IntegrationTest; import org.apache.commons.lang3.RandomUtils; -import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -44,6 +43,7 @@ import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -53,9 +53,9 @@ public class SDSTouchFeatureTest extends AbstractSDSTest { @Test public void testSupported() { final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session); - assertTrue(new SDSTouchFeature(session, nodeid).isSupported(new Path(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), StringUtils.EMPTY)); - assertTrue(new SDSTouchFeature(session, nodeid).isSupported(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), StringUtils.EMPTY)); - assertFalse(new SDSTouchFeature(session, nodeid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), StringUtils.EMPTY)); + assertTrue(new SDSTouchFeature(session, nodeid).isSupported(new Path(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), Optional.empty())); + assertTrue(new SDSTouchFeature(session, nodeid).isSupported(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), Optional.empty())); + assertFalse(new SDSTouchFeature(session, nodeid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), Optional.empty())); } @Test(expected = BackgroundException.class) @@ -77,8 +77,8 @@ public class SDSTouchFeatureTest extends AbstractSDSTest { new SDSDirectS3MultipartWriteFeature(session, nodeid), new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus()); try { final SDSTouchFeature feature = new SDSTouchFeature(session, nodeid); - assertFalse(feature.isSupported(room, "?")); - assertThrows(InvalidFilenameException.class, () -> feature.preflight(room, "?")); + assertFalse(feature.isSupported(room, Optional.of("?"))); + assertThrows(InvalidFilenameException.class, () -> feature.preflight(room, Optional.of("?"))); feature.touch(new SDSDirectS3MultipartWriteFeature(session, nodeid), new Path(room, "CON", EnumSet.of(Path.Type.file)), new TransferStatus()); } catch(InteroperabilityException e) { @@ -97,8 +97,8 @@ public class SDSTouchFeatureTest extends AbstractSDSTest { new SDSDirectS3MultipartWriteFeature(session, nodeid), new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus()); try { final SDSTouchFeature feature = new SDSTouchFeature(session, nodeid); - assertFalse(feature.isSupported(room, "?")); - assertThrows(InvalidFilenameException.class, () -> feature.preflight(room, "?")); + assertFalse(feature.isSupported(room, Optional.of("?"))); + assertThrows(InvalidFilenameException.class, () -> feature.preflight(room, Optional.of("?"))); feature.touch(new SDSDirectS3MultipartWriteFeature(session, nodeid), new Path(room, "?", EnumSet.of(Path.Type.file)), new TransferStatus()); } catch(InteroperabilityException e) { @@ -132,7 +132,7 @@ public class SDSTouchFeatureTest extends AbstractSDSTest { final long quota = 1L + PreferencesFactory.get().getInteger("sds.upload.multipart.chunksize"); updateRoomRequest.setQuota(quota); assertEquals(quota, new NodesApi(session.getClient()).updateRoom(updateRoomRequest, Long.valueOf(room.attributes().getVersionId()), null).getQuota(), 0L); - assertTrue(new SDSTouchFeature(session, nodeid).isSupported(room.withAttributes(new SDSAttributesFinderFeature(session, nodeid).find(room)), StringUtils.EMPTY)); + assertTrue(new SDSTouchFeature(session, nodeid).isSupported(room.withAttributes(new SDSAttributesFinderFeature(session, nodeid).find(room)), Optional.empty())); assertEquals(quota, room.attributes().getQuota().available, 0L); final byte[] content = RandomUtils.nextBytes(2); final TransferStatus status = new TransferStatus(); @@ -150,7 +150,7 @@ public class SDSTouchFeatureTest extends AbstractSDSTest { } } while(attr.getSize() != 2L); - assertFalse(new SDSTouchFeature(session, nodeid).isSupported(room.withAttributes(attr), StringUtils.EMPTY)); + assertFalse(new SDSTouchFeature(session, nodeid).isSupported(room.withAttributes(attr), Optional.empty())); assertEquals(quota, attr.getQuota().available, 0L); assertEquals(2L, attr.getSize()); new SDSDeleteFeature(session, nodeid).delete(Arrays.asList(test, room), LoginCallback.noop, new Delete.DisabledCallback()); diff --git a/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxDirectoryFeature.java b/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxDirectoryFeature.java index 0df75ae462..7d8dcb7360 100644 --- a/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxDirectoryFeature.java +++ b/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxDirectoryFeature.java @@ -25,6 +25,7 @@ import ch.cyberduck.core.features.Write; import ch.cyberduck.core.transfer.TransferStatus; import java.text.MessageFormat; +import java.util.Optional; import com.dropbox.core.DbxException; import com.dropbox.core.v2.files.CreateFolderResult; @@ -54,9 +55,11 @@ public class DropboxDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!DropboxTouchFeature.validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!DropboxTouchFeature.validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + } } } } diff --git a/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxTouchFeature.java b/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxTouchFeature.java index 7fd223c4b2..11eacb7f06 100644 --- a/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxTouchFeature.java +++ b/dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxTouchFeature.java @@ -24,6 +24,7 @@ import ch.cyberduck.core.shared.DefaultTouchFeature; import org.apache.commons.lang3.StringUtils; import java.text.MessageFormat; +import java.util.Optional; import com.dropbox.core.v2.files.Metadata; @@ -42,9 +43,11 @@ public class DropboxTouchFeature extends DefaultTouchFeature { * @throws InvalidFilenameException If restricted filename */ @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } } diff --git a/dropbox/src/test/java/ch/cyberduck/core/dropbox/DropboxTouchFeatureTest.java b/dropbox/src/test/java/ch/cyberduck/core/dropbox/DropboxTouchFeatureTest.java index 1534cd1a24..655f34ede3 100644 --- a/dropbox/src/test/java/ch/cyberduck/core/dropbox/DropboxTouchFeatureTest.java +++ b/dropbox/src/test/java/ch/cyberduck/core/dropbox/DropboxTouchFeatureTest.java @@ -41,6 +41,7 @@ import org.junit.experimental.categories.Category; import java.io.ByteArrayInputStream; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -51,7 +52,7 @@ public class DropboxTouchFeatureTest extends AbstractDropboxTest { public void testDisallowedName() throws Exception { final DropboxTouchFeature touch = new DropboxTouchFeature(session); final Path file = new Path(new DefaultHomeFinderService(session).find(), String.format("~%s.tmp", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)); - assertFalse(touch.isSupported(new DefaultHomeFinderService(session).find(), file.getName())); + assertFalse(touch.isSupported(new DefaultHomeFinderService(session).find(), Optional.of(file.getName()))); touch.touch(new DropboxWriteFeature(session), file, new TransferStatus()); } diff --git a/eue/src/main/java/ch/cyberduck/core/eue/EueDirectoryFeature.java b/eue/src/main/java/ch/cyberduck/core/eue/EueDirectoryFeature.java index 267298c742..e62e638d4e 100644 --- a/eue/src/main/java/ch/cyberduck/core/eue/EueDirectoryFeature.java +++ b/eue/src/main/java/ch/cyberduck/core/eue/EueDirectoryFeature.java @@ -38,6 +38,7 @@ import org.apache.logging.log4j.Logger; import java.text.MessageFormat; import java.util.Collections; +import java.util.Optional; public class EueDirectoryFeature implements Directory { private static final Logger log = LogManager.getLogger(EueDirectoryFeature.class); @@ -89,9 +90,11 @@ public class EueDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!EueTouchFeature.validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!EueTouchFeature.validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); + } } } } diff --git a/eue/src/main/java/ch/cyberduck/core/eue/EueTouchFeature.java b/eue/src/main/java/ch/cyberduck/core/eue/EueTouchFeature.java index 71a790c8cf..209eadb6f2 100644 --- a/eue/src/main/java/ch/cyberduck/core/eue/EueTouchFeature.java +++ b/eue/src/main/java/ch/cyberduck/core/eue/EueTouchFeature.java @@ -24,6 +24,7 @@ import ch.cyberduck.core.shared.DefaultTouchFeature; import org.apache.commons.lang3.StringUtils; import java.text.MessageFormat; +import java.util.Optional; public class EueTouchFeature extends DefaultTouchFeature { @@ -32,9 +33,11 @@ public class EueTouchFeature extends DefaultTouchFeature } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { - if(!validate(filename)) { - throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { + if(filename.isPresent()) { + if(!validate(filename.get())) { + throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)); + } } } diff --git a/eue/src/test/java/ch/cyberduck/core/eue/EueTouchFeatureTest.java b/eue/src/test/java/ch/cyberduck/core/eue/EueTouchFeatureTest.java index ec079c0b80..d64891a7c5 100644 --- a/eue/src/test/java/ch/cyberduck/core/eue/EueTouchFeatureTest.java +++ b/eue/src/test/java/ch/cyberduck/core/eue/EueTouchFeatureTest.java @@ -30,6 +30,7 @@ import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; @@ -40,12 +41,12 @@ public class EueTouchFeatureTest extends AbstractEueSessionTest { @Test public void testSupported() { final EueResourceIdProvider fileid = new EueResourceIdProvider(session); - assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), "f >f")); - assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), "f ")); - assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), "f.")); + assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), Optional.of("f >f"))); + assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), Optional.of("f "))); + assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), Optional.of("f."))); // max path length exceeded. Allowed are 250, but the length was 255 assertFalse(new EueTouchFeature(session, fileid).isSupported(new Path("/", EnumSet.of(Path.Type.directory)), - new AsciiRandomStringService(255).random())); + Optional.of(new AsciiRandomStringService(255).random()))); } @Test diff --git a/ftp/src/main/java/ch/cyberduck/core/ftp/FTPDirectoryFeature.java b/ftp/src/main/java/ch/cyberduck/core/ftp/FTPDirectoryFeature.java index f2425aab4d..3483e4363d 100644 --- a/ftp/src/main/java/ch/cyberduck/core/ftp/FTPDirectoryFeature.java +++ b/ftp/src/main/java/ch/cyberduck/core/ftp/FTPDirectoryFeature.java @@ -27,6 +27,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import org.apache.commons.net.ftp.FTPReply; import java.io.IOException; +import java.util.Optional; public class FTPDirectoryFeature implements Directory { @@ -57,7 +58,7 @@ public class FTPDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) { + public void preflight(final Path workdir, final Optional filename) { // Skip checking permission mask } } diff --git a/ftp/src/main/java/ch/cyberduck/core/ftp/FTPTouchFeature.java b/ftp/src/main/java/ch/cyberduck/core/ftp/FTPTouchFeature.java index 292aecd4bd..29f236a1de 100644 --- a/ftp/src/main/java/ch/cyberduck/core/ftp/FTPTouchFeature.java +++ b/ftp/src/main/java/ch/cyberduck/core/ftp/FTPTouchFeature.java @@ -18,6 +18,8 @@ package ch.cyberduck.core.ftp; import ch.cyberduck.core.Path; import ch.cyberduck.core.shared.DefaultTouchFeature; +import java.util.Optional; + public class FTPTouchFeature extends DefaultTouchFeature { public FTPTouchFeature(final FTPSession session) { @@ -25,7 +27,7 @@ public class FTPTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) { + public void preflight(final Path workdir, final Optional filename) { // Skip checking permission mask } } diff --git a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveDirectoryFeature.java b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveDirectoryFeature.java index fa5106a272..e0639b0f64 100644 --- a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveDirectoryFeature.java +++ b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveDirectoryFeature.java @@ -17,7 +17,6 @@ package ch.cyberduck.core.googledrive; import ch.cyberduck.core.DefaultPathAttributes; import ch.cyberduck.core.Path; -import ch.cyberduck.core.PathAttributes; import ch.cyberduck.core.SimplePathPredicate; import ch.cyberduck.core.UUIDRandomStringService; import ch.cyberduck.core.exception.BackgroundException; @@ -30,6 +29,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import java.io.IOException; import java.util.Collections; +import java.util.Optional; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; @@ -81,7 +81,7 @@ public class DriveDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { new DriveTouchFeature(session, fileid).preflight(workdir, filename); } } diff --git a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTouchFeature.java b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTouchFeature.java index c2f3ef49bf..d6897f8c66 100644 --- a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTouchFeature.java +++ b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTouchFeature.java @@ -30,6 +30,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import java.io.IOException; import java.text.MessageFormat; import java.util.Collections; +import java.util.Optional; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; @@ -71,7 +72,7 @@ public class DriveTouchFeature implements Touch { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); } diff --git a/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageDirectoryFeature.java b/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageDirectoryFeature.java index 2caf0516a5..1fa55eba82 100644 --- a/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageDirectoryFeature.java +++ b/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageDirectoryFeature.java @@ -32,6 +32,7 @@ import org.jets3t.service.utils.ServiceUtils; import java.io.IOException; import java.text.MessageFormat; import java.util.EnumSet; +import java.util.Optional; import com.google.api.services.storage.Storage; import com.google.api.services.storage.model.Bucket; @@ -77,20 +78,19 @@ public class GoogleStorageDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { - if(StringUtils.isNotBlank(filename)) { - if(StringUtils.startsWith(filename, "goog")) { + if(filename.isPresent()) { + if(StringUtils.startsWith(filename.get(), "goog")) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } - if(StringUtils.contains(filename, "google")) { + if(StringUtils.contains(filename.get(), "google")) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } - if(!ServiceUtils.isBucketNameValidDNSName(filename)) { + if(!ServiceUtils.isBucketNameValidDNSName(filename.get())) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } } } } - } diff --git a/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageTouchFeature.java b/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageTouchFeature.java index 38dd91a90e..159c1f901f 100644 --- a/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageTouchFeature.java +++ b/googlestorage/src/main/java/ch/cyberduck/core/googlestorage/GoogleStorageTouchFeature.java @@ -22,6 +22,7 @@ import ch.cyberduck.core.exception.BackgroundException; import ch.cyberduck.core.shared.DefaultTouchFeature; import java.text.MessageFormat; +import java.util.Optional; import com.google.api.services.storage.model.StorageObject; @@ -32,7 +33,7 @@ public class GoogleStorageTouchFeature extends DefaultTouchFeature filename) throws BackgroundException { // Creating files is only possible inside a bucket. if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); diff --git a/irods/src/main/java/ch/cyberduck/core/irods/IRODSTouchFeature.java b/irods/src/main/java/ch/cyberduck/core/irods/IRODSTouchFeature.java index 608fc277e7..2f4123d983 100644 --- a/irods/src/main/java/ch/cyberduck/core/irods/IRODSTouchFeature.java +++ b/irods/src/main/java/ch/cyberduck/core/irods/IRODSTouchFeature.java @@ -22,8 +22,6 @@ import ch.cyberduck.core.features.Touch; import ch.cyberduck.core.features.Write; import ch.cyberduck.core.transfer.TransferStatus; -import com.fasterxml.jackson.databind.ObjectMapper; - import org.irods.irods4j.high_level.connection.IRODSConnection; import org.irods.irods4j.low_level.api.IRODSApi; import org.irods.irods4j.low_level.api.IRODSException; @@ -32,6 +30,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import com.fasterxml.jackson.databind.ObjectMapper; + public class IRODSTouchFeature implements Touch { private static final ObjectMapper mapper = new ObjectMapper(); @@ -66,9 +66,4 @@ public class IRODSTouchFeature implements Touch { throw new DefaultIOExceptionMappingService().map("Cannot create {0}", e, file); } } - - @Override - public boolean isSupported(final Path workdir, final String filename) { - return true; - } } diff --git a/manta/src/main/java/ch/cyberduck/core/manta/MantaDirectoryFeature.java b/manta/src/main/java/ch/cyberduck/core/manta/MantaDirectoryFeature.java index 82f90ca2e8..3f74bc4261 100644 --- a/manta/src/main/java/ch/cyberduck/core/manta/MantaDirectoryFeature.java +++ b/manta/src/main/java/ch/cyberduck/core/manta/MantaDirectoryFeature.java @@ -26,11 +26,12 @@ import ch.cyberduck.core.transfer.TransferStatus; import java.io.IOException; import java.text.MessageFormat; +import java.util.Optional; import com.joyent.manta.exception.MantaClientHttpResponseException; import com.joyent.manta.exception.MantaException; -public class MantaDirectoryFeature implements Directory { +public class MantaDirectoryFeature implements Directory { private final MantaSession session; @@ -39,7 +40,7 @@ public class MantaDirectoryFeature implements Directory { } @Override - public Path mkdir(final Write writer, final Path folder, final TransferStatus status) throws BackgroundException { + public Path mkdir(final Write writer, final Path folder, final TransferStatus status) throws BackgroundException { try { session.getClient().putDirectory(folder.getAbsolute()); return folder; @@ -56,7 +57,7 @@ public class MantaDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(!session.isUserWritable(workdir)) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)).withFile(workdir); } diff --git a/manta/src/main/java/ch/cyberduck/core/manta/MantaTouchFeature.java b/manta/src/main/java/ch/cyberduck/core/manta/MantaTouchFeature.java index e1924e7045..834aa624d7 100644 --- a/manta/src/main/java/ch/cyberduck/core/manta/MantaTouchFeature.java +++ b/manta/src/main/java/ch/cyberduck/core/manta/MantaTouchFeature.java @@ -26,6 +26,7 @@ import ch.cyberduck.core.transfer.TransferStatus; import java.io.IOException; import java.text.MessageFormat; +import java.util.Optional; import com.joyent.manta.client.MantaObjectResponse; import com.joyent.manta.exception.MantaClientHttpResponseException; @@ -60,7 +61,7 @@ public class MantaTouchFeature implements Touch { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(!session.isUserWritable(workdir)) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); } diff --git a/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphDirectoryFeature.java b/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphDirectoryFeature.java index 6dc963bb4c..d3a31acef5 100644 --- a/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphDirectoryFeature.java +++ b/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphDirectoryFeature.java @@ -34,6 +34,7 @@ import org.nuxeo.onedrive.client.types.DriveItem; import java.io.IOException; import java.text.MessageFormat; +import java.util.Optional; public class GraphDirectoryFeature implements Directory { @@ -68,7 +69,7 @@ public class GraphDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(!session.isAccessible(workdir)) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)).withFile(workdir); } diff --git a/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphTouchFeature.java b/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphTouchFeature.java index 126b46c05b..b21317524f 100644 --- a/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphTouchFeature.java +++ b/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphTouchFeature.java @@ -37,6 +37,7 @@ import org.nuxeo.onedrive.client.types.DriveItem; import java.io.IOException; import java.text.MessageFormat; +import java.util.Optional; public class GraphTouchFeature implements Touch { @@ -70,7 +71,7 @@ public class GraphTouchFeature implements Touch { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(!session.isAccessible(workdir)) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); } diff --git a/onedrive/src/test/java/ch/cyberduck/core/onedrive/OfflineGraphDirectoryTouchFeatureTest.java b/onedrive/src/test/java/ch/cyberduck/core/onedrive/OfflineGraphDirectoryTouchFeatureTest.java index 14ac1fa826..15ba9f8597 100644 --- a/onedrive/src/test/java/ch/cyberduck/core/onedrive/OfflineGraphDirectoryTouchFeatureTest.java +++ b/onedrive/src/test/java/ch/cyberduck/core/onedrive/OfflineGraphDirectoryTouchFeatureTest.java @@ -32,6 +32,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.List; +import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -107,11 +108,11 @@ public class OfflineGraphDirectoryTouchFeatureTest { if(feature instanceof Touch) { final Touch touch = (Touch) feature; - assertEquals(String.format("Create \"%s\" in \"%s\".", name, parent.getAbsolute()), testCase.isValid, touch.isSupported(parent, name)); + assertEquals(String.format("Create \"%s\" in \"%s\".", name, parent.getAbsolute()), testCase.isValid, touch.isSupported(parent, Optional.of(name))); } else if(feature instanceof Directory) { final Directory directory = (Directory) feature; - assertEquals(String.format("Create \"%s\" in \"%s\".", name, parent.getAbsolute()), testCase.isValid, directory.isSupported(parent, name)); + assertEquals(String.format("Create \"%s\" in \"%s\".", name, parent.getAbsolute()), testCase.isValid, directory.isSupported(parent, Optional.of(name))); } else { fail(); diff --git a/openstack/src/main/java/ch/cyberduck/core/openstack/SwiftTouchFeature.java b/openstack/src/main/java/ch/cyberduck/core/openstack/SwiftTouchFeature.java index 44faaea64d..768ac4c7b6 100644 --- a/openstack/src/main/java/ch/cyberduck/core/openstack/SwiftTouchFeature.java +++ b/openstack/src/main/java/ch/cyberduck/core/openstack/SwiftTouchFeature.java @@ -25,6 +25,7 @@ import ch.cyberduck.core.exception.BackgroundException; import ch.cyberduck.core.shared.DefaultTouchFeature; import java.text.MessageFormat; +import java.util.Optional; import ch.iterate.openstack.swift.model.StorageObject; @@ -35,7 +36,7 @@ public class SwiftTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { // Creating files is only possible inside a container. if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); diff --git a/openstack/src/test/java/ch/cyberduck/core/openstack/SwiftTouchFeatureTest.java b/openstack/src/test/java/ch/cyberduck/core/openstack/SwiftTouchFeatureTest.java index 64dcdd3e2f..5aff74774b 100644 --- a/openstack/src/test/java/ch/cyberduck/core/openstack/SwiftTouchFeatureTest.java +++ b/openstack/src/test/java/ch/cyberduck/core/openstack/SwiftTouchFeatureTest.java @@ -8,11 +8,11 @@ import ch.cyberduck.core.SimplePathPredicate; import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.test.IntegrationTest; -import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.experimental.categories.Category; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -21,8 +21,8 @@ public class SwiftTouchFeatureTest extends AbstractSwiftTest { @Test public void testSupported() { - assertFalse(new SwiftTouchFeature(session, new SwiftRegionService(session)).isSupported(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), StringUtils.EMPTY)); - assertTrue(new SwiftTouchFeature(session, new SwiftRegionService(session)).isSupported(new Path("/container", EnumSet.of(Path.Type.directory, Path.Type.volume)), StringUtils.EMPTY)); + assertFalse(new SwiftTouchFeature(session, new SwiftRegionService(session)).isSupported(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), Optional.empty())); + assertTrue(new SwiftTouchFeature(session, new SwiftRegionService(session)).isSupported(new Path("/container", EnumSet.of(Path.Type.directory, Path.Type.volume)), Optional.empty())); } @Test diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java index f93a3c75e6..cd3d344695 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java @@ -2727,8 +2727,7 @@ public class BrowserController extends WindowController implements NSToolbar.Del uploadPanel = NSOpenPanel.openPanel(); uploadPanel.setCanChooseDirectories(true); uploadPanel.setCanChooseFiles(pool.getFeature(Touch.class).isSupported( - new UploadTargetFinder(workdir).find(this.getSelectedPath()), - StringUtils.EMPTY)); + new UploadTargetFinder(workdir).find(this.getSelectedPath()), Optional.empty())); uploadPanel.setCanCreateDirectories(false); uploadPanel.setTreatsFilePackagesAsDirectories(true); uploadPanel.setAllowsMultipleSelection(true); diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BrowserTableDataSource.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BrowserTableDataSource.java index 2ed9c1564e..7a494d675b 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BrowserTableDataSource.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BrowserTableDataSource.java @@ -470,7 +470,7 @@ public abstract class BrowserTableDataSource extends ProxyController implements return NSDraggingInfo.NSDragOperationNone; } final Touch feature = controller.getSession().getFeature(Touch.class); - if(!feature.isSupported(destination, StringUtils.EMPTY)) { + if(!feature.isSupported(destination, Optional.empty())) { // Target file system does not support creating files. Creating files is not supported // for example in root of cloud storage accounts. return NSDraggingInfo.NSDragOperationNone; diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/toolbar/BrowserToolbarValidator.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/toolbar/BrowserToolbarValidator.java index 1d8ced19bf..00e784ca9b 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/toolbar/BrowserToolbarValidator.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/toolbar/BrowserToolbarValidator.java @@ -45,7 +45,6 @@ import ch.cyberduck.core.vault.VaultRegistry; import ch.cyberduck.ui.browser.UploadTargetFinder; import ch.cyberduck.ui.cocoa.controller.BrowserController; -import org.apache.commons.lang3.StringUtils; import org.rococoa.Foundation; import org.rococoa.Rococoa; import org.rococoa.Selector; @@ -236,25 +235,25 @@ public class BrowserToolbarValidator implements ToolbarValidator { else if(action.equals(newfolder.action())) { return this.isBrowser() && controller.isMounted() && controller.getSession().getFeature(Directory.class).isSupported( - new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), StringUtils.EMPTY + new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), Optional.empty() ); } else if(action.equals(Foundation.selector("createEncryptedVaultButtonClicked:"))) { return this.isBrowser() && controller.isMounted() && controller.getSession().getVaultRegistry() != VaultRegistry.DISABLED && !controller.getSession().getVaultRegistry().contains(controller.workdir()) && controller.getSession().getFeature(Directory.class).isSupported( - new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), StringUtils.EMPTY + new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), Optional.empty() ); } else if(action.equals(Foundation.selector("createFileButtonClicked:"))) { return this.isBrowser() && controller.isMounted() && controller.getSession().getFeature(Touch.class).isSupported( - new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), StringUtils.EMPTY + new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), Optional.empty() ); } else if(action.equals(upload.action())) { return this.isBrowser() && controller.isMounted() && controller.getSession().getFeature(Touch.class).isSupported( new UploadTargetFinder(controller.workdir()).find(controller.getSelectedPath()), - StringUtils.EMPTY); + Optional.empty()); } else if(action.equals(Foundation.selector("createSymlinkButtonClicked:"))) { return this.isBrowser() && controller.isMounted() && controller.getSession().getFeature(Symlink.class) != null diff --git a/s3/src/main/java/ch/cyberduck/core/s3/S3DirectoryFeature.java b/s3/src/main/java/ch/cyberduck/core/s3/S3DirectoryFeature.java index a2385695b1..83f95e99c4 100644 --- a/s3/src/main/java/ch/cyberduck/core/s3/S3DirectoryFeature.java +++ b/s3/src/main/java/ch/cyberduck/core/s3/S3DirectoryFeature.java @@ -33,6 +33,7 @@ import org.jets3t.service.utils.ServiceUtils; import java.text.MessageFormat; import java.util.EnumSet; +import java.util.Optional; public class S3DirectoryFeature implements Directory { @@ -69,11 +70,11 @@ public class S3DirectoryFeature implements Directory { @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(StringUtils.isEmpty(RequestEntityRestStorageService.findBucketInHostname(session.getHost()))) { if(workdir.isRoot()) { - if(StringUtils.isNotBlank(filename)) { - if(!ServiceUtils.isBucketNameValidDNSName(filename)) { + if(filename.isPresent()) { + if(!ServiceUtils.isBucketNameValidDNSName(filename.get())) { throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)); } } diff --git a/s3/src/main/java/ch/cyberduck/core/s3/S3TouchFeature.java b/s3/src/main/java/ch/cyberduck/core/s3/S3TouchFeature.java index 4e0f148bd4..9a013fdffa 100644 --- a/s3/src/main/java/ch/cyberduck/core/s3/S3TouchFeature.java +++ b/s3/src/main/java/ch/cyberduck/core/s3/S3TouchFeature.java @@ -31,6 +31,7 @@ import org.apache.commons.lang3.StringUtils; import org.jets3t.service.model.StorageObject; import java.text.MessageFormat; +import java.util.Optional; public class S3TouchFeature extends DefaultTouchFeature { @@ -47,7 +48,7 @@ public class S3TouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(StringUtils.isEmpty(RequestEntityRestStorageService.findBucketInHostname(session.getHost()))) { // Creating files is only possible inside a bucket. if(workdir.isRoot()) { diff --git a/s3/src/test/java/ch/cyberduck/core/s3/S3DirectoryFeatureTest.java b/s3/src/test/java/ch/cyberduck/core/s3/S3DirectoryFeatureTest.java index 3153b3ff18..24efb0bd6e 100644 --- a/s3/src/test/java/ch/cyberduck/core/s3/S3DirectoryFeatureTest.java +++ b/s3/src/test/java/ch/cyberduck/core/s3/S3DirectoryFeatureTest.java @@ -39,6 +39,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import static org.junit.Assert.*; @@ -59,7 +60,7 @@ public class S3DirectoryFeatureTest extends AbstractS3Test { break; default: final Path test = new Path(new DefaultHomeFinderService(session).find(), new AsciiRandomStringService(30).random(), EnumSet.of(Path.Type.directory, Path.Type.volume)); - assertTrue(feature.isSupported(test.getParent(), test.getName())); + assertTrue(feature.isSupported(test.getParent(), Optional.of(test.getName()))); test.attributes().setRegion(region.getIdentifier()); feature.mkdir(new S3WriteFeature(session, new S3AccessControlListFeature(session)), test, new TransferStatus().setRegion(region.getIdentifier())); assertTrue(new S3FindFeature(session, acl).find(test)); @@ -92,7 +93,7 @@ public class S3DirectoryFeatureTest extends AbstractS3Test { final S3DirectoryFeature feature = new S3DirectoryFeature(session, acl); for(Location.Name region : Collections.singletonList(new S3LocationFeature.S3Region("us-east-1"))) { final Path test = new Path(new DefaultHomeFinderService(session).find(), new AsciiRandomStringService(30).random(), EnumSet.of(Path.Type.directory, Path.Type.volume)); - assertTrue(feature.isSupported(test.getParent(), test.getName())); + assertTrue(feature.isSupported(test.getParent(), Optional.of(test.getName()))); test.attributes().setRegion(region.getIdentifier()); feature.mkdir(new S3WriteFeature(session, new S3AccessControlListFeature(session)), test, new TransferStatus().setRegion(region.getIdentifier())); assertTrue(new S3FindFeature(session, acl).find(test)); @@ -125,7 +126,7 @@ public class S3DirectoryFeatureTest extends AbstractS3Test { final S3DirectoryFeature feature = new S3DirectoryFeature(session, acl); for(Location.Name region : Collections.singletonList(new S3LocationFeature.S3Region("us-east-1"))) { final Path test = new Path(new DefaultHomeFinderService(session).find(), new AsciiRandomStringService(30).random(), EnumSet.of(Path.Type.directory, Path.Type.volume)); - assertTrue(feature.isSupported(test.getParent(), test.getName())); + assertTrue(feature.isSupported(test.getParent(), Optional.of(test.getName()))); test.attributes().setRegion(region.getIdentifier()); feature.mkdir(new S3WriteFeature(session, new S3AccessControlListFeature(session)), test, new TransferStatus().setRegion(region.getIdentifier())); assertTrue(new S3FindFeature(session, acl).find(test)); @@ -139,8 +140,8 @@ public class S3DirectoryFeatureTest extends AbstractS3Test { public void testCreateBucketInvalidName() throws Exception { final S3AccessControlListFeature acl = new S3AccessControlListFeature(session); final Path test = new Path(new DefaultHomeFinderService(session).find(), "untitled folder", EnumSet.of(Path.Type.directory, Path.Type.volume)); - assertFalse(new S3DirectoryFeature(session, acl).isSupported(test.getParent(), test.getName())); - assertTrue(new S3DirectoryFeature(virtualhost, acl).isSupported(test.getParent(), test.getName())); + assertFalse(new S3DirectoryFeature(session, acl).isSupported(test.getParent(), Optional.of(test.getName()))); + assertTrue(new S3DirectoryFeature(virtualhost, acl).isSupported(test.getParent(), Optional.of(test.getName()))); final S3LocationFeature.S3Region region = new S3LocationFeature.S3Region("eu-west-2"); test.attributes().setRegion(region.getIdentifier()); new S3DirectoryFeature(session, acl).mkdir(new S3WriteFeature(session, new S3AccessControlListFeature(session)), test, new TransferStatus().setRegion(region.getIdentifier())); diff --git a/s3/src/test/java/ch/cyberduck/core/s3/S3TouchFeatureTest.java b/s3/src/test/java/ch/cyberduck/core/s3/S3TouchFeatureTest.java index 75e32b6f3c..352f658f4d 100644 --- a/s3/src/test/java/ch/cyberduck/core/s3/S3TouchFeatureTest.java +++ b/s3/src/test/java/ch/cyberduck/core/s3/S3TouchFeatureTest.java @@ -14,12 +14,12 @@ import ch.cyberduck.core.shared.DefaultFindFeature; import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.test.IntegrationTest; -import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.*; @@ -29,10 +29,10 @@ public class S3TouchFeatureTest extends AbstractS3Test { @Test public void testFile() { final S3AccessControlListFeature acl = new S3AccessControlListFeature(session); - assertFalse(new S3TouchFeature(session, acl).isSupported(Home.root(), StringUtils.EMPTY)); - assertTrue(new S3TouchFeature(session, acl).isSupported(new Path(Home.root(), "/container", EnumSet.of(Path.Type.volume, Path.Type.directory)), StringUtils.EMPTY)); - assertTrue(new S3TouchFeature(virtualhost, acl).isSupported(Home.root(), StringUtils.EMPTY)); - assertTrue(new S3TouchFeature(virtualhost, acl).isSupported(new Path(Home.root(), "/container", EnumSet.of(Path.Type.volume, Path.Type.directory)), StringUtils.EMPTY)); + assertFalse(new S3TouchFeature(session, acl).isSupported(Home.root(), Optional.empty())); + assertTrue(new S3TouchFeature(session, acl).isSupported(new Path(Home.root(), "/container", EnumSet.of(Path.Type.volume, Path.Type.directory)), Optional.empty())); + assertTrue(new S3TouchFeature(virtualhost, acl).isSupported(Home.root(), Optional.empty())); + assertTrue(new S3TouchFeature(virtualhost, acl).isSupported(new Path(Home.root(), "/container", EnumSet.of(Path.Type.volume, Path.Type.directory)), Optional.empty())); } @Test @@ -41,8 +41,8 @@ public class S3TouchFeatureTest extends AbstractS3Test { final S3AccessControlListFeature acl = new S3AccessControlListFeature(session); final S3TouchFeature feature = new S3TouchFeature(session, acl); final String filename = new AsciiRandomStringService().random(); - assertFalse(feature.isSupported(Home.root(), filename)); - assertTrue(feature.isSupported(container, filename)); + assertFalse(feature.isSupported(Home.root(), Optional.of(filename))); + assertTrue(feature.isSupported(container, Optional.of(filename))); final Path test = feature.touch(new S3WriteFeature(session, new S3AccessControlListFeature(session)), new Path(container, filename, EnumSet.of(Path.Type.file)), new TransferStatus()); assertNull(test.attributes().getVersionId()); assertTrue(new S3FindFeature(session, acl).find(test)); @@ -57,7 +57,7 @@ public class S3TouchFeatureTest extends AbstractS3Test { final S3AccessControlListFeature acl = new S3AccessControlListFeature(virtualhost); final S3TouchFeature feature = new S3TouchFeature(virtualhost, acl); final String filename = new AsciiRandomStringService().random(); - assertTrue(feature.isSupported(Home.root(), filename)); + assertTrue(feature.isSupported(Home.root(), Optional.of(filename))); final Path test = feature.touch(new S3WriteFeature(virtualhost, new S3AccessControlListFeature(virtualhost)), new Path(filename, EnumSet.of(Path.Type.file)), new TransferStatus()); assertNull(test.attributes().getVersionId()); assertTrue(new S3FindFeature(virtualhost, acl).find(test)); diff --git a/spectra/src/main/java/ch/cyberduck/core/spectra/SpectraTouchFeature.java b/spectra/src/main/java/ch/cyberduck/core/spectra/SpectraTouchFeature.java index 23d5e73846..6b842e698e 100644 --- a/spectra/src/main/java/ch/cyberduck/core/spectra/SpectraTouchFeature.java +++ b/spectra/src/main/java/ch/cyberduck/core/spectra/SpectraTouchFeature.java @@ -29,6 +29,7 @@ import org.jets3t.service.model.StorageObject; import java.text.MessageFormat; import java.util.Collections; +import java.util.Optional; public class SpectraTouchFeature extends DefaultTouchFeature { @@ -47,7 +48,7 @@ public class SpectraTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { // Creating files is only possible inside a bucket. if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); diff --git a/spectra/src/test/java/ch/cyberduck/core/spectra/SpectraTouchFeatureTest.java b/spectra/src/test/java/ch/cyberduck/core/spectra/SpectraTouchFeatureTest.java index 2bfe23806b..7d0f446d59 100644 --- a/spectra/src/test/java/ch/cyberduck/core/spectra/SpectraTouchFeatureTest.java +++ b/spectra/src/test/java/ch/cyberduck/core/spectra/SpectraTouchFeatureTest.java @@ -22,12 +22,12 @@ import ch.cyberduck.core.features.Home; import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.test.IntegrationTest; -import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.experimental.categories.Category; import java.util.Collections; import java.util.EnumSet; +import java.util.Optional; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -37,8 +37,8 @@ public class SpectraTouchFeatureTest extends AbstractSpectraTest { @Test public void testFile() { - assertFalse(new SpectraTouchFeature(session).isSupported(Home.root(), StringUtils.EMPTY)); - assertTrue(new SpectraTouchFeature(session).isSupported(new Path(Home.root(), "/container", EnumSet.of(Path.Type.directory, Path.Type.volume)), StringUtils.EMPTY)); + assertFalse(new SpectraTouchFeature(session).isSupported(Home.root(), Optional.empty())); + assertTrue(new SpectraTouchFeature(session).isSupported(new Path(Home.root(), "/container", EnumSet.of(Path.Type.directory, Path.Type.volume)), Optional.empty())); } @Test diff --git a/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateDirectoryFeature.java b/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateDirectoryFeature.java index 4d0d61ffa1..743cd31908 100644 --- a/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateDirectoryFeature.java +++ b/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateDirectoryFeature.java @@ -28,6 +28,7 @@ import ch.cyberduck.core.storegate.io.swagger.client.model.File; import ch.cyberduck.core.transfer.TransferStatus; import java.text.MessageFormat; +import java.util.Optional; public class StoregateDirectoryFeature implements Directory { @@ -56,7 +57,7 @@ public class StoregateDirectoryFeature implements Directory { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create folder {0}", "Error"), filename)).withFile(workdir); } diff --git a/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateTouchFeature.java b/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateTouchFeature.java index 56073a6e03..172b17aa23 100644 --- a/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateTouchFeature.java +++ b/storegate/src/main/java/ch/cyberduck/core/storegate/StoregateTouchFeature.java @@ -23,6 +23,7 @@ import ch.cyberduck.core.shared.DefaultTouchFeature; import ch.cyberduck.core.storegate.io.swagger.client.model.File; import java.text.MessageFormat; +import java.util.Optional; public class StoregateTouchFeature extends DefaultTouchFeature { @@ -31,7 +32,7 @@ public class StoregateTouchFeature extends DefaultTouchFeature { } @Override - public void preflight(final Path workdir, final String filename) throws BackgroundException { + public void preflight(final Path workdir, final Optional filename) throws BackgroundException { if(workdir.isRoot()) { throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir); } diff --git a/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs b/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs index 7ffaac6bf6..6fd3a148d4 100644 --- a/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs +++ b/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs @@ -1014,7 +1014,7 @@ namespace Ch.Cyberduck.Ui.Controller return; } Touch feature = (Touch)Pool.getFeature(typeof(Touch)); - if (!feature.isSupported(destination, String.Empty)) + if (!feature.isSupported(destination, Optional.empty())) { args.Effect = DragDropEffects.None; args.DropTargetLocation = DropTargetLocation.None; @@ -1885,14 +1885,14 @@ namespace Ch.Cyberduck.Ui.Controller { return IsMounted() && ((Touch)Pool.getFeature(typeof(Touch))).isSupported( - new UploadTargetFinder(Workdir).find(SelectedPath), String.Empty); + new UploadTargetFinder(Workdir).find(SelectedPath), Optional.empty()); } private bool View_ValidateUpload() { return IsMounted() && ((Touch)Pool.getFeature(typeof(Touch))).isSupported( - new UploadTargetFinder(Workdir).find(SelectedPath), String.Empty); + new UploadTargetFinder(Workdir).find(SelectedPath), Optional.empty()); } private void View_Upload() @@ -2061,7 +2061,7 @@ namespace Ch.Cyberduck.Ui.Controller { return IsMounted() && ((Directory)Pool.getFeature(typeof(Directory))).isSupported( - new UploadTargetFinder(Workdir).find(SelectedPath), String.Empty); + new UploadTargetFinder(Workdir).find(SelectedPath), Optional.empty()); } private bool View_ValidateNewVault() @@ -2069,7 +2069,7 @@ namespace Ch.Cyberduck.Ui.Controller return IsMounted() && Pool.getVaultRegistry() != VaultRegistry.DISABLED && !Pool.getVaultRegistry().contains(Workdir) && ((Directory)Pool.getFeature(typeof(Directory))).isSupported( - new UploadTargetFinder(Workdir).find(SelectedPath), String.Empty); + new UploadTargetFinder(Workdir).find(SelectedPath), Optional.empty()); } private void View_DuplicateFile() @@ -2263,7 +2263,7 @@ namespace Ch.Cyberduck.Ui.Controller return; } Touch feature = (Touch)Pool.getFeature(typeof(Touch)); - if (!feature.isSupported(destination, String.Empty)) + if (!feature.isSupported(destination, Optional.empty())) { Log.trace("Pool does not allow file creation"); args.Effect = DragDropEffects.None;