diff --git a/src/main/java/com/github/jlangch/venice/impl/functions/IOFunctions.java b/src/main/java/com/github/jlangch/venice/impl/functions/IOFunctions.java index 9c5da6a28..abaef7b14 100644 --- a/src/main/java/com/github/jlangch/venice/impl/functions/IOFunctions.java +++ b/src/main/java/com/github/jlangch/venice/impl/functions/IOFunctions.java @@ -1948,18 +1948,17 @@ public VncVal apply(final VncList args) { validateReadableDirectory(srcdir); validateWritableDirectory(dstdir); - final List files = new ArrayList<>(); - try (DirectoryStream dirStream = Files.newDirectoryStream(srcdir.toPath(), glob)) { dirStream.forEach(path -> { - files.add(new VncJavaObject(path.toFile())); try { - Files.copy( + final Path d = dstdir.toPath().resolve(srcdir.toPath().relativize(path)); + + Files.copy( path, - dstdir.toPath(), + d, copyOptions.toArray(new CopyOption[0])); } - catch(IOException ex) { + catch(Exception ex) { throw new VncException( String.format("Failed to copy file %s", path), ex); @@ -1979,7 +1978,7 @@ public VncVal apply(final VncList args) { ex); } - return VncList.ofList(files); + return Nil; } private static final long serialVersionUID = -1848883965231344442L; @@ -2199,30 +2198,29 @@ public VncVal apply(final VncList args) { final String glob = Coerce.toVncString(args.third()).getValue(); - final VncHashMap options = VncHashMap.ofAll(args.rest().rest()); + final VncHashMap options = VncHashMap.ofAll(args.rest().rest().rest()); final VncVal replaceOpt = options.get(new VncKeyword("replace")); final VncVal atomicMoveOpt = options.get(new VncKeyword("atomic-move")); validateReadableDirectory(srcdir); validateWritableDirectory(dstdir); - final List files = new ArrayList<>(); + final List moveOptions = new ArrayList<>(); + if (VncBoolean.isTrue(replaceOpt)) { + moveOptions.add(StandardCopyOption.REPLACE_EXISTING); + } + if (VncBoolean.isTrue(atomicMoveOpt)) { + moveOptions.add(StandardCopyOption.ATOMIC_MOVE); + } try (DirectoryStream dirStream = Files.newDirectoryStream(srcdir.toPath(), glob)) { dirStream.forEach(path -> { - files.add(new VncJavaObject(path.toFile())); try { - final List moveOptions = new ArrayList<>(); - if (VncBoolean.isTrue(replaceOpt)) { - moveOptions.add(StandardCopyOption.REPLACE_EXISTING); - } - if (VncBoolean.isTrue(atomicMoveOpt)) { - moveOptions.add(StandardCopyOption.ATOMIC_MOVE); - } + final Path d = dstdir.toPath().resolve(srcdir.toPath().relativize(path)); Files.move( path, - dstdir.toPath(), + d, moveOptions.toArray(new CopyOption[0])); } catch(IOException ex) { @@ -2245,7 +2243,7 @@ public VncVal apply(final VncList args) { ex); } - return VncList.ofList(files); + return Nil; } private static final long serialVersionUID = -1848883965231344442L;