Skip to content

Commit

Permalink
Fix hardlink issue with whiteout deletes in the merge snapshotter.
Browse files Browse the repository at this point in the history
Whiteouts may share the same inode which cause the snapshotter
to attempt to create a hardlink between two whiteouts in the destination layer.

The problem is that the first whiteout is only created if it is part of the lower layer from the base snapshot.
Otherwise, the whiteout is not created in the destination layer because it is not needed.

If the first whiteout is not created in the destination, attempting to create a hardlink for the second whiteout will fail.

To avoid this issue, this fix disables hardlinks for whiteouts.

Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
  • Loading branch information
gdlg committed Jan 2, 2024
1 parent 686c0ad commit a35951a
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit a35951a

Please sign in to comment.