mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] lgoldstein commented on a change in pull request #89: [SSHD-893] Fix SCP download with pattern issue in rooted filesystem
Date Mon, 11 Feb 2019 17:11:02 GMT
lgoldstein commented on a change in pull request #89: [SSHD-893] Fix SCP download with pattern
issue in rooted filesystem
URL: https://github.com/apache/mina-sshd/pull/89#discussion_r255604869
 
 

 ##########
 File path: sshd-common/src/main/java/org/apache/sshd/common/util/io/DirectoryScanner.java
 ##########
 @@ -244,46 +257,35 @@ public void setIncludes(String[] includes) {
      * matching of includes, excludes, and the selectors. When a directory
      * is found, it is scanned recursively.
      *
-     * @param dir   The directory to scan. Must not be {@code null}.
-     * @param vpath The path relative to the base directory (needed to
-     *              prevent problems with an absolute path when using
-     *              dir). Must not be {@code null}.
+     * @param <C> Target matches collection type
+     * @param dir The directory to scan. Must not be {@code null}.
+     * @param vpath The path relative to the base directory (needed to prevent
+     * problems with an absolute path when using <tt>dir</tt>). Must not be {@code
null}.
+     * @param filesList Target {@link Collection} to accumulate the relative
+     * path matches
+     * @throws IOException if failed to scan the directory
      */
-    protected void scandir(File dir, String vpath) {
-        String[] newfiles = dir.list();
-        if (GenericUtils.isEmpty(newfiles)) {
-            newfiles = GenericUtils.EMPTY_STRING_ARRAY;
-        }
-
-        for (String newfile : newfiles) {
-            String name = vpath + newfile;
-            File file = new File(dir, newfile);
-            if (file.isDirectory()) {
-                if (isIncluded(name)) {
-                    filesIncluded.add(name);
-                    scandir(file, name + File.separator);
-                } else if (couldHoldIncluded(name)) {
-                    scandir(file, name + File.separator);
-                }
-            } else if (file.isFile()) {
-                if (isIncluded(name)) {
-                    filesIncluded.add(name);
+    protected <C extends Collection<Path>> C scandir(Path rootDir, Path dir,
C filesList) throws IOException {
+        try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir)) {
+            for (Path p : ds) {
+                Path rel = rootDir.relativize(p);
+                String name = rel.toString();
 
 Review comment:
   1. Cascaded calls are not more efficient than separate ones
   2. Separating calls makes the code more debug-able...
   . 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message