From a32ab3d34fb1f7902de761db0c6668dec0361f2e Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Sun, 20 Dec 2020 18:38:25 +0100 Subject: [PATCH] upload to storage by checksum --- internal/git.go | 2 +- internal/process.go | 12 ++++++------ internal/utils.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/git.go b/internal/git.go index 70a40c4..8f2739a 100644 --- a/internal/git.go +++ b/internal/git.go @@ -147,7 +147,7 @@ func (g *GitMode) WriteSource(md *modeData) { log.Fatalf("could not open file pointer: %v", err) } - hasher := compareHash(body, hash) + hasher := CompareHash(body, hash) if hasher == nil { log.Fatal("checksum in metadata does not match dist-git file") } diff --git a/internal/process.go b/internal/process.go index 068ec1e..60e9155 100644 --- a/internal/process.go +++ b/internal/process.go @@ -154,21 +154,21 @@ func ProcessRPM(pd *ProcessData) { log.Fatalf("could not read the whole of ignored source file: %v", err) } - path := fmt.Sprintf("%s-%s/%s", rpmFile.Name(), md.pushBranch, source.name) - pd.BlobStorage.Write(path, sourceFileBts) - log.Printf("wrote %s to blob storage", path) - source.hashFunction.Reset() _, err = source.hashFunction.Write(sourceFileBts) if err != nil { log.Fatalf("could not write bytes to hash function: %v", err) } - checksum := source.hashFunction.Sum(nil) - checksumLine := fmt.Sprintf("%s %s\n", hex.EncodeToString(checksum), sourcePath) + checksum := hex.EncodeToString(source.hashFunction.Sum(nil)) + checksumLine := fmt.Sprintf("%s %s\n", checksum, sourcePath) _, err = metadata.Write([]byte(checksumLine)) if err != nil { log.Fatalf("could not write to metadata file: %v", err) } + + path := fmt.Sprintf("%s-%s/%s", rpmFile.Name(), md.pushBranch, checksum) + pd.BlobStorage.Write(path, sourceFileBts) + log.Printf("wrote %s to blob storage", path) } _, err = w.Add(metadataFile) diff --git a/internal/utils.go b/internal/utils.go index 16f6b39..566a94f 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -59,7 +59,7 @@ func ignoredContains(a []*ignoredSource, b string) bool { // check if content and checksum matches // returns the hash type if success else nil -func compareHash(content []byte, checksum string) hash.Hash { +func CompareHash(content []byte, checksum string) hash.Hash { var hashType hash.Hash switch len(checksum) {