Mercurial Hosting > luan
diff src/luan/modules/IoLuan.java @ 1367:836e00bf7ce2
add Lucene backup_to
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Jun 2019 16:27:03 -0600 |
parents | 0cceff521abb |
children | b765f146f4dc |
line wrap: on
line diff
--- a/src/luan/modules/IoLuan.java Mon Jun 17 21:50:40 2019 -0600 +++ b/src/luan/modules/IoLuan.java Tue Jun 18 16:27:03 2019 -0600 @@ -134,9 +134,11 @@ } - private static File objToFile(Object obj) { + private static File objToFile(Luan luan,Object obj) throws LuanException { if( obj instanceof String ) { - return new File((String)obj); + String fileName = (String)obj; + check(luan,"file:"+fileName); + return new File(fileName); } if( obj instanceof LuanTable ) { LuanTable t = (LuanTable)obj; @@ -444,14 +446,28 @@ return file.exists(); } - public void rename_to(Object destObj) throws LuanException { - File dest = objToFile(destObj); + public void rename_to(Luan luan,Object destObj) throws LuanException { + File dest = objToFile(luan,destObj); if( dest==null ) - throw new LuanException( "bad argument #1 to 'objToFile' (string or file table expected)" ); + 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); } + public void link_to(Luan luan,Object destObj) throws LuanException, IOException { + File dest = objToFile(luan,destObj); + if( dest==null ) + throw new LuanException( "bad argument #1 to 'link_to' (string or file table expected)" ); + Files.createLink( file.toPath(), dest.toPath() ); + } + + public void symlink_to(Luan luan,Object destObj) throws LuanException, IOException { + File dest = objToFile(luan,destObj); + if( dest==null ) + throw new LuanException( "bad argument #1 to 'symlink_to' (string or file table expected)" ); + Files.createSymbolicLink( file.toPath(), dest.toPath() ); + } + public LuanFile canonical(Luan luan) throws LuanException, IOException { return new LuanFile(luan,file.getCanonicalFile()); } @@ -535,13 +551,13 @@ final File dir; Process proc; - private BaseOs(String cmd,LuanTable options) throws IOException, LuanException { + private BaseOs(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { this.cmd = cmd; File dir = null; if( options != null ) { Map map = options.asMap(); Object obj = map.remove("dir"); - dir = objToFile(obj); + dir = objToFile(luan,obj); if( dir==null ) throw new LuanException( "bad option 'dir' (string or file table expected)" ); if( !map.isEmpty() ) @@ -596,7 +612,7 @@ public static final class LuanOs extends BaseOs { public LuanOs(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { - super(cmd,options); + super(luan,cmd,options); check(luan,"os:"+cmd); this.proc = Runtime.getRuntime().exec(cmd,null,dir); } @@ -604,7 +620,7 @@ public static final class LuanBash extends BaseOs { public LuanBash(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { - super(cmd,options); + super(luan,cmd,options); check(luan,"bash:"+cmd); this.proc = Runtime.getRuntime().exec(new String[]{"bash","-c",cmd},null,dir); }