You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2017/05/10 08:02:41 UTC
jclouds git commit: fix for deleting an invalid file
Repository: jclouds
Updated Branches:
refs/heads/master 15d27da73 -> 6452960c7
fix for deleting an invalid file
If the file for delete is invalid (typically a wrong filename) an IOException will be thrown.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/6452960c
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/6452960c
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/6452960c
Branch: refs/heads/master
Commit: 6452960c72a5f8247acae12481b94cdf9d8e4218
Parents: 15d27da
Author: Tomas Tulka <to...@gmail.com>
Authored: Mon May 8 09:32:56 2017 +0200
Committer: Andrew Gaul <ga...@apache.org>
Committed: Wed May 10 01:02:09 2017 -0700
----------------------------------------------------------------------
.../main/java/org/jclouds/filesystem/util/Utils.java | 14 +++++++++++---
.../internal/FilesystemStorageStrategyImplTest.java | 11 +++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/6452960c/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
index 8119e98..e9439f9 100644
--- a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
+++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
@@ -27,6 +27,7 @@ import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
+import java.nio.file.InvalidPathException;
import java.nio.file.attribute.AclEntry;
import java.nio.file.attribute.AclEntryPermission;
import java.nio.file.attribute.AclEntryType;
@@ -77,10 +78,17 @@ public class Utils {
}
public static void delete(File file) throws IOException {
+ Path path;
+ try {
+ path = file.toPath();
+ } catch (InvalidPathException ipe) {
+ throw new IOException("Invalid file: " + file, ipe);
+ }
+
for (int n = 0; n < 10; n++) {
try {
- Files.delete(file.toPath());
- if (Files.exists(file.toPath())) {
+ Files.delete(path);
+ if (Files.exists(path)) {
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
continue;
}
@@ -98,7 +106,7 @@ public class Utils {
}
}
// File could not be deleted multiple times. It is very likely locked in another process
- throw new IOException("Could not delete: " + file.toPath());
+ throw new IOException("Could not delete: " + path);
}
/**
http://git-wip-us.apache.org/repos/asf/jclouds/blob/6452960c/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
index 6eb4238..3c0c948 100644
--- a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
+++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
@@ -29,6 +29,7 @@ import static org.testng.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.file.InvalidPathException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -685,6 +686,16 @@ public class FilesystemStorageStrategyImplTest {
}
}
+ @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);
+ }
+ }
+
// ---------------------------------------------------------- Private methods
/**