change blob path, and skip duplicate blob uploads

This commit is contained in:
Mustafa Gezen 2020-12-23 14:38:46 +01:00
parent 600ba21558
commit 654c4933df
2 changed files with 16 additions and 0 deletions

View File

@ -208,6 +208,8 @@ func ProcessRPM(pd *ProcessData) {
executePatchesRpm(pd, md)
}
// already uploaded blobs are skipped
var alreadyUploadedBlobs []string
// get ignored files hash and add to .{name}.metadata
metadataFile := fmt.Sprintf(".%s.metadata", rpmFile.Name())
metadata, err := w.Filesystem.Create(metadataFile)
@ -238,8 +240,12 @@ func ProcessRPM(pd *ProcessData) {
}
path := fmt.Sprintf("%s/%s", rpmFile.Name(), checksum)
if strContains(alreadyUploadedBlobs, path) {
continue
}
pd.BlobStorage.Write(path, sourceFileBts)
log.Printf("wrote %s to blob storage", path)
alreadyUploadedBlobs = append(alreadyUploadedBlobs, path)
}
_, err = w.Add(metadataFile)

View File

@ -57,6 +57,16 @@ func ignoredContains(a []*ignoredSource, b string) bool {
return false
}
func strContains(a []string, b string) bool {
for _, val := range a {
if val == b {
return true
}
}
return false
}
// check if content and checksum matches
// returns the hash type if success else nil
func CompareHash(content []byte, checksum string) hash.Hash {