Skip to content

Commit a17f4f0

Browse files
committed
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: codehaus-plexus#37 Signed-off-by: mirabilos <[email protected]>
1 parent 3759018 commit a17f4f0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCac
7171
@Nonnull Map<Integer, String> groupCache )
7272
throws IOException
7373
{
74+
this( file.toPath(), userCache, groupCache );
75+
}
7476

75-
Path path = file.toPath();
77+
public FileAttributes( @Nonnull Path path, @Nonnull Map<Integer, String> userCache,
78+
@Nonnull Map<Integer, String> groupCache )
79+
throws IOException
80+
{
7681
Set<String> views = path.getFileSystem().supportedFileAttributeViews();
7782
String names;
7883
if ( views.contains( "unix" ) )

src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.File;
2828
import java.io.IOException;
2929
import java.io.InputStream;
30+
import java.nio.file.Path;
3031
import java.util.ArrayList;
3132
import java.util.Comparator;
3233
import java.util.HashMap;
@@ -158,8 +159,13 @@ private void addResources( List<PlexusIoResource> result, String[] resources )
158159
{
159160
String sourceDir = name.replace( '\\', '/' );
160161
File f = new File( dir, sourceDir );
162+
Path p = f.toPath();
163+
if ( isFollowingSymLinks() )
164+
{
165+
p = p.toRealPath();
166+
}
161167

162-
FileAttributes fattrs = new FileAttributes( f, cache1, cache2 );
168+
FileAttributes fattrs = new FileAttributes( p, cache1, cache2 );
163169
PlexusIoResourceAttributes attrs = mergeAttributes( fattrs, fattrs.isDirectory() );
164170

165171
String remappedName = getName( name );

0 commit comments

Comments
 (0)