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

Use filepath.Join when combining filesystem components #611

Merged
merged 4 commits into from
Feb 22, 2024
Merged
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
10 changes: 6 additions & 4 deletions metadata/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func (update *Updater) DownloadTarget(targetFile *metadata.TargetFiles, filePath
} else {
targetBaseURL = ensureTrailingSlash(targetBaseURL)
}

targetFilePath := targetFile.Path
targetRemotePath := targetFilePath
consistentSnapshot := update.trusted.Root.Signed.ConsistentSnapshot
if consistentSnapshot && update.cfg.PrefixTargetsWithHash {
hashes := ""
Expand All @@ -235,13 +237,13 @@ func (update *Updater) DownloadTarget(targetFile *metadata.TargetFiles, filePath
dirName, baseName, ok := strings.Cut(targetFilePath, "/")
if !ok {
// <hash>.<target-name>
targetFilePath = fmt.Sprintf("%s.%s", hashes, dirName)
targetRemotePath = fmt.Sprintf("%s.%s", hashes, dirName)
} else {
// <dir-prefix>/<hash>.<target-name>
targetFilePath = filepath.Join(dirName, fmt.Sprintf("%s.%s", hashes, baseName))
targetRemotePath = fmt.Sprintf("%s/%s.%s", dirName, hashes, baseName)
}
}
fullURL := fmt.Sprintf("%s%s", targetBaseURL, targetFilePath)
fullURL := fmt.Sprintf("%s%s", targetBaseURL, targetRemotePath)
data, err := update.cfg.Fetcher.DownloadFile(fullURL, targetFile.Length, time.Second*15)
if err != nil {
return "", nil, err
Expand Down Expand Up @@ -674,7 +676,7 @@ func (update *Updater) generateTargetFilePath(tf *metadata.TargetFiles) (string,
return "", &metadata.ErrValue{Msg: "LocalTargetsDir must be set if filepath is not given"}
}
// Use URL encoded target path as filename
return url.JoinPath(update.cfg.LocalTargetsDir, url.QueryEscape(tf.Path))
return filepath.Join(update.cfg.LocalTargetsDir, url.QueryEscape(tf.Path)), nil
}

// loadLocalMetadata reads a local <roleName>.json file and returns its bytes
Expand Down
Loading