Skip to content

Commit

Permalink
sets uri sha as the downloaded artifact filename and removes checks f…
Browse files Browse the repository at this point in the history
…or http(s) uri

Signed-off-by: Amit Singh <[email protected]>
  • Loading branch information
semmet95 authored and anthonydahanne committed Sep 14, 2023
1 parent ff207df commit 59a6098
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions dependency_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func (d *DependencyCache) Artifact(dependency BuildpackDependency, mods ...Reque
actual BuildpackDependency
artifact string
file string
hasher = sha256.New()
uri = dependency.URI
uriSha string
)

for d, u := range d.Mappings {
Expand All @@ -177,26 +179,17 @@ func (d *DependencyCache) Artifact(dependency BuildpackDependency, mods ...Reque
}
}

// downloaded artifact will have the uri sha as its filename
hasher.Write([]byte(uri))
uriSha = hex.EncodeToString(hasher.Sum(nil))

if dependency.SHA256 == "" {
d.Logger.Headerf("%s Dependency has no SHA256. Skipping cache.",
color.New(color.FgYellow, color.Bold).Sprint("Warning:"))

d.Logger.Bodyf("%s from %s", color.YellowString("Downloading"), uri)

// ensure query parameters are not included in the downloaded file name if the uri is http type
downloadUri, err := url.Parse(uri)
if err != nil {
return nil, fmt.Errorf("unable to parse the download uri %s\n%w", uri, err)
}

if(downloadUri.Scheme == "http" || downloadUri.Scheme == "https") {
hasher := sha256.New()
hasher.Write([]byte(uri))

artifact = filepath.Join(d.DownloadPath, hex.EncodeToString(hasher.Sum(nil)))
} else {
artifact = filepath.Join(d.DownloadPath, filepath.Base(uri))
}
artifact = filepath.Join(d.DownloadPath, uriSha)

if err := d.download(uri, artifact, mods...); err != nil {
return nil, fmt.Errorf("unable to download %s\n%w", uri, err)
Expand Down Expand Up @@ -234,7 +227,7 @@ func (d *DependencyCache) Artifact(dependency BuildpackDependency, mods ...Reque
}

d.Logger.Bodyf("%s from %s", color.YellowString("Downloading"), uri)
artifact = filepath.Join(d.DownloadPath, dependency.SHA256, filepath.Base(uri))
artifact = filepath.Join(d.DownloadPath, dependency.SHA256, uriSha)
if err := d.download(uri, artifact, mods...); err != nil {
return nil, fmt.Errorf("unable to download %s\n%w", uri, err)
}
Expand Down

0 comments on commit 59a6098

Please sign in to comment.