upload to storage by checksum

This commit is contained in:
Mustafa Gezen 2020-12-20 18:38:25 +01:00
parent 5576abbffc
commit a32ab3d34f
3 changed files with 8 additions and 8 deletions

View File

@ -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")
}

View File

@ -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)

View File

@ -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) {