You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2020/05/26 01:05:00 UTC

[maven-shared-utils] branch pr-31 updated (0598dac -> 8b35ffc)

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

olamy pushed a change to branch pr-31
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git.


    omit 0598dac  [MSHARED-681] Tests explicitly assuming Windows use consistent assumption
    omit ecee0e8  [MSHARED-681] createSymbolicLink() overwrites existing different symlinks
     new 8b35ffc  [MSHARED-681] createSymbolicLink() overwrites existing different symlinks Tests explicitly assuming Windows use consistent assumption

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (0598dac)
            \
             N -- N -- N   refs/heads/pr-31 (8b35ffc)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:


[maven-shared-utils] 01/01: [MSHARED-681] createSymbolicLink() overwrites existing different symlinks Tests explicitly assuming Windows use consistent assumption

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch pr-31
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit 8b35ffcf1b410a0870a22ae37f18d96423d42852
Author: Rob Oxspring <ro...@imapmail.org>
AuthorDate: Sun May 17 21:57:24 2020 +0100

    [MSHARED-681] createSymbolicLink() overwrites existing different symlinks
    Tests explicitly assuming Windows use consistent assumption
---
 .../apache/maven/shared/utils/io/FileUtils.java    | 15 ++++++++---
 .../maven/shared/utils/io/FileUtilsTest.java       | 29 ++++++++++++++++++++--
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
index 895cf44..24dcf98 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
@@ -42,6 +42,7 @@ import java.net.URL;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.security.SecureRandom;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
@@ -2004,10 +2005,18 @@ public class FileUtils
     @Nonnull public static File createSymbolicLink( @Nonnull File symlink,  @Nonnull File target )
             throws IOException
     {
-        if ( !Files.exists( symlink.toPath() ) )
+        final Path symlinkPath = symlink.toPath();
+
+        if ( Files.exists( symlinkPath ) )
         {
-            return Files.createSymbolicLink( symlink.toPath(), target.toPath() ).toFile();
+            if ( target.equals( Files.readSymbolicLink( symlinkPath ).toFile() ) )
+            {
+                return symlink;
+            }
+
+            Files.delete( symlinkPath );
         }
-        return symlink;
+
+        return Files.createSymbolicLink( symlinkPath, target.toPath() ).toFile();
     }
 }
diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
index 46b94ff..b9fd7c4 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
@@ -1429,7 +1429,7 @@ public class FileUtilsTest
         throws IOException
     {
         // This testcase will pass when running under java7 or higher
-        assumeThat( Os.isFamily(Os.FAMILY_WINDOWS), is(false) );
+        assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) );
 
         File file = new File( "src/test/resources/symlinks/src/symDir" );
         assertTrue(FileUtils.isSymbolicLink(file  ));
@@ -1466,7 +1466,8 @@ public class FileUtilsTest
     public void createAndReadSymlink()
         throws Exception
     {
-        assumeThat( System.getProperty( "os.name" ), not( startsWith( "Windows" ) ) );
+        assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) );
+
         File file = new File( "target/fzz" );
         FileUtils.createSymbolicLink(  file, new File("../target") );
 
@@ -1475,6 +1476,30 @@ public class FileUtilsTest
         Files.delete( file.toPath() );
     }
 
+    @Test
+    public void createSymbolicLinkWithDifferentTargetOverwritesSymlink()
+            throws Exception
+    {
+        assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) );
+
+        // Arrange
+
+        final File symlink1 = new File( tempFolder.getRoot(), "symlink" );
+
+        FileUtils.createSymbolicLink( symlink1, testFile1 );
+
+        // Act
+
+        final File symlink2 = FileUtils.createSymbolicLink( symlink1, testFile2 );
+
+        // Assert
+
+        assertThat(
+            Files.readSymbolicLink( symlink2.toPath() ).toFile(),
+            CoreMatchers.equalTo( testFile2 )
+        );
+    }
+
     //// constants for testing
 
     private static final String[] MINIMUM_DEFAULT_EXCLUDES = {