ubuntu: remove dir if clone/pull fails halfway (#79)

* ubuntu: remove dir if clone/pull fails halfway

* ubuntu: remove dir if clone/pull fails halfway (nit)

https://github.com/aquasecurity/vuln-list-update/pull/79#discussion_r592879762
This commit is contained in:
aprp 2021-03-15 11:30:12 +07:00 committed by GitHub
parent dae5f0ef64
commit e75006e8cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,12 +78,15 @@ func Update() error {
dir := filepath.Join(utils.CacheDir(), cveTrackerDir)
for _, url := range repoURLs {
_, err = gc.CloneOrPull(url, dir, "master", false)
if err != nil {
log.Printf("failed to clone or pull: %s: %v", url, err)
continue
}
if err == nil {
break
}
log.Printf("failed to clone or pull: %s: %v", url, err)
log.Printf("removing %s directory", cveTrackerDir)
if err := os.RemoveAll(dir); err != nil {
return xerrors.Errorf("failed to remove %s directory: %w", cveTrackerDir, err)
}
}
if err != nil {
return xerrors.Errorf("failed to clone or pull: %w", err)
}