diff --git a/nextcloud/src/main/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeature.java b/nextcloud/src/main/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeature.java index 554c9d7f804..954d3ea8354 100644 --- a/nextcloud/src/main/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeature.java +++ b/nextcloud/src/main/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeature.java @@ -17,8 +17,12 @@ import ch.cyberduck.core.Host; import ch.cyberduck.core.Path; +import ch.cyberduck.core.exception.BackgroundException; +import ch.cyberduck.core.features.Home; import ch.cyberduck.core.preferences.HostPreferences; import ch.cyberduck.core.shared.AbstractHomeFeature; +import ch.cyberduck.core.shared.DefaultPathHomeFeature; +import ch.cyberduck.core.shared.DelegatingHomeFeature; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -29,36 +33,51 @@ public class NextcloudHomeFeature extends AbstractHomeFeature { private static final Logger log = LogManager.getLogger(NextcloudHomeFeature.class); + private final Home delegate; private final Host bookmark; private final String root; public NextcloudHomeFeature(final Host bookmark) { - this(bookmark, new HostPreferences(bookmark).getProperty("nextcloud.root.default")); + this(new DefaultPathHomeFeature(bookmark), bookmark); + } + + public NextcloudHomeFeature(final Home delegate, final Host bookmark) { + this(delegate, bookmark, new HostPreferences(bookmark).getProperty("nextcloud.root.default")); } /** * @param root WebDAV root */ - public NextcloudHomeFeature(final Host bookmark, final String root) { + public NextcloudHomeFeature(final Home delegate, final Host bookmark, final String root) { + this.delegate = delegate; this.bookmark = bookmark; this.root = root; } @Override - public Path find() { + public Path find() throws BackgroundException { return this.find(Context.files); } - public Path find(final Context files) { - String username = bookmark.getCredentials().getUsername(); + public Path find(final Context files) throws BackgroundException { + final String username = bookmark.getCredentials().getUsername(); if(StringUtils.isBlank(username)) { if(log.isWarnEnabled()) { log.warn(String.format("Missing username for %s", bookmark)); } - return null; + return delegate.find(); + } + // Custom path setting + final Path workdir; + final Path defaultpath = new DelegatingHomeFeature(delegate).find(); + if(!defaultpath.isRoot() && StringUtils.isNotBlank(StringUtils.removeStart(defaultpath.getAbsolute(), root))) { + workdir = new Path(new Path(String.format("%s/%s/%s", root, files.name(), username), EnumSet.of(Path.Type.directory)), + StringUtils.removeStart(defaultpath.getAbsolute(), root), EnumSet.of(Path.Type.directory)); + } + else { + workdir = new Path(new Path(String.format("%s/%s", root, files.name()), EnumSet.of(Path.Type.directory)), + username, EnumSet.of(Path.Type.directory)); } - final Path workdir = new Path(new Path(String.format("%s/%s", root, files.name()), EnumSet.of(Path.Type.directory)), - username, EnumSet.of(Path.Type.directory)); if(log.isDebugEnabled()) { log.debug(String.format("Use home directory %s", workdir)); } @@ -67,6 +86,7 @@ public Path find(final Context files) { public enum Context { files, - versions + versions, + meta } } diff --git a/nextcloud/src/test/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeatureTest.java b/nextcloud/src/test/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeatureTest.java index 1585ee2a816..36248f59d13 100644 --- a/nextcloud/src/test/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeatureTest.java +++ b/nextcloud/src/test/java/ch/cyberduck/core/nextcloud/NextcloudHomeFeatureTest.java @@ -35,5 +35,17 @@ public void testFind() throws Exception { assertNull(feature.find()); bookmark.setCredentials(new Credentials("u")); assertEquals(new Path("/remote.php/dav/files/u", EnumSet.of(Path.Type.directory)), feature.find()); + bookmark.setDefaultPath("/remote.php/dav/"); + assertEquals(new Path("/remote.php/dav/files/u", EnumSet.of(Path.Type.directory)), feature.find()); + bookmark.setDefaultPath("/remote.php/dav"); + assertEquals(new Path("/remote.php/dav/files/u", EnumSet.of(Path.Type.directory)), feature.find()); + bookmark.setDefaultPath("/remote.php/dav/d"); + assertEquals(new Path("/remote.php/dav/files/u/d", EnumSet.of(Path.Type.directory)), feature.find()); + bookmark.setDefaultPath("/remote.php/dav/d/"); + assertEquals(new Path("/remote.php/dav/files/u/d", EnumSet.of(Path.Type.directory)), feature.find()); + bookmark.setDefaultPath("/d"); + assertEquals(new Path("/remote.php/dav/files/u/d", EnumSet.of(Path.Type.directory)), feature.find()); + bookmark.setDefaultPath("/d/"); + assertEquals(new Path("/remote.php/dav/files/u/d", EnumSet.of(Path.Type.directory)), feature.find()); } } \ No newline at end of file