Skip to content

Commit

Permalink
No need to decode prefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylangisc committed Apr 12, 2023
1 parent f4db88a commit 24e6b8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import ch.cyberduck.core.PathContainerService;
import ch.cyberduck.core.PathNormalizer;
import ch.cyberduck.core.SimplePathPredicate;
import ch.cyberduck.core.URIEncoder;
import ch.cyberduck.core.VersioningConfiguration;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.NotfoundException;
Expand Down Expand Up @@ -77,17 +76,18 @@ public AttributedList<Path> list(final Path directory, final ListProgressListene
}

protected AttributedList<Path> list(final Path directory, final ListProgressListener listener, final String delimiter) throws BackgroundException {
return this.list(directory, listener, delimiter, new HostPreferences(session.getHost()).getInteger("googlestorage.listing.chunksize"));
final VersioningConfiguration versioning = new HostPreferences(session.getHost()).getBoolean("googlestorage.listing.versioning.enable") &&
null != session.getFeature(Versioning.class) ? session.getFeature(Versioning.class).getConfiguration(
containerService.getContainer(directory)
) : VersioningConfiguration.empty();
return this.list(directory, listener, delimiter, new HostPreferences(session.getHost()).getInteger("googlestorage.listing.chunksize"), versioning);
}

protected AttributedList<Path> list(final Path directory, final ListProgressListener listener, final String delimiter, final int chunksize) throws BackgroundException {
protected AttributedList<Path> list(final Path directory, final ListProgressListener listener, final String delimiter, final int chunksize,
final VersioningConfiguration versioning) throws BackgroundException {
final ThreadPool pool = ThreadPoolFactory.get("list", concurrency);
try {
final Path bucket = containerService.getContainer(directory);
final VersioningConfiguration versioning = new HostPreferences(session.getHost()).getBoolean("googlestorage.listing.versioning.enable")
&& null != session.getFeature(Versioning.class) ? session.getFeature(Versioning.class).getConfiguration(
containerService.getContainer(directory)
) : VersioningConfiguration.empty();
final AttributedList<Path> objects = new AttributedList<>();
Objects response;
long revision = 0L;
Expand Down Expand Up @@ -143,7 +143,7 @@ protected AttributedList<Path> list(final Path directory, final ListProgressList
if(response.getPrefixes() != null) {
final List<Future<Path>> folders = new ArrayList<>();
for(String prefix : response.getPrefixes()) {
final String key = StringUtils.chomp(URIEncoder.decode(prefix), String.valueOf(Path.DELIMITER));
final String key = StringUtils.chomp(prefix, String.valueOf(Path.DELIMITER));
if(new SimplePathPredicate(PathNormalizer.compose(bucket, key)).test(directory)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import ch.cyberduck.core.DisabledLoginCallback;
import ch.cyberduck.core.IndexedListProgressListener;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.VersioningConfiguration;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.preferences.HostPreferences;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;

Expand Down Expand Up @@ -90,7 +92,7 @@ public void visit(final AttributedList<Path> list, final int index, final Path f
}

@Test
public void testListEncodedCharacter() throws Exception {
public void testListEncodedCharacterFile() throws Exception {
final Path container = new Path("cyberduck-test-eu", EnumSet.of(Path.Type.directory, Path.Type.volume));
container.attributes().setRegion("us-east-1");
final Path placeholder = new GoogleStorageTouchFeature(session).touch(
Expand All @@ -99,6 +101,27 @@ public void testListEncodedCharacter() throws Exception {
new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(placeholder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

@Test
public void testListEncodedCharacterFolderVersioned() throws Exception {
final Path container = new Path("cyberduck-test-eu", EnumSet.of(Path.Type.directory, Path.Type.volume));
container.attributes().setRegion("us-east-1");
final Path placeholder = new GoogleStorageDirectoryFeature(session).mkdir(
new Path(container, String.format("%s +", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory)), new TransferStatus());
assertTrue(new GoogleStorageObjectListService(session).list(container, new DisabledListProgressListener()).contains(placeholder));
new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(placeholder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

@Test
public void testListEncodedCharacterFolderNonVersioned() throws Exception {
final Path container = new Path("cyberduck-test-eu", EnumSet.of(Path.Type.directory, Path.Type.volume));
container.attributes().setRegion("us-east-1");
final Path placeholder = new GoogleStorageDirectoryFeature(session).mkdir(
new Path(container, String.format("%s +", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory)), new TransferStatus());
assertTrue(new GoogleStorageObjectListService(session).list(container, new DisabledListProgressListener(), String.valueOf(Path.DELIMITER),
new HostPreferences(session.getHost()).getInteger("googlestorage.listing.chunksize"), VersioningConfiguration.empty()).contains(placeholder));
new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(placeholder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

@Test
public void testListInvisibleCharacter() throws Exception {
final Path container = new Path("cyberduck-test-eu", EnumSet.of(Path.Type.directory, Path.Type.volume));
Expand Down

0 comments on commit 24e6b8d

Please sign in to comment.