diff src/luan/modules/IoLuan.java @ 1311:ca742d51b31f

don't delete into symbolic links
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 24 Jan 2019 21:15:03 -0700
parents 781ec0a92bb5
children 15af473045c4
line wrap: on
line diff
--- a/src/luan/modules/IoLuan.java	Thu Jan 24 12:20:33 2019 -0700
+++ b/src/luan/modules/IoLuan.java	Thu Jan 24 21:15:03 2019 -0700
@@ -25,6 +25,7 @@
 import java.net.NetworkInterface;
 import java.net.MalformedURLException;
 import java.net.UnknownHostException;
+import java.nio.file.Files;
 import java.util.Enumeration;
 import java.util.Map;
 import luan.LuanState;
@@ -462,10 +463,12 @@
 		}
 
 		private static void delete(File file) throws LuanException {
-			File[] children = file.listFiles();
-			if( children != null ) {
-				for( File child : children ) {
-					delete(child);
+			if( !isSymbolicLink(file) ) {
+				File[] children = file.listFiles();
+				if( children != null ) {
+					for( File child : children ) {
+						delete(child);
+					}
 				}
 			}
 			if( !file.delete() )
@@ -483,6 +486,14 @@
 			if( !file.setLastModified(time) )
 				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);
+		}
 	}
 
 	public static LuanUrl classpath(LuanState luan,String name) throws LuanException {