Explorar o código

svn merge -c 1367196 FIXES: HADOOP-8634. Ensure FileSystem#close doesn't squawk for deleteOnExit paths (daryn via bobby)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1367200 13f79535-47bb-0310-9956-ffa450edef68
Robert Joseph Evans %!s(int64=13) %!d(string=hai) anos
pai
achega
5378f10e33

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -132,6 +132,9 @@ Release 0.23.3 - UNRELEASED
 
     HADOOP-8627. FS deleteOnExit may delete the wrong path (daryn via bobby)
 
+    HADOOP-8634. Ensure FileSystem#close doesn't squawk for deleteOnExit paths 
+    (daryn via bobby)
+
 Release 0.23.2 - UNRELEASED 
 
   NEW FEATURES

+ 3 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java

@@ -1165,7 +1165,9 @@ public abstract class FileSystem extends Configured implements Closeable {
       for (Iterator<Path> iter = deleteOnExit.iterator(); iter.hasNext();) {
         Path path = iter.next();
         try {
-          delete(path, true);
+          if (exists(path)) {
+            delete(path, true);
+          }
         }
         catch (IOException e) {
           LOG.info("Ignoring failure to deleteOnExit for path " + path);

+ 26 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemCaching.java

@@ -35,7 +35,7 @@ import java.security.PrivilegedExceptionAction;
 import java.util.concurrent.Semaphore;
 
 import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.*;
 
 
 public class TestFileSystemCaching {
@@ -267,4 +267,28 @@ public class TestFileSystemCaching {
     });
     assertNotSame(fsA, fsA1);
   }
-}
+  
+  @Test
+  public void testDeleteOnExitChecksExists() throws Exception {
+    FileSystem mockFs = mock(FileSystem.class);
+    FileSystem fs = new FilterFileSystem(mockFs);
+    Path p = new Path("/a");
+    
+    // path has to exist for deleteOnExit to register it
+    when(mockFs.getFileStatus(p)).thenReturn(new FileStatus());
+    fs.deleteOnExit(p);
+    verify(mockFs).getFileStatus(eq(p));
+    fs.close();
+    verify(mockFs).delete(eq(p), anyBoolean());
+    reset(mockFs);
+    
+    // make sure it doesn't try to delete a file that doesn't exist
+    when(mockFs.getFileStatus(p)).thenReturn(new FileStatus());
+    fs.deleteOnExit(p);
+    verify(mockFs).getFileStatus(eq(p));
+    reset(mockFs);
+    fs.close();
+    verify(mockFs).getFileStatus(eq(p));
+    verify(mockFs, never()).delete(any(Path.class), anyBoolean());
+  }
+}