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

Fix hardlink issue with whiteout deletes in the merge snapshotter. #4516

Merged
merged 1 commit into from
Jan 3, 2024
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
27 changes: 27 additions & 0 deletions client/mergediff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,33 @@ func diffOpTestCases() (tests []integration.Test) {
),
})

// Check that deleting together a file from the base and another one from a merge
// does not result in a crash.
deleteFileAfterMergeCmds := []string{
"rm /unmodifiedDir/deleteFile1 /unmodifiedDir/deleteFile2",
}

extraContent := llb.Scratch().
File(llb.Mkdir("/unmodifiedDir", 0755)).
File(llb.Mkfile("/unmodifiedDir/deleteFile2", 0644, []byte("foo")))

tests = append(tests, verifyContents{
name: "TestDiffDeleteFilesAfterMerge",
state: llb.Diff(
base(),
runShell(llb.Merge([]llb.State{
base(),
extraContent,
}),
joinCmds(
deleteFileAfterMergeCmds,
)...)),
contents: mergeContents(
apply(
fstest.CreateDir("/unmodifiedDir", 0755)),
),
})

// Opaque dirs should be converted to the "explicit whiteout" format, as described in the OCI image spec:
// https://github.com/opencontainers/image-spec/blob/main/layer.md#opaque-whiteout
opaqueDirCmds := []string{
Expand Down
5 changes: 4 additions & 1 deletion snapshot/diffapply_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,10 @@ func (d *differ) overlayChanges(ctx context.Context, handle func(context.Context
return errors.Errorf("unhandled stat type for %+v", srcfi)
}

if !srcfi.IsDir() && c.srcStat.Nlink > 1 {
// Changes with Delete kind may share the same inode even if they are unrelated.
// Skip them to avoid creating hardlinks between whiteouts as whiteouts are not
// always created and may leave the hardlink dangling.
if !srcfi.IsDir() && c.srcStat.Nlink > 1 && c.kind != fs.ChangeKindDelete {
if linkSubPath, ok := d.inodes[statInode(c.srcStat)]; ok {
c.linkSubPath = linkSubPath
} else {
Expand Down