Skip to content

Commit

Permalink
*: try to fix download racing bugs
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <[email protected]>
  • Loading branch information
xhebox committed Sep 13, 2024
1 parent c1a14a5 commit 102e225
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/cluster/operation/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Download(component, nodeOS, arch string, version string) error {
if err := repo.DownloadComponent(component, version, targetPath); err != nil {
return err
}
} else {
} else if version != "nightly" {
if err := repo.VerifyComponent(component, version, targetPath); err != nil {
os.Remove(targetPath)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,16 @@ func (r *V1Repository) updateComponentManifest(id string, withYanked bool) (*v1m
// DownloadComponent downloads the component specified by item into local file,
// the component will be removed if hash is not correct
func (r *V1Repository) DownloadComponent(item *v1manifest.VersionItem, target string) error {
targetDir := filepath.Dir(target)
err := r.mirror.Download(item.URL, targetDir)
// make a tempdir such that every download will not inference each other
targetDir, err := os.MkdirTemp(filepath.Dir(target), "download")
if err != nil {
return err
}

if err := r.mirror.Download(item.URL, targetDir); err != nil {
return err
}

// the downloaded file is named by item.URL, which maybe differ to target name
if downloaded := path.Join(targetDir, item.URL); downloaded != target {
err := os.Rename(downloaded, target)
Expand Down

0 comments on commit 102e225

Please sign in to comment.