Commit a32ab3d3 authored by Mustafa Gezen's avatar Mustafa Gezen
Browse files

upload to storage by checksum

parent 5576abbf
......@@ -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")
}
......
......@@ -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)
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment