@Test public void testDeletingInvalidPathFileEndsNormally() { String invalidPathBlobKey = "A<!:!@#$%^&*?]8 /\0"; try { storageStrategy.removeBlob(CONTAINER_NAME, invalidPathBlobKey); } catch (InvalidPathException ipe) { fail("Deleting an invalid path ended with an InvalidPathException.", ipe); } }
@Override public void removeBlob(final String container, final String blobKey) { filesystemContainerNameValidator.validate(container); filesystemBlobKeyValidator.validate(blobKey); String fileName = buildPathStartingFromBaseDir(container, blobKey); logger.debug("Deleting blob %s", fileName); File fileToBeDeleted = new File(fileName); if (fileToBeDeleted.isDirectory()) { try { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(fileToBeDeleted.toPath()); if (view != null) { for (String s : view.list()) { view.delete(s); } } } catch (IOException e) { logger.debug("Could not delete attributes from %s: %s", fileToBeDeleted, e); } } try { delete(fileToBeDeleted); } catch (IOException e) { logger.debug("Could not delete %s: %s", fileToBeDeleted, e); } removeDirectoriesTreeOfBlobKey(container, blobKey); }
FilesystemStorageStrategyImpl implements LocalStorageStrategy { @Override public void removeBlob(final String container, final String blobKey) { filesystemContainerNameValidator.validate(container); filesystemBlobKeyValidator.validate(blobKey); String fileName = buildPathStartingFromBaseDir(container, blobKey); logger.debug("Deleting blob %s", fileName); File fileToBeDeleted = new File(fileName); if (fileToBeDeleted.isDirectory()) { try { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(fileToBeDeleted.toPath()); if (view != null) { for (String s : view.list()) { view.delete(s); } } } catch (IOException e) { logger.debug("Could not delete attributes from %s: %s", fileToBeDeleted, e); } } try { delete(fileToBeDeleted); } catch (IOException e) { logger.debug("Could not delete %s: %s", fileToBeDeleted, e); } removeDirectoriesTreeOfBlobKey(container, blobKey); } }
FilesystemStorageStrategyImpl implements LocalStorageStrategy { @Override public void removeBlob(final String container, final String blobKey) { filesystemContainerNameValidator.validate(container); filesystemBlobKeyValidator.validate(blobKey); String fileName = buildPathStartingFromBaseDir(container, blobKey); logger.debug("Deleting blob %s", fileName); File fileToBeDeleted = new File(fileName); if (fileToBeDeleted.isDirectory()) { try { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(fileToBeDeleted.toPath()); if (view != null) { for (String s : view.list()) { view.delete(s); } } } catch (IOException e) { logger.debug("Could not delete attributes from %s: %s", fileToBeDeleted, e); } } try { delete(fileToBeDeleted); } catch (IOException e) { logger.debug("Could not delete %s: %s", fileToBeDeleted, e); } removeDirectoriesTreeOfBlobKey(container, blobKey); } @Inject protected  FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
         @Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
         @Named(FilesystemConstants.PROPERTY_AUTO_DETECT_CONTENT_TYPE) boolean autoDetectContentType,
         FilesystemContainerNameValidator filesystemContainerNameValidator,
         FilesystemBlobKeyValidator filesystemBlobKeyValidator,
         Supplier<Location> defaultLocation); }
FilesystemStorageStrategyImpl implements LocalStorageStrategy { @Override public void removeBlob(final String container, final String blobKey) { filesystemContainerNameValidator.validate(container); filesystemBlobKeyValidator.validate(blobKey); String fileName = buildPathStartingFromBaseDir(container, blobKey); logger.debug("Deleting blob %s", fileName); File fileToBeDeleted = new File(fileName); if (fileToBeDeleted.isDirectory()) { try { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(fileToBeDeleted.toPath()); if (view != null) { for (String s : view.list()) { view.delete(s); } } } catch (IOException e) { logger.debug("Could not delete attributes from %s: %s", fileToBeDeleted, e); } } try { delete(fileToBeDeleted); } catch (IOException e) { logger.debug("Could not delete %s: %s", fileToBeDeleted, e); } removeDirectoriesTreeOfBlobKey(container, blobKey); } @Inject protected  FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
         @Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
         @Named(FilesystemConstants.PROPERTY_AUTO_DETECT_CONTENT_TYPE) boolean autoDetectContentType,
         FilesystemContainerNameValidator filesystemContainerNameValidator,
         FilesystemBlobKeyValidator filesystemBlobKeyValidator,
         Supplier<Location> defaultLocation); @Override boolean containerExists(String container); @Override Collection<String> getAllContainerNames(); @Override boolean createContainerInLocation(String container, Location location, CreateContainerOptions options); @Override ContainerAccess getContainerAccess(String container); @Override void setContainerAccess(String container, ContainerAccess access); @Override void deleteContainer(String container); @Override void clearContainer(final String container); @Override void clearContainer(String container, ListContainerOptions options); @Override StorageMetadata getContainerMetadata(String container); @Override boolean blobExists(String container, String key); @Override Iterable<String> getBlobKeysInsideContainer(String container, String prefix); @Override Blob getBlob(final String container, final String key); @Override String putBlob(final String containerName, final Blob blob); @Override void removeBlob(final String container, final String blobKey); @Override BlobAccess getBlobAccess(String containerName, String blobName); @Override void setBlobAccess(String container, String name, BlobAccess access); @Override Location getLocation(final String containerName); @Override String getSeparator(); boolean createContainer(String container); Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name); File getFileForBlobKey(String container, String blobKey); boolean directoryExists(String container, String directory); void createDirectory(String container, String directory); void deleteDirectory(String container, String directory); long countBlobs(String container, ListContainerOptions options); }
FilesystemStorageStrategyImpl implements LocalStorageStrategy { @Override public void removeBlob(final String container, final String blobKey) { filesystemContainerNameValidator.validate(container); filesystemBlobKeyValidator.validate(blobKey); String fileName = buildPathStartingFromBaseDir(container, blobKey); logger.debug("Deleting blob %s", fileName); File fileToBeDeleted = new File(fileName); if (fileToBeDeleted.isDirectory()) { try { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(fileToBeDeleted.toPath()); if (view != null) { for (String s : view.list()) { view.delete(s); } } } catch (IOException e) { logger.debug("Could not delete attributes from %s: %s", fileToBeDeleted, e); } } try { delete(fileToBeDeleted); } catch (IOException e) { logger.debug("Could not delete %s: %s", fileToBeDeleted, e); } removeDirectoriesTreeOfBlobKey(container, blobKey); } @Inject protected  FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
         @Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
         @Named(FilesystemConstants.PROPERTY_AUTO_DETECT_CONTENT_TYPE) boolean autoDetectContentType,
         FilesystemContainerNameValidator filesystemContainerNameValidator,
         FilesystemBlobKeyValidator filesystemBlobKeyValidator,
         Supplier<Location> defaultLocation); @Override boolean containerExists(String container); @Override Collection<String> getAllContainerNames(); @Override boolean createContainerInLocation(String container, Location location, CreateContainerOptions options); @Override ContainerAccess getContainerAccess(String container); @Override void setContainerAccess(String container, ContainerAccess access); @Override void deleteContainer(String container); @Override void clearContainer(final String container); @Override void clearContainer(String container, ListContainerOptions options); @Override StorageMetadata getContainerMetadata(String container); @Override boolean blobExists(String container, String key); @Override Iterable<String> getBlobKeysInsideContainer(String container, String prefix); @Override Blob getBlob(final String container, final String key); @Override String putBlob(final String containerName, final Blob blob); @Override void removeBlob(final String container, final String blobKey); @Override BlobAccess getBlobAccess(String containerName, String blobName); @Override void setBlobAccess(String container, String name, BlobAccess access); @Override Location getLocation(final String containerName); @Override String getSeparator(); boolean createContainer(String container); Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name); File getFileForBlobKey(String container, String blobKey); boolean directoryExists(String container, String directory); void createDirectory(String container, String directory); void deleteDirectory(String container, String directory); long countBlobs(String container, ListContainerOptions options);  }