GNU Tar does not tolerate with leading slashes, cut them off from hardlinks explicitly

This commit is contained in:
eleksir
2026-04-18 12:22:18 +03:00
parent 3a6a8e9644
commit 3a16bd2e08

View File

@@ -136,7 +136,8 @@ func writeFilesToTar(ctx context.Context, filepaths []string, tw *tar.Writer, cl
if inode != 0 { if inode != 0 {
if existingPath, seen := seenInodes[inode]; seen { if existingPath, seen := seenInodes[inode]; seen {
// This is a hard link to already-archived file. // This is a hard link to already-archived file.
linkTarget = existingPath // To avoid "tar: Removing leading `/' from hard link targets" message, remove leading slash.
linkTarget = strings.TrimPrefix(filepath.ToSlash(filepath.Clean(existingPath)), "/")
isHardLink = true isHardLink = true
log.Debugf("Hard link detected: %s -> %s", fpath, existingPath) log.Debugf("Hard link detected: %s -> %s", fpath, existingPath)