Copilot commented on code in PR #2628:
URL: https://github.com/apache/karaf/pull/2628#discussion_r3176794337


##########
features/command/src/main/java/org/apache/karaf/features/command/FeatureExport.java:
##########
@@ -172,23 +170,15 @@ private void saveBundles(final File dest, final Feature 
feature, final FeaturesS
     private static boolean copyFileToDirectory(final File file, final File 
directory) throws IOException {
         if (!directory.isDirectory()) {
             throw new IOException("Can't copy to non-directory specified: " + 
directory.getAbsolutePath());
-        } else {
-            boolean copied = false;
-            final File newFile = new File(directory.getAbsolutePath() + "/" + 
file.getName());
-            if (!newFile.isFile()) {
-                try (final FileInputStream fis = new FileInputStream(file)) {
-                    try (final FileOutputStream fos = new 
FileOutputStream(newFile)) {
-                        byte[] buffer = new byte[1024 * 8];
-                        int read = -1;
-                        while ((read = fis.read(buffer)) >= 0) {
-                            fos.write(buffer, 0, read);
-                        }
-                    }
-                }
-                copied = true;
-            }
-            return copied;
         }
+
+        final var newFile = directory.toPath().resolve(file.getName());
+        if (Files.isRegularFile(newFile)) {
+            return false;
+        }
+
+        Files.copy(file.toPath(), newFile);

Review Comment:
   This refactor changes the copy implementation to `Files.copy()`, which has 
different failure modes from the previous stream-based copy (for example around 
existing targets and missing source files), but this command still has no unit 
tests covering `copyFileToDirectory()`/`saveBundles()`. Since this module 
already has command-level tests, please add coverage here to lock in the 
intended behavior before merging.



##########
features/command/src/main/java/org/apache/karaf/features/command/FeatureExport.java:
##########
@@ -17,10 +17,9 @@
 package org.apache.karaf.features.command;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;

Review Comment:
   `FileNotFoundException` is no longer referenced after the switch to 
`Files.copy()`, so this import is now dead code. Please remove it to keep the 
file clean and avoid unused-import checks failing if they are enabled.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to