Skip to content

Conversation

@mirabilos
Copy link

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: #37

I’ve tested this in a patch against 3.2.0 which slightly differs from this patch against git master, but I believe there to be no issues.

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]>
mirabilos added a commit to qvest-digital/plexus-archiver that referenced this pull request Jan 8, 2021
default is still true here, will be false when submitting upstream

REQUIRES a version of plexus-io with the following PR merged:
codehaus-plexus/plexus-io#38

advances codehaus-plexus#160
even if I don’t know how to make this configurable from Maven
Path p = f.toPath();
if ( isFollowingSymLinks() )
{
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.

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.

@plamentotev
Copy link
Member

Adding a test case would be great if you have the time.

@mirabilos thanks for the contribution. The symbolic link handling in Plexus IO and Plexus Archiver could be improved, it is great to see contributors helping with that,

@mirabilos
Copy link
Author

mirabilos commented Apr 18, 2021 via email

@mirabilos
Copy link
Author

mirabilos commented Apr 18, 2021 via email

@mirabilos
Copy link
Author

mirabilos commented Apr 18, 2021 via email

@slachiewicz slachiewicz marked this pull request as draft December 22, 2024 21:21
@slachiewicz slachiewicz requested a review from Copilot October 26, 2025 07:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for following symbolic links when archiving files by leveraging the existing follow-symlinks flag. When enabled, the archive will contain the actual file contents that symlinks point to rather than the symbolic links themselves.

Key changes:

  • Modified file resource collection to resolve symbolic links to their real paths when the follow-symlinks flag is enabled
  • Refactored FileAttributes constructor to accept Path objects directly, enabling symlink resolution

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
PlexusIoFileResourceCollection.java Resolves symbolic links to real paths when follow-symlinks is enabled before creating file attributes
FileAttributes.java Adds new constructor accepting Path parameter to support resolved symlink paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Path p = f.toPath();
if ( isFollowingSymLinks() )
{
p = p.toRealPath();
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support following symbolic links to *files* as well

3 participants