You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/09/15 19:28:51 UTC

[commons-io] branch master updated (23c837f -> 4ddc11c)

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

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


    from 23c837f  Use assertThrows and don't catch and rethrow exceptions in tests.
     new 1fe7494  Fix Javadoc.
     new 32646f3  More precise Javadoc.
     new 4ddc11c  Use NIO to create sum links but keep OS commands as a back up.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../io/filefilter/SymbolicLinkFileFilter.java      |  6 +--
 .../org/apache/commons/io/FileUtilsTestCase.java   | 47 ++++++++++++++++------
 2 files changed, 37 insertions(+), 16 deletions(-)

[commons-io] 03/03: Use NIO to create sum links but keep OS commands as a back up.

Posted by gg...@apache.org.
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

commit 4ddc11c9fb4f64adb45b46645ab8c8d226b81c13
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 15 15:28:48 2021 -0400

    Use NIO to create sum links but keep OS commands as a back up.
---
 .../org/apache/commons/io/FileUtilsTestCase.java   | 47 ++++++++++++++++------
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
index 092e204..f6680a1 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
@@ -154,6 +154,7 @@ public class FileUtilsTestCase {
      * List files recursively
      */
     private static final ListDirectoryWalker LIST_WALKER = new ListDirectoryWalker();
+
     @TempDir
     public File temporaryFolder;
 
@@ -184,16 +185,38 @@ public class FileUtilsTestCase {
     }
 
     private void createCircularSymLink(final File file) throws IOException {
-        if (!FilenameUtils.isSystemWindows()) {
-            Runtime.getRuntime()
-                    .exec("ln -s " + file + "/.. " + file + "/cycle");
-        } else {
+        assertTrue(file.exists());
+        final String linkName = file + "/cycle";
+        final String targetName = file + "/..";
+        assertTrue(file.exists());
+        final Path linkPath = Paths.get(linkName);
+        assertFalse(Files.exists(linkPath));
+        final Path targetPath = Paths.get(targetName);
+        assertTrue(Files.exists(targetPath));
+        try {
+            // May throw java.nio.file.FileSystemException: C:\Users\...\FileUtilsTestCase\cycle: A required privilege is not held by the client.
+            // On Windows, you are fine if you run a terminal with admin karma.
+            Files.createSymbolicLink(linkPath, targetPath);
+        } catch (final UnsupportedOperationException e) {
+            e.printStackTrace();
+            createCircularOsSymLink(linkName, targetName);
+        }
+        // Sanity check:
+        assertTrue(Files.isSymbolicLink(linkPath), () -> "Expected a sym link here: " + linkName);
+    }
+
+    private void createCircularOsSymLink(final String linkName, final String targetName) throws IOException {
+        if (FilenameUtils.isSystemWindows()) {
+            // Windows
             try {
-                Runtime.getRuntime()
-                        .exec("mklink /D " + file + "/cycle" + file + "/.. ");
-            } catch (final IOException ioe) { // So that tests run in FAT filesystems
-                //don't fail
+                Runtime.getRuntime().exec("mklink /D " + linkName + " " + targetName);
+            } catch (final IOException ioe) {
+                // So that tests run in FAT filesystems don't fail
+                ioe.printStackTrace();
             }
+        } else {
+            // Not Windows, assume Linux
+            Runtime.getRuntime().exec("ln -s " + targetName + " " + linkName);
         }
     }
 
@@ -814,10 +837,8 @@ public class FileUtilsTestCase {
         final File childDir = new File(parentDir, "child");
         createFilesForTestCopyDirectory(grandParentDir, parentDir, childDir);
 
-        final long expectedCount = LIST_WALKER.list(grandParentDir).size() +
-                LIST_WALKER.list(parentDir).size();
-        final long expectedSize = FileUtils.sizeOfDirectory(grandParentDir) +
-                FileUtils.sizeOfDirectory(parentDir);
+        final long expectedCount = LIST_WALKER.list(grandParentDir).size() + LIST_WALKER.list(parentDir).size();
+        final long expectedSize = FileUtils.sizeOfDirectory(grandParentDir) + FileUtils.sizeOfDirectory(parentDir);
         FileUtils.copyDirectory(parentDir, childDir);
         assertEquals(expectedCount, LIST_WALKER.list(grandParentDir).size());
         assertEquals(expectedSize, FileUtils.sizeOfDirectory(grandParentDir));
@@ -2538,7 +2559,7 @@ public class FileUtilsTestCase {
         file.delete();
         file.mkdir();
 
-        this.createCircularSymLink(file);
+        createCircularSymLink(file);
 
         assertEquals(TEST_DIRECTORY_SIZE_BI, FileUtils.sizeOfDirectoryAsBigInteger(file), "Unexpected directory size");
 

[commons-io] 01/03: Fix Javadoc.

Posted by gg...@apache.org.
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

commit 1fe7494a03eb5fa8a9f0702cca1a066cab658e01
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 15 12:01:36 2021 -0400

    Fix Javadoc.
---
 .../java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
index 3697766..aafbe99 100644
--- a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
+++ b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
@@ -41,7 +41,7 @@ import java.nio.file.attribute.BasicFileAttributes;
  * <h2>Using NIO</h2>
  * <pre>
  * final Path dir = Paths.get("");
- * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.FILE);
+ * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.INSTANCE);
  * //
  * // Walk one dir
  * Files.<b>walkFileTree</b>(dir, Collections.emptySet(), 1, visitor);

[commons-io] 02/03: More precise Javadoc.

Posted by gg...@apache.org.
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

commit 32646f31867ae47ec35d63e0e5bc45037e3e4c9b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 15 12:13:01 2021 -0400

    More precise Javadoc.
---
 .../java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
index aafbe99..05e7f7f 100644
--- a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
+++ b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
@@ -87,10 +87,10 @@ public class SymbolicLinkFileFilter extends AbstractFileFilter implements Serial
     }
 
     /**
-     * Checks to see if the file is a file.
+     * Checks to see if the file is a symbolic link.
      * @param file  the File to check
      *
-     * @return true if the file is a file
+     * @return true if the file is a symbolic link.
      */
     @Override
     public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {