Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1310:41b35c15ad36 | 1311:ca742d51b31f |
---|---|
23 import java.net.InetAddress; | 23 import java.net.InetAddress; |
24 import java.net.Inet4Address; | 24 import java.net.Inet4Address; |
25 import java.net.NetworkInterface; | 25 import java.net.NetworkInterface; |
26 import java.net.MalformedURLException; | 26 import java.net.MalformedURLException; |
27 import java.net.UnknownHostException; | 27 import java.net.UnknownHostException; |
28 import java.nio.file.Files; | |
28 import java.util.Enumeration; | 29 import java.util.Enumeration; |
29 import java.util.Map; | 30 import java.util.Map; |
30 import luan.LuanState; | 31 import luan.LuanState; |
31 import luan.LuanTable; | 32 import luan.LuanTable; |
32 import luan.LuanFunction; | 33 import luan.LuanFunction; |
460 if( file.exists() ) | 461 if( file.exists() ) |
461 delete(file); | 462 delete(file); |
462 } | 463 } |
463 | 464 |
464 private static void delete(File file) throws LuanException { | 465 private static void delete(File file) throws LuanException { |
465 File[] children = file.listFiles(); | 466 if( !isSymbolicLink(file) ) { |
466 if( children != null ) { | 467 File[] children = file.listFiles(); |
467 for( File child : children ) { | 468 if( children != null ) { |
468 delete(child); | 469 for( File child : children ) { |
470 delete(child); | |
471 } | |
469 } | 472 } |
470 } | 473 } |
471 if( !file.delete() ) | 474 if( !file.delete() ) |
472 throw new LuanException("couldn't delete file "+file); | 475 throw new LuanException("couldn't delete file "+file); |
473 } | 476 } |
480 } | 483 } |
481 | 484 |
482 public void set_last_modified(long time) throws LuanException { | 485 public void set_last_modified(long time) throws LuanException { |
483 if( !file.setLastModified(time) ) | 486 if( !file.setLastModified(time) ) |
484 throw new LuanException("couldn't set_last_modified on "+file); | 487 throw new LuanException("couldn't set_last_modified on "+file); |
488 } | |
489 | |
490 private static boolean isSymbolicLink(File file) { | |
491 return Files.isSymbolicLink(file.toPath()); | |
492 } | |
493 | |
494 public boolean is_symbolic_link() { | |
495 return isSymbolicLink(file); | |
485 } | 496 } |
486 } | 497 } |
487 | 498 |
488 public static LuanUrl classpath(LuanState luan,String name) throws LuanException { | 499 public static LuanUrl classpath(LuanState luan,String name) throws LuanException { |
489 if( name.contains("//") ) | 500 if( name.contains("//") ) |