Skip to content
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

Add workaround for macOS archive xattrs #2504

Merged
merged 4 commits into from
Oct 18, 2023
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## [Unreleased]

- No changes yet.
- Fix issue where `buf build` and other commands may fail when handling certain
archives created on macOS that contain files with extended attributes.

## [v1.27.1] - 2023-10-16

Expand Down
22 changes: 22 additions & 0 deletions private/pkg/storage/storagearchive/storagearchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"math"
"strings"

"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/storage"
Expand Down Expand Up @@ -109,6 +111,9 @@ func Untar(
if tarHeader.Size < 0 {
return fmt.Errorf("invalid size for tar file %s: %d", tarHeader.Name, tarHeader.Size)
}
if isAppleExtendedAttributesFile(tarHeader.FileInfo()) {
continue
}
path, ok, err := unmapArchivePath(tarHeader.Name, mapper, stripComponentCount)
if err != nil {
return err
Expand Down Expand Up @@ -210,6 +215,9 @@ func Unzip(
if !ok {
continue
}
if isAppleExtendedAttributesFile(zipFile.FileInfo()) {
continue
}
if zipFile.FileInfo().Mode().IsRegular() {
if err := copyZipFile(ctx, writeBucket, zipFile, path); err != nil {
return err
Expand All @@ -219,6 +227,20 @@ func Unzip(
return nil
}

func isAppleExtendedAttributesFile(fileInfo fs.FileInfo) bool {
// On macOS, .tar archives created with libarchive will contain additional
// files with a prefix of "._" if there are files with extended attributes
// and copyfile is enabled.
// Archive Utility.app has a similar behavior when creating .zip archives,
// except they are placed under a separate MACOSX directory tree.
// Here, both are handled by just ignoring all files with a "._" prefix.
// This is a reasonable compromise because files that live in a Module
// (.proto files, configuration files such as buf.yaml, README files) are
// almost never prefixed with ._, and fixing this issue in this manner
// outweighs the slight incorrectness.
return strings.HasPrefix(fileInfo.Name(), "._")
}

func copyZipFile(
ctx context.Context,
writeBucket storage.WriteBucket,
Expand Down