Skip to content

fix: Resolve symlinks being written with size 0 in tar #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2022
Merged
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
11 changes: 9 additions & 2 deletions provisionersdk/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ func Tar(directory string, limit int64) ([]byte, error) {
if err != nil {
return err
}
header, err := tar.FileInfoHeader(fileInfo, file)
var link string
if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
link, err = os.Readlink(file)
if err != nil {
return err
}
}
header, err := tar.FileInfoHeader(fileInfo, link)
Comment on lines +28 to +35
Copy link
Contributor

@coadler coadler May 16, 2022

Choose a reason for hiding this comment

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

This is a bit confusing. It seems like this only works for symlinks, since we're no longer using the file var if it's not.

Copy link
Member Author

Choose a reason for hiding this comment

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

The second arg is actually only a link. It was implemented incorrectly beforehand.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it should be empty if the file isn't a symlink?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe so

if err != nil {
return err
}
Expand All @@ -45,7 +52,7 @@ func Tar(directory string, limit int64) ([]byte, error) {
if err := tarWriter.WriteHeader(header); err != nil {
return err
}
if fileInfo.IsDir() {
if !fileInfo.Mode().IsRegular() {
return nil
}
data, err := os.Open(file)
Expand Down