FS utils throws IOException
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 8 May 2023 05:40:51 +0000 (07:40 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 8 May 2023 05:40:51 +0000 (07:40 +0200)
org.argeo.cms/src/org/argeo/cms/acr/fs/FsContent.java
org.argeo.cms/src/org/argeo/cms/util/FsUtils.java

index 5920c420370c78a4051f9000820af7d16c1c34da..8fca831b024293084a07ded2ff93d9ad8a9085e4 100644 (file)
@@ -315,7 +315,11 @@ public class FsContent extends AbstractContent implements ProvidedContent {
 
        @Override
        public void remove() {
-               FsUtils.delete(path);
+               try {
+                       FsUtils.delete(path);
+               } catch (IOException e) {
+                       throw new RuntimeException("Cannot delete " + path, e);
+               }
        }
 
        @Override
index 26c05b60e424fdba6a97d8f4173c85b72f33841c..57555ee53b189b3894fc5197890ddebf04bb08d1 100644 (file)
@@ -47,28 +47,24 @@ public class FsUtils {
         * Deletes this path, recursively if needed. Does nothing if the path does not
         * exist.
         */
-       public static void delete(Path path) {
-               try {
-                       if (!Files.exists(path))
-                               return;
-                       Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
-                               @Override
-                               public FileVisitResult postVisitDirectory(Path directory, IOException e) throws IOException {
-                                       if (e != null)
-                                               throw e;
-                                       Files.delete(directory);
-                                       return FileVisitResult.CONTINUE;
-                               }
+       public static void delete(Path path) throws IOException {
+               if (!Files.exists(path))
+                       return;
+               Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+                       @Override
+                       public FileVisitResult postVisitDirectory(Path directory, IOException e) throws IOException {
+                               if (e != null)
+                                       throw e;
+                               Files.delete(directory);
+                               return FileVisitResult.CONTINUE;
+                       }
 
-                               @Override
-                               public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                                       Files.delete(file);
-                                       return FileVisitResult.CONTINUE;
-                               }
-                       });
-               } catch (IOException e) {
-                       throw new RuntimeException("Cannot delete " + path, e);
-               }
+                       @Override
+                       public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+                               Files.delete(file);
+                               return FileVisitResult.CONTINUE;
+                       }
+               });
        }
 
        /** Singleton. */