ubuntu: remove vuln-dir before update (#78)

* add ignored to ubuntu target

* add ubuntu repo url

* remove vuln-list dir before update

* scope error handling
This commit is contained in:
aprp 2021-03-11 15:23:41 +07:00 committed by GitHub
parent 1e28a8e150
commit dae5f0ef64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,11 +19,19 @@ import (
)
const (
repoURL = "https://git.launchpad.net/ubuntu-cve-tracker"
ubuntuDir = "ubuntu"
cveTrackerDir = "ubuntu-cve-tracker"
ubuntuDir = "ubuntu"
)
var (
repoURLs = []string{
"https://git.launchpad.net/ubuntu-cve-tracker",
"git://git.launchpad.net/ubuntu-cve-tracker",
}
targets = []string{
"active",
"retired",
}
statuses = []string{
"released",
"needed",
@ -65,14 +73,29 @@ type Status struct {
}
func Update() error {
var err error
gc := git.Config{}
dir := filepath.Join(utils.CacheDir(), "ubuntu-cve-tracker")
if _, err := gc.CloneOrPull(repoURL, dir, "master", false); err != nil {
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
}
break
}
if err != nil {
return xerrors.Errorf("failed to clone or pull: %w", err)
}
log.Println("Walking Ubuntu...")
for _, target := range []string{"active", "retired"} {
dst := filepath.Join(utils.VulnListDir(), ubuntuDir)
log.Printf("removing ubuntu directory %s", dst)
if err := os.RemoveAll(dst); err != nil {
return xerrors.Errorf("failed to remove ubuntu directory: %w", err)
}
log.Println("walking ubuntu-cve-tracker ...")
for _, target := range targets {
if err := walkDir(filepath.Join(dir, target)); err != nil {
return err
}