Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCac
@Nonnull Map<Integer, String> groupCache )
throws IOException
{
this( file.toPath(), userCache, groupCache );
}

Path path = file.toPath();
public FileAttributes( @Nonnull Path path, @Nonnull Map<Integer, String> userCache,
@Nonnull Map<Integer, String> groupCache )
throws IOException
{
Set<String> views = path.getFileSystem().supportedFileAttributeViews();
String names;
if ( views.contains( "unix" ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,8 +159,13 @@ private void addResources( List<PlexusIoResource> result, String[] resources )
{
String sourceDir = name.replace( '\\', '/' );
File f = new File( dir, sourceDir );
Path p = f.toPath();
if ( isFollowingSymLinks() )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true by default isFollowingSymLinks. I'm a bit concerned that this change would change the behavior of existing applications. I know the existing behavior is odd, but it was existing for quite some time and maybe there are applications that depend on it. Do you think adding additional flag would made sense? In general I hate fix bug kind of flags, but this code was here for quite some time and maybe there is code out there depending on PlexusIoFileResourceCollection not following symlinks by default.

{
p = p.toRealPath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think f.getCanonicalPath() would do the same without introducing Path.

Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toRealPath() requires LinkOption varargs but none are provided. When following symlinks, this will throw NoSuchFileException if the symlink target doesn't exist. Consider adding exception handling or using toRealPath(LinkOption.NOFOLLOW_LINKS) with custom symlink resolution logic to provide better error messages when symlink targets are missing.

Suggested change
p = p.toRealPath();
try {
p = p.toRealPath();
} catch (java.nio.file.NoSuchFileException e) {
throw new IOException("Symlink target does not exist for: " + p.toString(), e);
}

Copilot uses AI. Check for mistakes.
}

FileAttributes fattrs = new FileAttributes( f, cache1, cache2 );
FileAttributes fattrs = new FileAttributes( p, cache1, cache2 );
PlexusIoResourceAttributes attrs = mergeAttributes( fattrs, fattrs.isDirectory() );

String remappedName = getName( name );
Expand Down