Skip to content

Commit

Permalink
rename hard_link_id to inode
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Dec 17, 2024
1 parent 31d2f01 commit 78808c8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 85 deletions.
8 changes: 4 additions & 4 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Path struct {
FinalSHA256 string `json:"final_sha256,omitempty"`
Size uint64 `json:"size,omitempty"`
Link string `json:"link,omitempty"`
HardLinkID uint64 `json:"hard_link_id,omitempty"`
Inode uint64 `json:"inode,omitempty"`
}

type Content struct {
Expand Down Expand Up @@ -292,7 +292,7 @@ func manifestAddReport(dbw *jsonwall.DBWriter, report *Report) error {
FinalSHA256: entry.FinalSHA256,
Size: uint64(entry.Size),
Link: entry.Link,
HardLinkID: entry.HardLinkID,
Inode: entry.Inode,
})
if err != nil {
return err
Expand Down Expand Up @@ -345,10 +345,10 @@ func fastValidate(options *WriteOptions) (err error) {
return fmt.Errorf("path %q refers to missing slice %s", entry.Path, slice.String())
}
}
if entry.HardLinkID != 0 {
if entry.Inode != 0 {
// TODO remove the following line after upgrading to Go 1.22 or higher.
e := entry
hardLinkGroups[e.HardLinkID] = append(hardLinkGroups[e.HardLinkID], &e)
hardLinkGroups[e.Inode] = append(hardLinkGroups[e.Inode], &e)
}
}
// Entries within a hard link group must have same content.
Expand Down
52 changes: 26 additions & 26 deletions internal/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ var readManifestTests = []struct {
{"kind":"package","name":"pkg1","version":"v1","sha256":"hash1","arch":"arch1"}
{"kind":"package","name":"pkg2","version":"v2","sha256":"hash2","arch":"arch2"}
{"kind":"path","path":"/dir/file","mode":"0644","slices":["pkg1_myslice"],"sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","final_sha256":"8067926c032c090867013d14fb0eb21ae858344f62ad07086fd32375845c91a6","size":21}
{"kind":"path","path":"/dir/file2","mode":"0644","slices":["pkg1_myslice"],"sha256":"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c","size":3,"hard_link_id":1}
{"kind":"path","path":"/dir/file2","mode":"0644","slices":["pkg1_myslice"],"sha256":"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c","size":3,"inode":1}
{"kind":"path","path":"/dir/foo/bar/","mode":"01777","slices":["pkg2_myotherslice","pkg1_myslice"]}
{"kind":"path","path":"/dir/hardlink","mode":"0644","slices":["pkg1_myslice"],"sha256":"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c","size":3,"hard_link_id":1}
{"kind":"path","path":"/dir/hardlink","mode":"0644","slices":["pkg1_myslice"],"sha256":"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c","size":3,"inode":1}
{"kind":"path","path":"/dir/link/file","mode":"0644","slices":["pkg1_myslice"],"link":"/dir/file"}
{"kind":"path","path":"/manifest/manifest.wall","mode":"0644","slices":["pkg1_manifest"]}
{"kind":"slice","name":"pkg1_manifest"}
Expand All @@ -55,9 +55,9 @@ var readManifestTests = []struct {
mfest: &manifestContents{
Paths: []*manifest.Path{
{Kind: "path", Path: "/dir/file", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", FinalSHA256: "8067926c032c090867013d14fb0eb21ae858344f62ad07086fd32375845c91a6", Size: 0x15, Link: ""},
{Kind: "path", Path: "/dir/file2", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c", Size: 0x03, Link: "", HardLinkID: 0x01},
{Kind: "path", Path: "/dir/file2", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c", Size: 0x03, Link: "", Inode: 0x01},
{Kind: "path", Path: "/dir/foo/bar/", Mode: "01777", Slices: []string{"pkg2_myotherslice", "pkg1_myslice"}, SHA256: "", FinalSHA256: "", Size: 0x0, Link: ""},
{Kind: "path", Path: "/dir/hardlink", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c", Size: 0x03, Link: "", HardLinkID: 0x01},
{Kind: "path", Path: "/dir/hardlink", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c", Size: 0x03, Link: "", Inode: 0x01},
{Kind: "path", Path: "/dir/link/file", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "", FinalSHA256: "", Size: 0x0, Link: "/dir/file"},
{Kind: "path", Path: "/manifest/manifest.wall", Mode: "0644", Slices: []string{"pkg1_manifest"}, SHA256: "", FinalSHA256: "", Size: 0x0, Link: ""},
},
Expand Down Expand Up @@ -560,7 +560,7 @@ var generateManifestTests = []struct {
Size: 1234,
Slices: map[*setup.Slice]bool{slice1: true},
FinalSHA256: "final-hash",
HardLinkID: 1,
Inode: 1,
},
"/hardlink": {
Path: "/hardlink",
Expand All @@ -569,7 +569,7 @@ var generateManifestTests = []struct {
Size: 1234,
Slices: map[*setup.Slice]bool{slice1: true},
FinalSHA256: "final-hash",
HardLinkID: 1,
Inode: 1,
},
},
},
Expand All @@ -588,7 +588,7 @@ var generateManifestTests = []struct {
Size: 1234,
SHA256: "hash",
FinalSHA256: "final-hash",
HardLinkID: 1,
Inode: 1,
}, {
Kind: "path",
Path: "/hardlink",
Expand All @@ -597,7 +597,7 @@ var generateManifestTests = []struct {
Size: 1234,
SHA256: "hash",
FinalSHA256: "final-hash",
HardLinkID: 1,
Inode: 1,
}},
Packages: []*manifest.Package{{
Kind: "package",
Expand Down Expand Up @@ -626,9 +626,9 @@ var generateManifestTests = []struct {
Root: "/",
Entries: map[string]manifest.ReportEntry{
"/file": {
Path: "/file",
Slices: map[*setup.Slice]bool{slice1: true},
HardLinkID: 2,
Path: "/file",
Slices: map[*setup.Slice]bool{slice1: true},
Inode: 2,
},
},
},
Expand All @@ -639,9 +639,9 @@ var generateManifestTests = []struct {
Root: "/",
Entries: map[string]manifest.ReportEntry{
"/file": {
Path: "/file",
Slices: map[*setup.Slice]bool{slice1: true},
HardLinkID: 1,
Path: "/file",
Slices: map[*setup.Slice]bool{slice1: true},
Inode: 1,
},
},
},
Expand All @@ -652,20 +652,20 @@ var generateManifestTests = []struct {
Root: "/",
Entries: map[string]manifest.ReportEntry{
"/file": {
Path: "/file",
Mode: 0456,
SHA256: "hash",
Size: 1234,
Slices: map[*setup.Slice]bool{slice1: true},
HardLinkID: 1,
Path: "/file",
Mode: 0456,
SHA256: "hash",
Size: 1234,
Slices: map[*setup.Slice]bool{slice1: true},
Inode: 1,
},
"/hardlink": {
Path: "/hardlink",
Mode: 0456,
SHA256: "different-hash",
Size: 1234,
Slices: map[*setup.Slice]bool{slice1: true},
HardLinkID: 1,
Path: "/hardlink",
Mode: 0456,
SHA256: "different-hash",
Size: 1234,
Slices: map[*setup.Slice]bool{slice1: true},
Inode: 1,
},
},
},
Expand Down
33 changes: 17 additions & 16 deletions internal/manifest/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type ReportEntry struct {
Slices map[*setup.Slice]bool
Link string
FinalSHA256 string
// If HardLinkID is greater than 0, all entries with the same id represent hard links to the same inode.
HardLinkID uint64
// If Inode is greater than 0, all entries represent hard links to the same
// inode.
Inode uint64
}

// Report holds the information about files and directories created when slicing
Expand All @@ -29,9 +30,9 @@ type Report struct {
Root string
// Entries holds all reported content, indexed by their path.
Entries map[string]ReportEntry
// lastHardLinkID is used internally to allocate unique HardLinkID for hard
// lastInode is used internally to allocate unique Inode for hard
// links.
lastHardLinkID uint64
lastInode uint64
}

// NewReport returns an empty report for content that will be based at the
Expand All @@ -57,20 +58,20 @@ func (r *Report) Add(slice *setup.Slice, fsEntry *fsutil.Entry) error {
return fmt.Errorf("cannot add path to report: %s", err)
}

var hardLinkID uint64
var inode uint64
fsEntryCpy := *fsEntry
if fsEntry.HardLink {
relLinkPath, _ := r.sanitizeAbsPath(fsEntry.Link, false)
entry, ok := r.Entries[relLinkPath]
if !ok {
return fmt.Errorf("cannot add hard link %s to report: target %s not previously added", relPath, relLinkPath)
}
if entry.HardLinkID == 0 {
r.lastHardLinkID += 1
entry.HardLinkID = r.lastHardLinkID
if entry.Inode == 0 {
r.lastInode += 1
entry.Inode = r.lastInode
r.Entries[relLinkPath] = entry
}
hardLinkID = entry.HardLinkID
inode = entry.Inode
fsEntryCpy.SHA256 = entry.SHA256
fsEntryCpy.Size = entry.Size
fsEntryCpy.Link = entry.Link
Expand All @@ -90,13 +91,13 @@ func (r *Report) Add(slice *setup.Slice, fsEntry *fsutil.Entry) error {
r.Entries[relPath] = entry
} else {
r.Entries[relPath] = ReportEntry{
Path: relPath,
Mode: fsEntry.Mode,
SHA256: fsEntryCpy.SHA256,
Size: fsEntryCpy.Size,
Slices: map[*setup.Slice]bool{slice: true},
Link: fsEntryCpy.Link,
HardLinkID: hardLinkID,
Path: relPath,
Mode: fsEntry.Mode,
SHA256: fsEntryCpy.SHA256,
Size: fsEntryCpy.Size,
Slices: map[*setup.Slice]bool{slice: true},
Link: fsEntryCpy.Link,
Inode: inode,
}
}
return nil
Expand Down
72 changes: 36 additions & 36 deletions internal/manifest/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,20 @@ var reportTests = []struct {
{entry: sampleHardLink, 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},
HardLinkID: 1,
Path: "/example-file",
Mode: 0777,
SHA256: "example-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{oneSlice: true},
Inode: 1,
},
"/example-hard-link": {
Path: "/example-hard-link",
Mode: 0777,
SHA256: "example-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{oneSlice: true},
HardLinkID: 1,
Path: "/example-hard-link",
Mode: 0777,
SHA256: "example-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{oneSlice: true},
Inode: 1,
},
},
}, {
Expand Down Expand Up @@ -324,36 +324,36 @@ var reportTests = []struct {
}},
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},
HardLinkID: 1,
Path: "/example-file",
Mode: 0777,
SHA256: "example-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{oneSlice: true},
Inode: 1,
},
"/example-hard-link": {
Path: "/example-hard-link",
Mode: 0777,
SHA256: "example-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{oneSlice: true},
HardLinkID: 1,
Path: "/example-hard-link",
Mode: 0777,
SHA256: "example-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{oneSlice: true},
Inode: 1,
},
"/another-file": {
Path: "/another-file",
Mode: 0777,
SHA256: "another-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{otherSlice: true},
HardLinkID: 2,
Path: "/another-file",
Mode: 0777,
SHA256: "another-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{otherSlice: true},
Inode: 2,
},
"/another-hard-link": {
Path: "/another-hard-link",
Mode: 0777,
SHA256: "another-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{otherSlice: true},
HardLinkID: 2,
Path: "/another-hard-link",
Mode: 0777,
SHA256: "another-file_hash",
Size: 5678,
Slices: map[*setup.Slice]bool{otherSlice: true},
Inode: 2,
},
},
}}
Expand Down
6 changes: 3 additions & 3 deletions internal/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1910,9 +1910,9 @@ func treeDumpManifestPaths(mfest *manifest.Manifest) (map[string]string, error)
}
}

if path.HardLinkID != 0 {
// Append <hardLinkID> to the end of the path dump.
fsDump = fmt.Sprintf("%s <%d>", fsDump, path.HardLinkID)
if path.Inode != 0 {
// Append <inode> to the end of the path dump.
fsDump = fmt.Sprintf("%s <%d>", fsDump, path.Inode)
}

// append {slice1, ..., sliceN} to the end of the path dump.
Expand Down

0 comments on commit 78808c8

Please sign in to comment.