diff --git a/internal/manifest/report.go b/internal/manifest/report.go index 0d30a10d..d4b73016 100644 --- a/internal/manifest/report.go +++ b/internal/manifest/report.go @@ -103,10 +103,10 @@ func (r *Report) getHardLinkId(fsEntry *fsutil.Entry) uint64 { r.Entries[relLinkPath] = entry } hardLinkId = entry.HardLinkId + fsEntry.SHA256 = entry.SHA256 + fsEntry.Size = entry.Size if fsEntry.Mode.IsRegular() { // The hard link links to a regular file - fsEntry.SHA256 = entry.SHA256 - fsEntry.Size = entry.Size fsEntry.Link = "" } else { // The hard link links to a symlink diff --git a/internal/manifest/report_test.go b/internal/manifest/report_test.go index af0373a7..37537ab2 100644 --- a/internal/manifest/report_test.go +++ b/internal/manifest/report_test.go @@ -48,6 +48,20 @@ var sampleLink = fsutil.Entry{ Link: "/base/example-file", } +var sampleHardLinkReg = fsutil.Entry{ + Path: "/base/example-hard-link-reg", + Mode: sampleFile.Mode, + Link: "/base/example-file", + LinkType: fsutil.TypeHardLink, +} + +var sampleHardLinkSym = fsutil.Entry{ + Path: "/base/example-hard-link-sym", + Mode: fs.ModeSymlink | sampleFile.Mode, + Link: "/base/example-link", + LinkType: fsutil.TypeHardLink, +} + var sampleFileMutated = fsutil.Entry{ Path: sampleFile.Path, SHA256: sampleFile.SHA256 + "_changed", @@ -267,6 +281,116 @@ var reportTests = []struct { add: []sliceAndEntry{{entry: sampleDir, slice: oneSlice}}, mutate: []*fsutil.Entry{&sampleDir}, err: `cannot mutate path in report: /example-dir/ is a directory`, +}, { + summary: "Regular file hard link", + add: []sliceAndEntry{ + {entry: sampleFile, slice: oneSlice}, + {entry: sampleHardLinkReg, slice: oneSlice}}, + expected: map[string]manifest.ReportEntry{ + "/example-file": { + Path: "/example-file", + Mode: 0777, + SHA256: "example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "", + HardLinkId: 1, + }, + "/example-hard-link-reg": { + Path: "/example-hard-link-reg", + Mode: sampleFile.Mode, + SHA256: "example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "", + HardLinkId: 1, + }}, +}, { + summary: "Symlink hard link", + add: []sliceAndEntry{ + {entry: sampleLink, slice: oneSlice}, + {entry: sampleHardLinkSym, slice: oneSlice}}, + expected: map[string]manifest.ReportEntry{ + "/example-link": { + Path: "/example-link", + Mode: fs.ModeSymlink | 0777, + SHA256: "example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "/base/example-file", + HardLinkId: 1, + }, + "/example-hard-link-sym": { + Path: "/example-hard-link-sym", + Mode: fs.ModeSymlink | 0777, + SHA256: "example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "/base/example-file", + HardLinkId: 1, + }}, +}, { + summary: "Multiple hard links", + add: []sliceAndEntry{ + {entry: sampleFile, slice: oneSlice}, + {entry: sampleHardLinkReg, slice: oneSlice}, + { + entry: fsutil.Entry{ + Path: "/base/another-example-file", + Mode: 0777, + SHA256: "another-example-file_hash", + Size: 5678, + Link: "", + }, + slice: oneSlice, + }, + { + entry: fsutil.Entry{ + Path: "/base/another-example-hard-link-reg", + Mode: sampleFile.Mode, + Link: "/base/another-example-file", + LinkType: fsutil.TypeHardLink, + }, + slice: oneSlice, + }, + }, + expected: map[string]manifest.ReportEntry{ + "/example-file": { + Path: "/example-file", + Mode: 0777, + SHA256: "example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "", + HardLinkId: 1, + }, + "/example-hard-link-reg": { + Path: "/example-hard-link-reg", + Mode: sampleFile.Mode, + SHA256: "example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "", + HardLinkId: 1, + }, + "/another-example-file": { + Path: "/another-example-file", + Mode: 0777, + SHA256: "another-example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "", + HardLinkId: 2, + }, + "/another-example-hard-link-reg": { + Path: "/another-example-hard-link-reg", + Mode: sampleFile.Mode, + SHA256: "another-example-file_hash", + Size: 5678, + Slices: map[*setup.Slice]bool{oneSlice: true}, + Link: "", + HardLinkId: 2, + }}, }} func (s *S) TestReport(c *C) {