Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
Former-commit-id: f7e426ed89e80d8f3122c49ae4b2a38b94a7e687
  • Loading branch information
dkocher committed Jul 9, 2013
1 parent e9cb48a commit 18bde3e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
34 changes: 24 additions & 10 deletions source/ch/cyberduck/core/s3/S3ObjectListService.java
Expand Up @@ -52,6 +52,8 @@ public class S3ObjectListService implements ListService {

private S3Session session;

private PathContainerService containerService = new PathContainerService();

public S3ObjectListService(final S3Session session) {
this.session = session;
}
Expand All @@ -64,12 +66,12 @@ public AttributedList<Path> list(final Path file) throws BackgroundException {
// a special character that delimits hierarchy, you can use the list
// operation to select and browse keys hierarchically
String prefix = StringUtils.EMPTY;
if(!new PathContainerService().isContainer(file)) {
// estricts the response to only contain results that begin with the
if(!containerService.isContainer(file)) {
// Restricts the response to only contain results that begin with the
// specified prefix. If you omit this optional argument, the value
// of Prefix for your query will be the empty string.
// In other words, the results will be not be restricted by prefix.
prefix = new PathContainerService().getKey(file);
prefix = containerService.getKey(file);
if(!prefix.endsWith(String.valueOf(Path.DELIMITER))) {
prefix += Path.DELIMITER;
}
Expand All @@ -81,17 +83,17 @@ public AttributedList<Path> list(final Path file) throws BackgroundException {
// not returned elsewhere in the response.
final AttributedList<Path> children = new AttributedList<Path>();
children.addAll(this.listObjects(
new PathContainerService().getContainer(file), file, prefix, String.valueOf(Path.DELIMITER)));
containerService.getContainer(file), file, prefix, String.valueOf(Path.DELIMITER)));
if(Preferences.instance().getBoolean("s3.revisions.enable")) {
if(new S3VersioningFeature(session).getConfiguration(new PathContainerService().getContainer(file)).isEnabled()) {
if(new S3VersioningFeature(session).getConfiguration(containerService.getContainer(file)).isEnabled()) {
String priorLastKey = null;
String priorLastVersionId = null;
do {
final VersionOrDeleteMarkersChunk chunk = session.getClient().listVersionedObjectsChunked(
new PathContainerService().getContainer(file).getName(), prefix, String.valueOf(Path.DELIMITER),
containerService.getContainer(file).getName(), prefix, String.valueOf(Path.DELIMITER),
Preferences.instance().getInteger("s3.listing.chunksize"),
priorLastKey, priorLastVersionId, true);
children.addAll(this.listVersions(new PathContainerService().getContainer(file), file,
children.addAll(this.listVersions(containerService.getContainer(file), file,
Arrays.asList(chunk.getItems())));
priorLastKey = chunk.getNextKeyMarker();
priorLastVersionId = chunk.getNextVersionIdMarker();
Expand Down Expand Up @@ -123,7 +125,11 @@ private AttributedList<Path> listObjects(final Path bucket, final Path parent, f

final StorageObject[] objects = chunk.getObjects();
for(StorageObject object : objects) {
final Path p = new Path(parent, Path.getName(PathNormalizer.normalize(object.getKey())), Path.FILE_TYPE);
final String key = PathNormalizer.normalize(object.getKey());
if(new Path(bucket, key, Path.DIRECTORY_TYPE).equals(parent)) {
continue;
}
final Path p = new Path(parent, Path.getName(key), Path.FILE_TYPE);
p.attributes().setSize(object.getContentLength());
p.attributes().setModificationDate(object.getLastModifiedDate().getTime());
p.attributes().setRegion(bucket.attributes().getRegion());
Expand Down Expand Up @@ -161,7 +167,11 @@ else if(0 == object.getContentLength()) {
log.warn("Skipping prefix " + common);
continue;
}
final Path p = new Path(parent, Path.getName(PathNormalizer.normalize(common)), Path.DIRECTORY_TYPE);
final String key = PathNormalizer.normalize(common);
if(new Path(bucket, key, Path.DIRECTORY_TYPE).equals(parent)) {
continue;
}
final Path p = new Path(parent, Path.getName(key), Path.DIRECTORY_TYPE);
if(children.contains(p.getReference())) {
// There is already a placeholder object
continue;
Expand Down Expand Up @@ -192,7 +202,11 @@ public int compare(BaseVersionOrDeleteMarker o1, BaseVersionOrDeleteMarker o2) {
if((marker.isDeleteMarker() && marker.isLatest())
|| !marker.isLatest()) {
// Latest version already in default listing
final Path p = new Path(parent, Path.getName(PathNormalizer.normalize(marker.getKey())), Path.FILE_TYPE);
final String key = PathNormalizer.normalize(marker.getKey());
if(new Path(bucket, key, Path.DIRECTORY_TYPE).equals(parent)) {
continue;
}
final Path p = new Path(parent, Path.getName(key), Path.FILE_TYPE);
// Versioning is enabled if non null.
p.attributes().setVersionId(marker.getVersionId());
p.attributes().setRevision(++i);
Expand Down
14 changes: 14 additions & 0 deletions test/ch/cyberduck/core/s3/S3ObjectListServiceTest.java
Expand Up @@ -62,6 +62,20 @@ public void testList() throws Exception {
}
}

@Test
public void tetsEmptyPlaceholder() throws Exception {
final S3Session session = new S3Session(
new Host(Protocol.S3_SSL, Protocol.S3_SSL.getDefaultHostname(),
new Credentials(
properties.getProperty("s3.key"), properties.getProperty("s3.secret")
)));
session.open(new DefaultHostKeyController());
session.login(new DisabledPasswordStore(), new DisabledLoginController());
final Path container = new Path("test.cyberduck.ch", Path.VOLUME_TYPE);
final List<Path> list = new S3ObjectListService(session).list(new Path(container, "test", Path.DIRECTORY_TYPE));
assertTrue(list.isEmpty());
}

@Test(expected = NotfoundException.class)
public void testListNotfound() throws Exception {
final S3Session session = new S3Session(
Expand Down

0 comments on commit 18bde3e

Please sign in to comment.