Skip to content

Commit

Permalink
manifest: address comments from Alberto
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornplusplus authored and zhijie-yang committed Dec 3, 2024
1 parent 858524d commit 57f1de7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
16 changes: 5 additions & 11 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,17 @@ func fastValidate(options *WriteOptions) (err error) {
}
}
if entry.HardLinkID != 0 {
// TODO remove the following line after upgrading to Go 1.22 or higher.
e := entry
hardLinkGroups[e.HardLinkID] = append(hardLinkGroups[e.HardLinkID], &e)
}
}
// Entries within a hard link group must have same content.
var linkIDs []uint64
for id := range hardLinkGroups {
linkIDs = append(linkIDs, id)
}
sort.Slice(linkIDs, func(i, j int) bool {
return linkIDs[i] < linkIDs[j]
})
for i, id := range linkIDs {
if uint64(i+1) != id {
return fmt.Errorf("skipped hard link ID %d, but %d exists", i+1, id)
for id := 1; id <= len(hardLinkGroups); id++ {
entries, ok := hardLinkGroups[uint64(id)]
if !ok {
return fmt.Errorf("cannot find hard link id %d", id)
}
entries := hardLinkGroups[id]
if len(entries) == 1 {
return fmt.Errorf("hard link group %d has only one path: %s", id, entries[0].Path)
}
Expand Down
24 changes: 14 additions & 10 deletions internal/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ var readManifestTests = []struct {
{"jsonwall":"1.0","schema":"1.0","count":13}
{"kind":"content","slice":"pkg1_manifest","path":"/manifest/manifest.wall"}
{"kind":"content","slice":"pkg1_myslice","path":"/dir/file"}
{"kind":"content","slice":"pkg1_myslice","path":"/dir/file2"}
{"kind":"content","slice":"pkg1_myslice","path":"/dir/foo/bar/"}
{"kind":"content","slice":"pkg1_myslice","path":"/dir/hardlink/file"}
{"kind":"content","slice":"pkg1_myslice","path":"/dir/hardlink/file2"}
{"kind":"content","slice":"pkg1_myslice","path":"/dir/link/file"}
{"kind":"content","slice":"pkg2_myotherslice","path":"/dir/foo/bar/"}
{"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,"hard_link_id":1}
{"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/foo/bar/","mode":"01777","slices":["pkg2_myotherslice","pkg1_myslice"]}
{"kind":"path","path":"/dir/hardlink/file","mode":"0644","slices":["pkg1_myslice"],"sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","final_sha256":"8067926c032c090867013d14fb0eb21ae858344f62ad07086fd32375845c91a6","size":21,"hard_link_id":1}
{"kind":"path","path":"/dir/hardlink/file2","mode":"0644","slices":["pkg1_myslice"],"sha256":"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c","size":3,"hard_link_id":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 @@ -52,9 +54,10 @@ 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: "", HardLinkID: 1},
{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/foo/bar/", Mode: "01777", Slices: []string{"pkg2_myotherslice", "pkg1_myslice"}, SHA256: "", FinalSHA256: "", Size: 0x0, Link: ""},
{Kind: "path", Path: "/dir/hardlink/file", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", FinalSHA256: "8067926c032c090867013d14fb0eb21ae858344f62ad07086fd32375845c91a6", Size: 0x15, Link: "", HardLinkID: 1},
{Kind: "path", Path: "/dir/hardlink/file2", Mode: "0644", Slices: []string{"pkg1_myslice"}, SHA256: "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c", Size: 0x03, Link: "", HardLinkID: 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 All @@ -70,8 +73,9 @@ var readManifestTests = []struct {
Contents: []*manifest.Content{
{Kind: "content", Slice: "pkg1_manifest", Path: "/manifest/manifest.wall"},
{Kind: "content", Slice: "pkg1_myslice", Path: "/dir/file"},
{Kind: "content", Slice: "pkg1_myslice", Path: "/dir/file2"},
{Kind: "content", Slice: "pkg1_myslice", Path: "/dir/foo/bar/"},
{Kind: "content", Slice: "pkg1_myslice", Path: "/dir/hardlink/file"},
{Kind: "content", Slice: "pkg1_myslice", Path: "/dir/hardlink/file2"},
{Kind: "content", Slice: "pkg1_myslice", Path: "/dir/link/file"},
{Kind: "content", Slice: "pkg2_myotherslice", Path: "/dir/foo/bar/"},
},
Expand Down Expand Up @@ -568,7 +572,7 @@ var generateManifestTests = []struct {
},
error: `internal error: invalid manifest: path "/dir" has invalid options: size set for directory`,
}, {
summary: "Invalid path: skipped hard link ID",
summary: "Skipped hard link id",
report: &manifest.Report{
Root: "/",
Entries: map[string]manifest.ReportEntry{
Expand All @@ -579,9 +583,9 @@ var generateManifestTests = []struct {
},
},
},
error: `internal error: invalid manifest: skipped hard link ID 1, but 2 exists`,
error: `internal error: invalid manifest: cannot find hard link id 1`,
}, {
summary: "Invalid path: hard link group has only one path",
summary: "Hard link group has only one path",
report: &manifest.Report{
Root: "/",
Entries: map[string]manifest.ReportEntry{
Expand All @@ -594,7 +598,7 @@ var generateManifestTests = []struct {
},
error: `internal error: invalid manifest: hard link group 1 has only one path: /file`,
}, {
summary: "Invalid path: hard linked paths differ",
summary: "Hard linked paths differ",
report: &manifest.Report{
Root: "/",
Entries: map[string]manifest.ReportEntry{
Expand Down

0 comments on commit 57f1de7

Please sign in to comment.