changeset 1475:c7b86342857f

more IoUtils
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 18 Apr 2020 11:02:18 -0600
parents 13cbce740e1e
children 7d145095cc0b
files src/goodjava/io/IoUtils.java src/goodjava/lucene/logging/LoggingIndexWriter.java src/luan/modules/IoLuan.java
diffstat 3 files changed, 18 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/goodjava/io/IoUtils.java	Fri Apr 17 21:53:09 2020 -0600
+++ b/src/goodjava/io/IoUtils.java	Sat Apr 18 11:02:18 2020 -0600
@@ -15,4 +15,18 @@
 	public static void delete(File file) throws IOException {
 		Files.deleteIfExists( file.toPath() );
 	}
+
+	public static boolean isSymbolicLink(File file) {
+		return Files.isSymbolicLink(file.toPath());
+	}
+
+	public static void deleteRecursively(File file) throws IOException {
+		if( file.isDirectory() && !isSymbolicLink(file) ) {
+			for( File f : file.listFiles() ) {
+				deleteRecursively(f);
+			}
+		}
+		delete(file);
+	}
+
 }
\ No newline at end of file
--- a/src/goodjava/lucene/logging/LoggingIndexWriter.java	Fri Apr 17 21:53:09 2020 -0600
+++ b/src/goodjava/lucene/logging/LoggingIndexWriter.java	Sat Apr 18 11:02:18 2020 -0600
@@ -123,20 +123,11 @@
 		}
 		for( File f : logDir.listFiles() ) {
 			if( !used.contains(f.getName()) ) {
-				deleteFile(f);
+				IoUtils.deleteRecursively(f);
 			}
 		}
 	}
 
-	private static void deleteFile(File file) throws IOException {
-		if( file.isDirectory() ) {
-			for( File f : file.listFiles() ) {
-				deleteFile(f);
-			}
-		}
-		IoUtils.delete(file);
-	}
-
 	private void writeIndex() throws IOException {
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		DataOutputStream dos = new DataOutputStream(baos);
@@ -218,7 +209,7 @@
 			System.exit(-1);
 		}
 		checkWriter.close();
-		deleteFile(dirFile);
+		IoUtils.deleteRecursively(dirFile);
 	}
 
 	private LogFile log() {
--- a/src/luan/modules/IoLuan.java	Fri Apr 17 21:53:09 2020 -0600
+++ b/src/luan/modules/IoLuan.java	Sat Apr 18 11:02:18 2020 -0600
@@ -488,18 +488,7 @@
 		}
 
 		public void delete() throws IOException {
-			if( file.exists() )
-				delete(file);
-		}
-
-		private static void delete(File file) throws IOException {
-			File[] children = file.listFiles();
-			if( children != null && !isSymbolicLink(file) ) {
-				for( File child : children ) {
-					delete(child);
-				}
-			}
-			IoUtils.delete(file);
+			IoUtils.deleteRecursively(file);
 		}
 
 		public void mkdir() throws LuanException {
@@ -514,12 +503,8 @@
 				throw new LuanException("couldn't set_last_modified on "+file);
 		}
 
-		private static boolean isSymbolicLink(File file) {
-			return Files.isSymbolicLink(file.toPath());
-		}
-
 		public boolean is_symbolic_link() {
-			return isSymbolicLink(file);
+			return IoUtils.isSymbolicLink(file);
 		}
 	}