Skip to content

Commit

Permalink
Make hash type available when storing files
Browse files Browse the repository at this point in the history
  • Loading branch information
moio committed Feb 10, 2018
1 parent 5ff7a34 commit be666dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion get/filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *FileStorage) Checksum(filename string, hash crypto.Hash) (checksum stri
}

// StoringMapper returns a mapper that will store read data to a temporary location specified by filename
func (s *FileStorage) StoringMapper(filename string, checksum string) util.ReaderMapper {
func (s *FileStorage) StoringMapper(filename string, checksum string, hash crypto.Hash) util.ReaderMapper {
return func(reader io.ReadCloser) (result io.ReadCloser, err error) {
fullPath := path.Join(s.directory+"-in-progress", filename)
// attempt to create any missing directories in the full path
Expand Down
2 changes: 1 addition & 1 deletion get/s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (s *S3Storage) Checksum(filename string, hash crypto.Hash) (checksum string
}

// StoringMapper returns a mapper that will store read data to a temporary location specified by filename
func (s *S3Storage) StoringMapper(filename string, checksum string) (mapper util.ReaderMapper) {
func (s *S3Storage) StoringMapper(filename string, checksum string, hash crypto.Hash) (mapper util.ReaderMapper) {
return func(reader io.ReadCloser) (result io.ReadCloser, err error) {
uploader := s3manager.NewUploaderWithClient(s.svc)

Expand Down
2 changes: 1 addition & 1 deletion get/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// temporary location is moved in the "permanent" location
type Storage interface {
// StoringMapper returns a mapper that will store read data to a temporary location specified by filename
StoringMapper(filename string, checksum string) util.ReaderMapper
StoringMapper(filename string, checksum string, hash crypto.Hash) util.ReaderMapper
// Commit moves any temporary file accumulated so far to the permanent location
Commit() (err error)
// Checksum returns the checksum value of a file in the permanent location, according to the checksumType algorithm
Expand Down
12 changes: 6 additions & 6 deletions get/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r *Syncer) storeRepo() (err error) {
downloadCount := len(packagesToDownload)
log.Printf("Downloading %v packages...\n", downloadCount)
for _, pack := range packagesToDownload {
err = r.downloadStoreApply(pack.Location.Href, pack.Checksum.Checksum, util.Nop)
err = r.downloadStoreApply(pack.Location.Href, pack.Checksum.Checksum, hashMap[pack.Checksum.Type], util.Nop)
if err != nil {
return err
}
Expand All @@ -126,23 +126,23 @@ func (r *Syncer) storeRepo() (err error) {

// downloadStore downloads a repo-relative path into a file
func (r *Syncer) downloadStore(path string) error {
return r.downloadStoreApply(path, "", util.Nop)
return r.downloadStoreApply(path, "", 0, util.Nop)
}

// downloadStoreApply downloads a repo-relative path into a file, while applying a ReaderConsumer
func (r *Syncer) downloadStoreApply(path string, checksum string, f util.ReaderConsumer) error {
func (r *Syncer) downloadStoreApply(path string, checksum string, hash crypto.Hash, f util.ReaderConsumer) error {
log.Printf("Downloading %v...", path)
body, err := ReadURL(r.Url + "/" + path)
if err != nil {
return err
}
return util.Compose(r.storage.StoringMapper(path, checksum), f)(body)
return util.Compose(r.storage.StoringMapper(path, checksum, hash), f)(body)
}

// processMetadata stores the repo metadata and returns a list of package file
// paths to download
func (r *Syncer) processMetadata() (packagesToDownload []XMLPackage, packagesToRecycle []XMLPackage, err error) {
err = r.downloadStoreApply(repomdPath, "", func(reader io.ReadCloser) (err error) {
err = r.downloadStoreApply(repomdPath, "", 0, func(reader io.ReadCloser) (err error) {
decoder := xml.NewDecoder(reader)
var repomd XMLRepomd
err = decoder.Decode(&repomd)
Expand Down Expand Up @@ -195,7 +195,7 @@ func (r *Syncer) processMetadata() (packagesToDownload []XMLPackage, packagesToR
// processPrimary stores the primary XML metadata file and returns a list of
// package file paths to download
func (r *Syncer) processPrimary(path string) (packagesToDownload []XMLPackage, packagesToRecycle []XMLPackage, err error) {
err = r.downloadStoreApply(path, "", func(reader io.ReadCloser) (err error) {
err = r.downloadStoreApply(path, "", 0, func(reader io.ReadCloser) (err error) {
gzReader, err := gzip.NewReader(reader)
if err != nil {
return
Expand Down

0 comments on commit be666dc

Please sign in to comment.