comparison src/luan/modules/IoLuan.java @ 1475:c7b86342857f

more IoUtils
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 18 Apr 2020 11:02:18 -0600
parents 6c6ce14db6a8
children 471ef3e6a84e
comparison
equal deleted inserted replaced
1474:13cbce740e1e 1475:c7b86342857f
486 File tmp = File.createTempFile(prefix,suffix,file); 486 File tmp = File.createTempFile(prefix,suffix,file);
487 return new LuanFile(luan,tmp); 487 return new LuanFile(luan,tmp);
488 } 488 }
489 489
490 public void delete() throws IOException { 490 public void delete() throws IOException {
491 if( file.exists() ) 491 IoUtils.deleteRecursively(file);
492 delete(file);
493 }
494
495 private static void delete(File file) throws IOException {
496 File[] children = file.listFiles();
497 if( children != null && !isSymbolicLink(file) ) {
498 for( File child : children ) {
499 delete(child);
500 }
501 }
502 IoUtils.delete(file);
503 } 492 }
504 493
505 public void mkdir() throws LuanException { 494 public void mkdir() throws LuanException {
506 if( !file.isDirectory() ) { 495 if( !file.isDirectory() ) {
507 if( !file.mkdirs() ) 496 if( !file.mkdirs() )
512 public void set_last_modified(long time) throws LuanException { 501 public void set_last_modified(long time) throws LuanException {
513 if( !file.setLastModified(time) ) 502 if( !file.setLastModified(time) )
514 throw new LuanException("couldn't set_last_modified on "+file); 503 throw new LuanException("couldn't set_last_modified on "+file);
515 } 504 }
516 505
517 private static boolean isSymbolicLink(File file) {
518 return Files.isSymbolicLink(file.toPath());
519 }
520
521 public boolean is_symbolic_link() { 506 public boolean is_symbolic_link() {
522 return isSymbolicLink(file); 507 return IoUtils.isSymbolicLink(file);
523 } 508 }
524 } 509 }
525 510
526 public static LuanUrl classpath(Luan luan,String name) throws LuanException { 511 public static LuanUrl classpath(Luan luan,String name) throws LuanException {
527 if( name.contains("//") ) 512 if( name.contains("//") )