-
Notifications
You must be signed in to change notification settings - Fork 34
Tracing which stabilizer is taking effect #776
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
fa61efc
56f63e2
78706d0
3c492ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"archive/zip" | ||
"bytes" | ||
"crypto/sha256" | ||
"encoding/base64" | ||
"encoding/hex" | ||
"io" | ||
"slices" | ||
|
@@ -216,14 +217,22 @@ func StabilizeZip(zr *zip.Reader, zw *zip.Writer, opts StabilizeOpts) error { | |
} | ||
mr := NewMutableReader(zr) | ||
for _, s := range opts.Stabilizers { | ||
var currentStabName string | ||
originalArchiveHash := getArchiveHash(&mr) | ||
switch s.(type) { | ||
case ZipArchiveStabilizer: | ||
currentStabName = s.(ZipArchiveStabilizer).Name | ||
s.(ZipArchiveStabilizer).Stabilize(&mr) | ||
case ZipEntryStabilizer: | ||
currentStabName = s.(ZipEntryStabilizer).Name | ||
for _, mf := range mr.File { | ||
s.(ZipEntryStabilizer).Stabilize(mf) | ||
} | ||
} | ||
newArchiveHash := getArchiveHash(&mr) | ||
if originalArchiveHash != newArchiveHash { | ||
println("Stabilizer taking effect:", currentStabName) | ||
giacomobenedetti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
return mr.WriteTo(zw) | ||
} | ||
|
@@ -252,3 +261,27 @@ func toZipCompatibleReader(r io.Reader) (io.ReaderAt, int64, error) { | |
} | ||
return bytes.NewReader(b), int64(len(b)), nil | ||
} | ||
|
||
// Helper to compute SHA256 and encode as base64 (url encoding, no padding) | ||
func computeSHA256Base64(data []byte) string { | ||
h := sha256.New() | ||
h.Write(data) | ||
sum := h.Sum(nil) | ||
return base64.RawURLEncoding.EncodeToString(sum) | ||
} | ||
|
||
func getArchiveHash(zr *MutableZipReader) string { | ||
var buf bytes.Buffer | ||
for _, zf := range zr.File { | ||
content, err := zf.Open() | ||
if err != nil { | ||
continue | ||
} | ||
data, err := io.ReadAll(content) | ||
if err != nil { | ||
continue | ||
} | ||
buf.Write(data) | ||
} | ||
return computeSHA256Base64(buf.Bytes()) | ||
} | ||
giacomobenedetti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.