Skip to content

Do not fail on symlinks that point to non-empty files, use default tar behavior#2

Open
m90 wants to merge 4 commits intowalle:masterfrom
m90:symlink-write
Open

Do not fail on symlinks that point to non-empty files, use default tar behavior#2
m90 wants to merge 4 commits intowalle:masterfrom
m90:symlink-write

Conversation

@m90
Copy link

@m90 m90 commented Sep 3, 2021

I'm using this package in a Docker image I maintain and an issue was raised where it seems that targz seems to fail on symlinks that point to non-empty files, failing with:

archive/tar: write too long

It seems this is due to the fact that package targz resolves symlinks to use the proper file instead, but still uses the fileInfo of the symlink itself, which means the size written to the header info does not match anymore.

As for how to fix this there are two options:

  1. Have package targz use the default behavior of the tar command which is keeping the symlink a symlink (potentially risking a broken symlink that points to something out of the bounds of the archive)
  2. Have package targz use the behavior that seems to be the one intended by the code (but isn't working), which is to resolve the symlinks and include their backing content

I opted for choosing 1 for now as it's the default of tar, but if you feel like 2 is the better fit for this package I am happy to change this as again.


As for the issue itself, you can repro this easily by checking out the first commit in this changeset which just updates the test setup to include a symlink to a non-empty file, which makes tests fail.


_, err = os.Create(filepath.Join(subDirectory, "my_file.txt"))
if err != nil {
if err := os.WriteFile(filepath.Join(subDirectory, "my_file.txt"), []byte("file contents"), 0666); err != nil {
Copy link
Author

Choose a reason for hiding this comment

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

This change is here so that the tests do not accidentally pass as all file's sizes are 0 in the previous suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant