test/lib/testlibrary/jdk/testlibrary/FileUtils.java

Print this page

        

@@ -62,12 +62,11 @@
         throws IOException
     {
         try {
             deleteFileWithRetry0(path);
         } catch (InterruptedException x) {
-            // Restore the interrupted status
-            Thread.currentThread().interrupt();
+            throw new IOException("Interrupted while deleting.", x);
         }
     }
 
     private static void deleteFileWithRetry0(Path path)
         throws IOException, InterruptedException

@@ -75,11 +74,19 @@
         int times = 0;
         IOException ioe = null;
         while (true) {
             try {
                 Files.delete(path);
+                while (true) {
+                    if (Files.notExists(path))
                 break;
+                    times++;
+                    if (times > MAX_RETRY_DELETE_TIMES)
+                        throw new IOException("File still exists after " + times + " waits.");
+                    Thread.sleep(RETRY_DELETE_MILLIS);
+                }
+                break;
             } catch (NoSuchFileException | DirectoryNotEmptyException x) {
                 throw x;
             } catch (IOException x) {
                 // Backoff/retry in case another process is accessing the file
                 times++;

@@ -129,12 +136,11 @@
                     try {
                         deleteFileWithRetry0(file);
                     } catch (IOException x) {
                         excs.add(x);
                     } catch (InterruptedException x) {
-                        // Restore the interrupted status and terminate
-                        Thread.currentThread().interrupt();
+                        excs.add(new IOException("Interrupted while deleting.", x));
                         return FileVisitResult.TERMINATE;
                     }
                     return FileVisitResult.CONTINUE;
                 }
                 @Override

@@ -142,12 +148,11 @@
                     try {
                         deleteFileWithRetry0(dir);
                     } catch (IOException x) {
                         excs.add(x);
                     } catch (InterruptedException x) {
-                        // Restore the interrupted status and terminate
-                        Thread.currentThread().interrupt();
+                        excs.add(new IOException("Interrupted while deleting.", x));
                         return FileVisitResult.TERMINATE;
                     }
                     return FileVisitResult.CONTINUE;
                 }
                 @Override