This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d41d2fd9 [IO-870] PathUtils.copyFileToDirectory() across file systems
0d41d2fd9 is described below

commit 0d41d2fd958f28a0c4eb21afb6f34be8efa0e4fb
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Mar 20 10:23:09 2025 -0400

    [IO-870] PathUtils.copyFileToDirectory() across file systems
    
    Simplify
---
 src/changes/changes.xml                                 | 1 +
 src/main/java/org/apache/commons/io/file/PathUtils.java | 6 ++----
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cbd07f5fe..1fbaed6e5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">FileChannels.contentEquals(FileChannel, FileChannel, int) can return 
false when comparing a non-blocking channel.</action>
       <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">Deprecate FileChannels.contentEquals(FileChannel, FileChannel, int) in 
favor of FileChannels.contentEquals(SeekableByteChannel, SeekableByteChannel, 
int).</action>
       <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">Improve performance of IOUtils.contentEquals(InputStream, InputStream) 
by about 13%.</action>
+      <action dev="ggregory" type="fix" issue="IO-870" due-to="Gary 
Gregory">PathUtils.copyFileToDirectory() across file systems #728.</action>
       <!-- ADD -->
       <action dev="ggregory" type="add" issue="IO-860" due-to="Nico Strecker, 
Gary Gregory">Add ThrottledInputStream.Builder.setMaxBytes(long, 
ChronoUnit).</action>
       <action dev="ggregory" type="add"                due-to="Gary 
Gregory">Add IOIterable.</action>
diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java 
b/src/main/java/org/apache/commons/io/file/PathUtils.java
index 9abdb361e..0d30404c4 100644
--- a/src/main/java/org/apache/commons/io/file/PathUtils.java
+++ b/src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -320,12 +320,10 @@ public static Path copyFile(final URL sourceFile, final 
Path targetFile, final C
      * @throws IOException if an I/O error occurs.
      * @see Files#copy(Path, Path, CopyOption...)
      */
+    @SuppressWarnings("resource") // getFileSystem() is a getter
     public static Path copyFileToDirectory(final Path sourceFile, final Path 
targetDirectory, final CopyOption... copyOptions) throws IOException {
         // Path.resolve() naturally won't work across FileSystem unless we 
convert to a String
-        final Path sourceFileName = sourceFile.getFileName();
-        if (sourceFileName == null) {
-            throw new IllegalArgumentException("must have a file name: " + 
sourceFile);
-        }
+        final Path sourceFileName = 
Objects.requireNonNull(sourceFile.getFileName(), "source file name");
         final Path targetFile;
         if (sourceFileName.getFileSystem() == targetDirectory.getFileSystem()) 
{
             targetFile = targetDirectory.resolve(sourceFileName);

Reply via email to