From a17f4f0bfe0fd213afb8d5e53b5b68c309c0da2e Mon Sep 17 00:00:00 2001 From: mirabilos Date: Fri, 8 Jan 2021 20:53:09 +0100 Subject: [PATCH] Support following symbolic links to files This implements the necessary support to allow plexus-archiver to archive the contents of symlinks (instead of the symbolic links themselves), depending on the (already-extant) follow-symlinks flag. Closes: https://github.com/codehaus-plexus/plexus-io/issues/37 Signed-off-by: mirabilos --- .../plexus/components/io/attributes/FileAttributes.java | 7 ++++++- .../io/resources/PlexusIoFileResourceCollection.java | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index 6b90fdff..4942e05b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -71,8 +71,13 @@ public FileAttributes( @Nonnull File file, @Nonnull Map userCac @Nonnull Map groupCache ) throws IOException { + this( file.toPath(), userCache, groupCache ); + } - Path path = file.toPath(); + public FileAttributes( @Nonnull Path path, @Nonnull Map userCache, + @Nonnull Map groupCache ) + throws IOException + { Set views = path.getFileSystem().supportedFileAttributeViews(); String names; if ( views.contains( "unix" ) ) diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java index 75631f15..ce3dcb10 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -158,8 +159,13 @@ private void addResources( List result, String[] resources ) { String sourceDir = name.replace( '\\', '/' ); File f = new File( dir, sourceDir ); + Path p = f.toPath(); + if ( isFollowingSymLinks() ) + { + p = p.toRealPath(); + } - FileAttributes fattrs = new FileAttributes( f, cache1, cache2 ); + FileAttributes fattrs = new FileAttributes( p, cache1, cache2 ); PlexusIoResourceAttributes attrs = mergeAttributes( fattrs, fattrs.isDirectory() ); String remappedName = getName( name );