@Test public void testDeleteVersionedPlaceholder() throws Exception { final Path container = new Path("versioning-test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final String name = new AlphanumericRandomStringService().random(); { final Path test = new S3DirectoryFeature(session, new S3WriteFeature(session, new S3DisabledMultipartService())).mkdir( new Path(container, name, EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertTrue(new S3FindFeature(session).find(test)); assertTrue(new DefaultFindFeature(session).find(test)); new S3MultipleDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(new S3FindFeature(session).find(test)); } { final Path test = new S3DirectoryFeature(session, new S3WriteFeature(session, new S3DisabledMultipartService())).mkdir( new Path(container, name, EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertTrue(new S3FindFeature(session).find(test)); assertTrue(new DefaultFindFeature(session).find(test)); new S3MultipleDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(new S3FindFeature(session).find(test)); } assertFalse(new S3VersionedObjectListService(session).list(container, new DisabledListProgressListener()).contains( new Path(container, name, EnumSet.of(Path.Type.directory)))); }
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { final Map<Path, List<ObjectKeyAndVersion>> map = new HashMap<Path, List<ObjectKeyAndVersion>>(); final List<Path> containers = new ArrayList<Path>(); for(Path file : files.keySet()) { if(containerService.isContainer(file)) { containers.add(file); continue; } callback.delete(file); if(file.getType().contains(Path.Type.upload)) { try { multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(NotfoundException ignored) { log.warn(String.format("Ignore failure deleting multipart upload %s", file)); } } else { final Path container = containerService.getContainer(file); final List<ObjectKeyAndVersion> keys = new ArrayList<ObjectKeyAndVersion>(); keys.add(new ObjectKeyAndVersion(containerService.getKey(file), file.attributes().getVersionId())); if(map.containsKey(container)) { map.get(container).addAll(keys); } else { map.put(container, keys); } } } for(Map.Entry<Path, List<ObjectKeyAndVersion>> entry : map.entrySet()) { final Path container = entry.getKey(); final List<ObjectKeyAndVersion> keys = entry.getValue(); this.delete(container, keys, prompt); } for(Path file : containers) { callback.delete(file); try { final String bucket = containerService.getContainer(file).getName(); session.getClient().deleteBucket(bucket); session.getClient().getRegionEndpointCache().removeRegionForBucketName(bucket); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file); } } }
S3MultipleDeleteFeature implements Delete { public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { final Map<Path, List<ObjectKeyAndVersion>> map = new HashMap<Path, List<ObjectKeyAndVersion>>(); final List<Path> containers = new ArrayList<Path>(); for(Path file : files.keySet()) { if(containerService.isContainer(file)) { containers.add(file); continue; } callback.delete(file); if(file.getType().contains(Path.Type.upload)) { try { multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(NotfoundException ignored) { log.warn(String.format("Ignore failure deleting multipart upload %s", file)); } } else { final Path container = containerService.getContainer(file); final List<ObjectKeyAndVersion> keys = new ArrayList<ObjectKeyAndVersion>(); keys.add(new ObjectKeyAndVersion(containerService.getKey(file), file.attributes().getVersionId())); if(map.containsKey(container)) { map.get(container).addAll(keys); } else { map.put(container, keys); } } } for(Map.Entry<Path, List<ObjectKeyAndVersion>> entry : map.entrySet()) { final Path container = entry.getKey(); final List<ObjectKeyAndVersion> keys = entry.getValue(); this.delete(container, keys, prompt); } for(Path file : containers) { callback.delete(file); try { final String bucket = containerService.getContainer(file).getName(); session.getClient().deleteBucket(bucket); session.getClient().getRegionEndpointCache().removeRegionForBucketName(bucket); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file); } } } }
S3MultipleDeleteFeature implements Delete { public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { final Map<Path, List<ObjectKeyAndVersion>> map = new HashMap<Path, List<ObjectKeyAndVersion>>(); final List<Path> containers = new ArrayList<Path>(); for(Path file : files.keySet()) { if(containerService.isContainer(file)) { containers.add(file); continue; } callback.delete(file); if(file.getType().contains(Path.Type.upload)) { try { multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(NotfoundException ignored) { log.warn(String.format("Ignore failure deleting multipart upload %s", file)); } } else { final Path container = containerService.getContainer(file); final List<ObjectKeyAndVersion> keys = new ArrayList<ObjectKeyAndVersion>(); keys.add(new ObjectKeyAndVersion(containerService.getKey(file), file.attributes().getVersionId())); if(map.containsKey(container)) { map.get(container).addAll(keys); } else { map.put(container, keys); } } } for(Map.Entry<Path, List<ObjectKeyAndVersion>> entry : map.entrySet()) { final Path container = entry.getKey(); final List<ObjectKeyAndVersion> keys = entry.getValue(); this.delete(container, keys, prompt); } for(Path file : containers) { callback.delete(file); try { final String bucket = containerService.getContainer(file).getName(); session.getClient().deleteBucket(bucket); session.getClient().getRegionEndpointCache().removeRegionForBucketName(bucket); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file); } } } S3MultipleDeleteFeature(final S3Session session);  S3MultipleDeleteFeature(final S3Session session, final S3MultipartService multipartService); }
S3MultipleDeleteFeature implements Delete { public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { final Map<Path, List<ObjectKeyAndVersion>> map = new HashMap<Path, List<ObjectKeyAndVersion>>(); final List<Path> containers = new ArrayList<Path>(); for(Path file : files.keySet()) { if(containerService.isContainer(file)) { containers.add(file); continue; } callback.delete(file); if(file.getType().contains(Path.Type.upload)) { try { multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(NotfoundException ignored) { log.warn(String.format("Ignore failure deleting multipart upload %s", file)); } } else { final Path container = containerService.getContainer(file); final List<ObjectKeyAndVersion> keys = new ArrayList<ObjectKeyAndVersion>(); keys.add(new ObjectKeyAndVersion(containerService.getKey(file), file.attributes().getVersionId())); if(map.containsKey(container)) { map.get(container).addAll(keys); } else { map.put(container, keys); } } } for(Map.Entry<Path, List<ObjectKeyAndVersion>> entry : map.entrySet()) { final Path container = entry.getKey(); final List<ObjectKeyAndVersion> keys = entry.getValue(); this.delete(container, keys, prompt); } for(Path file : containers) { callback.delete(file); try { final String bucket = containerService.getContainer(file).getName(); session.getClient().deleteBucket(bucket); session.getClient().getRegionEndpointCache().removeRegionForBucketName(bucket); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file); } } } S3MultipleDeleteFeature(final S3Session session);  S3MultipleDeleteFeature(final S3Session session, final S3MultipartService multipartService); void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback); void delete(final Path container, final List<ObjectKeyAndVersion> keys, final PasswordCallback prompt); }
S3MultipleDeleteFeature implements Delete { public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { final Map<Path, List<ObjectKeyAndVersion>> map = new HashMap<Path, List<ObjectKeyAndVersion>>(); final List<Path> containers = new ArrayList<Path>(); for(Path file : files.keySet()) { if(containerService.isContainer(file)) { containers.add(file); continue; } callback.delete(file); if(file.getType().contains(Path.Type.upload)) { try { multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(NotfoundException ignored) { log.warn(String.format("Ignore failure deleting multipart upload %s", file)); } } else { final Path container = containerService.getContainer(file); final List<ObjectKeyAndVersion> keys = new ArrayList<ObjectKeyAndVersion>(); keys.add(new ObjectKeyAndVersion(containerService.getKey(file), file.attributes().getVersionId())); if(map.containsKey(container)) { map.get(container).addAll(keys); } else { map.put(container, keys); } } } for(Map.Entry<Path, List<ObjectKeyAndVersion>> entry : map.entrySet()) { final Path container = entry.getKey(); final List<ObjectKeyAndVersion> keys = entry.getValue(); this.delete(container, keys, prompt); } for(Path file : containers) { callback.delete(file); try { final String bucket = containerService.getContainer(file).getName(); session.getClient().deleteBucket(bucket); session.getClient().getRegionEndpointCache().removeRegionForBucketName(bucket); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file); } } } S3MultipleDeleteFeature(final S3Session session);  S3MultipleDeleteFeature(final S3Session session, final S3MultipartService multipartService); void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback); void delete(final Path container, final List<ObjectKeyAndVersion> keys, final PasswordCallback prompt);  }