Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Java: be more verbose when cleaning the disk on exit fails
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 2 Jun 2016 09:50:09 +0000 (11:50 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 2 Jun 2016 09:50:09 +0000 (11:50 +0200)
src/bindings/java/org/simgrid/NativeLib.java

index 7865f1c..35527c0 100644 (file)
@@ -112,7 +112,7 @@ public final class NativeLib {
                try {
                        // We must write the lib onto the disk before loading it -- stupid operating systems
                        if (tempDir == null) {
                try {
                        // We must write the lib onto the disk before loading it -- stupid operating systems
                        if (tempDir == null) {
-                               tempDir = Files.createTempDirectory("simgrid-java");
+                               tempDir = Files.createTempDirectory("simgrid-java-");
                                // don't leak the files on disk, but remove it on JVM shutdown
                                Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(tempDir.toFile())));
                        }
                                // don't leak the files on disk, but remove it on JVM shutdown
                                Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(tempDir.toFile())));
                        }
@@ -143,11 +143,13 @@ public final class NativeLib {
                @Override
                public void run() {
                        try {
                @Override
                public void run() {
                        try {
-                           for (File f : dir.listFiles())
-                               f.delete();
-                               dir.delete();
+                               for (File f : dir.listFiles())
+                                       if (! f.delete() )
+                                               System.err.println("Unable to clean temporary file "+f.getAbsolutePath()+" during shutdown.");
+                           if (! dir.delete() )
+                                       System.err.println("Unable to clean temporary file "+dir.getAbsolutePath()+" during shutdown.");                                
                        } catch(Exception e) {
                        } catch(Exception e) {
-                               System.out.println("Unable to clean temporary file "+dir.getAbsolutePath()+" during shutdown.");
+                               System.err.println("Unable to clean temporary file "+dir.getAbsolutePath()+" during shutdown: "+e.getCause());
                                e.printStackTrace();
                        }
                }    
                                e.printStackTrace();
                        }
                }