fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.1 kB View raw
1package gitindex 2 3import ( 4 "fmt" 5 "log" 6 "net/url" 7 "os" 8 "path/filepath" 9 "strings" 10) 11 12// DeleteRepos deletes stale repos under a specific path in disk. The `names` 13// argument stores names of repos retrieved from the git hosting site 14// and is used along with the `filter` argument to decide on repo deletion. 15func DeleteRepos(baseDir string, urlPrefix *url.URL, names map[string]struct{}, filter *Filter) error { 16 paths, err := ListRepos(baseDir, urlPrefix) 17 if err != nil { 18 return err 19 } 20 var toDelete []string 21 for _, p := range paths { 22 _, exists := names[p] 23 repoName := strings.Replace(p, filepath.Join(urlPrefix.Host, urlPrefix.Path), "", 1) 24 repoName = strings.TrimPrefix(repoName, "/") 25 if filter.Include(repoName) && !exists { 26 toDelete = append(toDelete, p) 27 } 28 } 29 30 if len(toDelete) > 0 { 31 log.Printf("deleting repos %v", toDelete) 32 } 33 34 var errs []string 35 for _, d := range toDelete { 36 if err := os.RemoveAll(filepath.Join(baseDir, d)); err != nil { 37 errs = append(errs, err.Error()) 38 } 39 } 40 if len(errs) > 0 { 41 return fmt.Errorf("errors: %v", errs) 42 } 43 return nil 44}