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

Pin the from/to versions in the delta filename #783

Merged
merged 4 commits into from
Sep 2, 2022
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
2 changes: 1 addition & 1 deletion swupd/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func findDeltas(c *config, oldManifest, newManifest *Manifest) ([]Delta, error)
from := nf.DeltaPeer
to := nf
dir := filepath.Join(c.outputDir, fmt.Sprint(to.Version), "delta")
name := fmt.Sprintf("%d-%d-%s-%s", from.Version, to.Version, from.Hash, to.Hash)
name := fmt.Sprintf("%d-%d-%s-%s", 10, 20, from.Hash, to.Hash)
path := filepath.Join(dir, name)

if seen[path] {
Expand Down
16 changes: 8 additions & 8 deletions swupd/packs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,19 @@ func TestCreatePackNonConsecutiveDeltas(t *testing.T) {
info = ts.createPack("contents", 20, 30, ts.path("image"))
mustHaveDeltaCount(t, info, 3)
checkFileInPack(t, ts.path("www/30/pack-contents-from-20.tar"),
fmt.Sprintf("delta/20-30-%s-%s", hashA1, hashA))
fmt.Sprintf("delta/10-20-%s-%s", hashA1, hashA))
// note that the from version is 10 since the B file did not change in 20
checkFileInPack(t, ts.path("www/30/pack-contents-from-20.tar"),
fmt.Sprintf("delta/10-30-%s-%s", hashB, hashB1))
fmt.Sprintf("delta/10-20-%s-%s", hashB, hashB1))
checkFileInPack(t, ts.path("www/30/pack-contents-from-20.tar"),
fmt.Sprintf("delta/20-30-%s-%s", hashC1, hashC2))
fmt.Sprintf("delta/10-20-%s-%s", hashC1, hashC2))

info = ts.createPack("contents", 10, 30, ts.path("image"))
mustHaveDeltaCount(t, info, 2)
checkFileInPack(t, ts.path("www/30/pack-contents-from-10.tar"),
fmt.Sprintf("delta/10-30-%s-%s", hashB, hashB1))
fmt.Sprintf("delta/10-20-%s-%s", hashB, hashB1))
checkFileInPack(t, ts.path("www/30/pack-contents-from-10.tar"),
fmt.Sprintf("delta/10-30-%s-%s", hashC, hashC2))
fmt.Sprintf("delta/10-20-%s-%s", hashC, hashC2))
}

func TestCreatePackWithDelta(t *testing.T) {
Expand Down Expand Up @@ -656,19 +656,19 @@ func TestPackRenames(t *testing.T) {
// Pack from 20->30 will contain a delta due to content change (and rename).
info = ts.createPack("os-core", 20, 30, ts.path("image"))
mustHaveDeltaCount(t, info, 1)
checkFileInPack(t, ts.path("www/30/pack-os-core-from-20.tar"), fmt.Sprintf("delta/20-30-%s-%s", hashIn20, hashIn30))
checkFileInPack(t, ts.path("www/30/pack-os-core-from-20.tar"), fmt.Sprintf("delta/10-20-%s-%s", hashIn20, hashIn30))

// Pack from 10->30 will contain a delta due to content change (and rename).
info = ts.createPack("os-core", 10, 30, ts.path("image"))
mustHaveDeltaCount(t, info, 1)
checkFileInPack(t, ts.path("www/30/pack-os-core-from-10.tar"), fmt.Sprintf("delta/10-30-%s-%s", hashIn10, hashIn30))
checkFileInPack(t, ts.path("www/30/pack-os-core-from-10.tar"), fmt.Sprintf("delta/10-20-%s-%s", hashIn10, hashIn30))

// Pack from 10->40 will contain a delta due to content change (and rename).
info = ts.createPack("os-core", 10, 40, ts.path("image"))
mustHaveDeltaCount(t, info, 1)

// Note that the delta refers to the version of the file, which is still 30.
checkFileInPack(t, ts.path("www/40/pack-os-core-from-10.tar"), fmt.Sprintf("delta/10-30-%s-%s", hashIn10, hashIn30))
checkFileInPack(t, ts.path("www/40/pack-os-core-from-10.tar"), fmt.Sprintf("delta/10-20-%s-%s", hashIn10, hashIn30))
}

// TestPackNoDeltas will test cases where there are no delta files
Expand Down