Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do the sha1 hash during download instead of after to reduce local I/O… #515

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions internal/component/artifactory_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,17 @@ func (ars *ArtifactoryReleaseSource) DownloadRelease(releaseDir string, remoteRe
if err != nil {
return Local{}, err
}
defer func() { _ = out.Close() }()
defer closeAndIgnoreError(out)

_, err = io.Copy(out, resp.Body)
hash := sha1.New()

mw := io.MultiWriter(out,hash)
_, err = io.Copy(mw, resp.Body)
_ = resp.Body.Close()
if err != nil {
return Local{}, err
}

_, err = out.Seek(0, 0)
if err != nil {
return Local{}, fmt.Errorf("error reseting file cursor: %w", err) // untested
}

hash := sha1.New()
_, err = io.Copy(hash, out)
if err != nil {
return Local{}, fmt.Errorf("error hashing file contents: %w", err) // untested
}

remoteRelease.SHA1 = hex.EncodeToString(hash.Sum(nil))

return Local{Lock: remoteRelease, LocalPath: filePath}, nil
Expand Down
16 changes: 4 additions & 12 deletions internal/component/bosh_io_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,15 @@ func (src BOSHIOReleaseSource) DownloadRelease(releaseDir string, remoteRelease
}
defer closeAndIgnoreError(out)

_, err = io.Copy(out, resp.Body)
hash := sha1.New()

mw := io.MultiWriter(out,hash)
_, err = io.Copy(mw, resp.Body)
_ = resp.Body.Close()
if err != nil {
return Local{}, err
}

_, err = out.Seek(0, 0)
if err != nil {
return Local{}, fmt.Errorf("error reseting file cursor: %w", err) // untested
}

hash := sha1.New()
_, err = io.Copy(hash, out)
if err != nil {
return Local{}, fmt.Errorf("error hashing file contents: %w", err) // untested
}

remoteRelease.SHA1 = hex.EncodeToString(hash.Sum(nil))

return Local{Lock: remoteRelease, LocalPath: filePath}, nil
Expand Down
Loading