changeset 1311:ca742d51b31f

don't delete into symbolic links
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 24 Jan 2019 21:15:03 -0700
parents 41b35c15ad36
children 60d013d5c7ef
files src/luan/modules/Boot.luan src/luan/modules/IoLuan.java
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/Boot.luan	Thu Jan 24 12:20:33 2019 -0700
+++ b/src/luan/modules/Boot.luan	Thu Jan 24 21:15:03 2019 -0700
@@ -129,6 +129,7 @@
 	this.set_last_modified = io.set_last_modified
 	this.length = io.file.length
 	this.rename_to = io.rename_to
+	this.is_symbolic_link = io.is_symbolic_link
 
 	function this.child(name)
 		return new_LuanFile( io.child(name) )
--- 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 {