From 0c166f43a8e1a60416bc20f707593c2ad69b1f4a Mon Sep 17 00:00:00 2001 From: Jens Baumgart Date: Mon, 6 Sep 2010 18:09:48 +0200 Subject: Fix deletion problem in EGit Core tests EGit core tests sometimes fail because TestUtils.deleteRecursive can not delete a file. To workaround the problem the deletion is retried 10 times. Change-Id: Ia25c9304884c95f54e8e7b98ed49dd044fa7b95b Signed-off-by: Jens Baumgart --- .../src/org/eclipse/egit/core/test/TestUtils.java | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java index 8ff9eb80d7..98bfd9b1a4 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java @@ -47,15 +47,32 @@ public class TestUtils { for (int i = 0; i < files.length; ++i) { if (files[i].isDirectory()) deleteRecursive(files[i]); - else if (!files[i].delete()) - throw new IOException(files[i] + " in use or undeletable"); + else + deleteFile(files[i]); } } - if (!d.delete()) - throw new IOException(d + " in use or undeletable"); + deleteFile(d); assert !d.exists(); } + private void deleteFile(File file) throws IOException{ + boolean deleted = false; + for (int i = 0; i < 10; i++) { + if (file.delete()) { + deleted = true; + break; + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // ignore + } + System.out.println(">>> retried deleting " + file.getAbsolutePath()); + } + if (!deleted) + throw new IOException("Retried 10 times. Could not delete " + file.getAbsolutePath()); + } + /** * Create a "temporary" directory * -- cgit v1.2.3