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

Fixed xattr reading and writing #2762

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions common/hash_data_adapter_xattr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"fmt"
"golang.org/x/sys/unix"
"path/filepath"
"strings"
)

// ===== OS-Specific hash adapter changes =====

const AzCopyHashXattrName = "user" + AzCopyHashDataStream

func (HashStorageMode) XAttr() HashStorageMode { return 11 } // It's OK if OS-specific options overlap, but we should leave some room for the agnostic options

func (e HashStorageMode) osDefault() HashStorageMode { return e.XAttr() }
Expand Down Expand Up @@ -52,7 +53,7 @@ func (a *XAttrHashDataAdapter) GetHashData(relativePath string) (*SyncHashData,

buf := make([]byte, 512) // 512 bytes should be plenty of space
retry:
sz, err := unix.Getxattr(metaFile, strings.TrimPrefix(AzCopyHashDataStream, "."), buf) // MacOS doesn't take well to the dot(?)
sz, err := unix.Getxattr(metaFile, AzCopyHashXattrName, buf) // MacOS doesn't take well to the dot(?)
if err != nil {
if err == unix.ERANGE { // But just in case, let's safeguard against it and re-call with a larger buffer.
buf = make([]byte, len(buf) * 2)
Expand Down Expand Up @@ -89,7 +90,7 @@ func (a *XAttrHashDataAdapter) SetHashData(relativePath string, data *SyncHashDa
return fmt.Errorf("failed to marshal xattr: %w", err)
}

err = unix.Setxattr(metaFile, strings.TrimPrefix(AzCopyHashDataStream, "."), buf, 0) // Default flags == create or replace
err = unix.Setxattr(metaFile, AzCopyHashXattrName, buf, 0) // Default flags == create or replace
if err != nil {
return fmt.Errorf("failed to write xattr: %w; consider utilizing an OS-agnostic hash storage mode", err)
}
Expand Down