ExportChanges: use POSIX / Unix conventions for Tar operations - #41
Conversation
The Change.Path field holds a local path, but it was used to set the Tar.Name field. Convert the path to a POSIX / Unix path before setting. Also explicitly convert the archive-path to a POSIX path when calling addTarFile, and explicitly strip a leading `/` (if present), instead of the first character. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
==========================================
- Coverage 66.35% 65.07% -1.28%
==========================================
Files 42 42
Lines 2027 2033 +6
==========================================
- Hits 1345 1323 -22
- Misses 497 535 +38
+ Partials 185 175 -10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| path := filepath.Join(dir, change.Path) | ||
| if err := ta.addTarFile(path, change.Path[1:]); err != nil { | ||
| log.G(context.TODO()).Debugf("Can't add file %s to tar: %s", path, err) | ||
| srcPath := filepath.Join(dir, change.Path) |
There was a problem hiding this comment.
GoDoc says;
// ExportChanges produces an Archive from the provided changes, relative to dir.So ... relative to dir, but not sure if that should also mean "outside of dir", but that's something for a follow-up.
There was a problem hiding this comment.
Moby code uses it like this, so yeah, probably expected to be within dir
parentFs, err := driver.Get(parent, "")
if err != nil {
return nil, err
}
defer driver.Put(parent)
changes, err := archive.ChangesDirs(layerFs, parentFs)
if err != nil {
return nil, err
}
tarArchive, err := archive.ExportChanges(layerFs, changes, gdw.IDMap)
if err != nil {
return nil, err
}There was a problem hiding this comment.
Pull request overview
This PR fixes tar archive path handling in ExportChanges by ensuring paths written into tar headers use POSIX (forward-slash) conventions and don’t start with an absolute /, which can be problematic for tar consumers and is especially incorrect for Windows-style paths.
Changes:
- Normalize whiteout tar header names using
filepath.ToSlashandstrings.TrimPrefix(..., "/")instead of slicing off the first byte. - Compute a POSIX
archivePathforaddTarFileto ensure hardlink bookkeeping (SeenFiles/Linkname) uses consistent forward-slash paths. - Replace ambiguous
pathvariable naming with clearersrcPathandarchivePath.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The Change.Path field holds a local path, but it was used to set the Tar.Name field.
Convert the path to a POSIX / Unix path before setting. Also explicitly convert the archive-path to a POSIX path when calling addTarFile, and explicitly strip a leading
/(if present), instead of the first character.