diff --git a/src/test/java/ysoserial/payloads/FileUploadTest.java b/src/test/java/ysoserial/payloads/FileUploadTest.java index 01c31b6..ee186ec 100644 --- a/src/test/java/ysoserial/payloads/FileUploadTest.java +++ b/src/test/java/ysoserial/payloads/FileUploadTest.java @@ -47,9 +47,12 @@ public class FileUploadTest implements CustomTest { payload.call(); File found = null; - for ( File f : this.repo.listFiles()) { - found = f; - break; + for (int i = 0; i < 50 && found == null; i++) { // try for 5s before failing + for (File f : this.repo.listFiles()) { + found = f; + break; + } + Thread.sleep(100); } Assert.assertNotNull("File not copied", found); if (OS.get() != OS.WINDOWS) { @@ -60,11 +63,21 @@ public class FileUploadTest implements CustomTest { } finally { if ( this.repo.exists()) { for ( File f : this.repo.listFiles()) { - f.deleteOnExit(); + safeDeleteOnExit(f); } - this.repo.deleteOnExit(); + safeDeleteOnExit(this.repo); } - this.source.deleteOnExit(); + safeDeleteOnExit(this.source); + } + } + + private static void safeDeleteOnExit(File f) { + try { + if (f.exists()) { + f.deleteOnExit(); + } + } catch (Exception e) { + e.printStackTrace(); } }