Mercurial Hosting > luan
comparison src/luan/modules/IoLuan.java @ 1473:6c6ce14db6a8
add goodjava.io
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 17 Apr 2020 13:56:57 -0600 |
parents | 580ee513a4b7 |
children | c7b86342857f |
comparison
equal
deleted
inserted
replaced
1472:60f6741f000a | 1473:6c6ce14db6a8 |
---|---|
30 import java.util.Map; | 30 import java.util.Map; |
31 import javax.naming.NamingException; | 31 import javax.naming.NamingException; |
32 import javax.naming.NameNotFoundException; | 32 import javax.naming.NameNotFoundException; |
33 import javax.naming.directory.Attribute; | 33 import javax.naming.directory.Attribute; |
34 import javax.naming.directory.InitialDirContext; | 34 import javax.naming.directory.InitialDirContext; |
35 import goodjava.io.IoUtils; | |
35 import luan.Luan; | 36 import luan.Luan; |
36 import luan.LuanTable; | 37 import luan.LuanTable; |
37 import luan.LuanFunction; | 38 import luan.LuanFunction; |
38 import luan.LuanException; | 39 import luan.LuanException; |
39 import luan.modules.url.LuanUrl; | 40 import luan.modules.url.LuanUrl; |
454 | 455 |
455 @Override public boolean exists() { | 456 @Override public boolean exists() { |
456 return file.exists(); | 457 return file.exists(); |
457 } | 458 } |
458 | 459 |
459 public void rename_to(Luan luan,Object destObj) throws LuanException { | 460 public void rename_to(Luan luan,Object destObj) throws LuanException, IOException { |
460 File dest = objToFile(luan,destObj); | 461 File dest = objToFile(luan,destObj); |
461 if( dest==null ) | 462 if( dest==null ) |
462 throw new LuanException( "bad argument #1 to 'rename_to' (string or file table expected)" ); | 463 throw new LuanException( "bad argument #1 to 'rename_to' (string or file table expected)" ); |
463 if( !file.renameTo(dest) ) | 464 IoUtils.move(file,dest); |
464 throw new LuanException("couldn't rename file "+file+" to "+dest); | |
465 } | 465 } |
466 | 466 |
467 public void link_to(Luan luan,Object destObj) throws LuanException, IOException { | 467 public void link_to(Luan luan,Object destObj) throws LuanException, IOException { |
468 File dest = objToFile(luan,destObj); | 468 File dest = objToFile(luan,destObj); |
469 if( dest==null ) | 469 if( dest==null ) |
485 public LuanFile create_temp_file(Luan luan,String prefix,String suffix) throws LuanException, IOException { | 485 public LuanFile create_temp_file(Luan luan,String prefix,String suffix) throws LuanException, IOException { |
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 LuanException { | 490 public void delete() throws IOException { |
491 if( file.exists() ) | 491 if( file.exists() ) |
492 delete(file); | 492 delete(file); |
493 } | 493 } |
494 | 494 |
495 private static void delete(File file) throws LuanException { | 495 private static void delete(File file) throws IOException { |
496 File[] children = file.listFiles(); | 496 File[] children = file.listFiles(); |
497 if( children != null && !isSymbolicLink(file) ) { | 497 if( children != null && !isSymbolicLink(file) ) { |
498 for( File child : children ) { | 498 for( File child : children ) { |
499 delete(child); | 499 delete(child); |
500 } | 500 } |
501 } | 501 } |
502 if( !file.delete() ) | 502 IoUtils.delete(file); |
503 throw new LuanException("couldn't delete file "+file); | |
504 } | 503 } |
505 | 504 |
506 public void mkdir() throws LuanException { | 505 public void mkdir() throws LuanException { |
507 if( !file.isDirectory() ) { | 506 if( !file.isDirectory() ) { |
508 if( !file.mkdirs() ) | 507 if( !file.mkdirs() ) |