Mercurial Hosting > luan
changeset 1661:08177ced7fa0
add file.copy_to
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 02 May 2022 18:56:55 -0600 |
parents | 2968e43cdd44 |
children | d6a50ed9604f |
files | src/goodjava/io/IoUtils.java src/luan/modules/Boot.luan src/luan/modules/IoLuan.java |
diffstat | 3 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 2968e43cdd44 -r 08177ced7fa0 src/goodjava/io/IoUtils.java --- a/src/goodjava/io/IoUtils.java Tue Apr 19 23:46:06 2022 -0600 +++ b/src/goodjava/io/IoUtils.java Mon May 02 18:56:55 2022 -0600 @@ -26,6 +26,10 @@ Files.move( from.toPath(), to.toPath() ); } + public static void copy( File from, File to ) throws IOException { + Files.copy( from.toPath(), to.toPath() ); + } + public static void delete(File file) throws IOException { Files.deleteIfExists( file.toPath() ); }
diff -r 2968e43cdd44 -r 08177ced7fa0 src/luan/modules/Boot.luan --- a/src/luan/modules/Boot.luan Tue Apr 19 23:46:06 2022 -0600 +++ b/src/luan/modules/Boot.luan Mon May 02 18:56:55 2022 -0600 @@ -193,6 +193,7 @@ this.set_last_modified = io.set_last_modified this.length = io.file.length this.rename_to = io.rename_to + this.copy_to = io.copy_to this.link_from = io.link_from this.symlink_from = io.symlink_from this.is_symbolic_link = io.is_symbolic_link
diff -r 2968e43cdd44 -r 08177ced7fa0 src/luan/modules/IoLuan.java --- a/src/luan/modules/IoLuan.java Tue Apr 19 23:46:06 2022 -0600 +++ b/src/luan/modules/IoLuan.java Mon May 02 18:56:55 2022 -0600 @@ -453,6 +453,13 @@ IoUtils.move(file,dest); } + public void copy_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)" ); + IoUtils.copy(file,dest); + } + public void link_from(Luan luan,Object linkObj) throws LuanException, IOException { File link = objToFile(luan,linkObj); if( link==null )