From e75006e8cdbab50c754564e4fa0265a5ee07db3b Mon Sep 17 00:00:00 2001 From: aprp Date: Mon, 15 Mar 2021 11:30:12 +0700 Subject: [PATCH] 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 --- ubuntu/ubuntu.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ubuntu/ubuntu.go b/ubuntu/ubuntu.go index 5b1abe5..0c6f548 100644 --- a/ubuntu/ubuntu.go +++ b/ubuntu/ubuntu.go @@ -78,11 +78,14 @@ 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) } - break } if err != nil { return xerrors.Errorf("failed to clone or pull: %w", err)