Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/luan/modules/IoLuan.java Fri Apr 17 11:16:38 2020 -0600 +++ b/src/luan/modules/IoLuan.java Fri Apr 17 13:56:57 2020 -0600 @@ -32,6 +32,7 @@ import javax.naming.NameNotFoundException; import javax.naming.directory.Attribute; import javax.naming.directory.InitialDirContext; +import goodjava.io.IoUtils; import luan.Luan; import luan.LuanTable; import luan.LuanFunction; @@ -456,12 +457,11 @@ return file.exists(); } - public void rename_to(Luan luan,Object destObj) throws LuanException { + public void rename_to(Luan luan,Object destObj) throws LuanException, IOException { File dest = objToFile(luan,destObj); if( dest==null ) throw new LuanException( "bad argument #1 to 'rename_to' (string or file table expected)" ); - if( !file.renameTo(dest) ) - throw new LuanException("couldn't rename file "+file+" to "+dest); + IoUtils.move(file,dest); } public void link_to(Luan luan,Object destObj) throws LuanException, IOException { @@ -487,20 +487,19 @@ return new LuanFile(luan,tmp); } - public void delete() throws LuanException { + public void delete() throws IOException { if( file.exists() ) delete(file); } - private static void delete(File file) throws LuanException { + private static void delete(File file) throws IOException { File[] children = file.listFiles(); if( children != null && !isSymbolicLink(file) ) { for( File child : children ) { delete(child); } } - if( !file.delete() ) - throw new LuanException("couldn't delete file "+file); + IoUtils.delete(file); } public void mkdir() throws LuanException {