Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Remove deleted catalogs from disk (#84)
Browse files Browse the repository at this point in the history
Use RemoveAll

Log error
  • Loading branch information
mrajashree authored and vincent99 committed Oct 23, 2016
1 parent b0e5882 commit 7c52bf7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions manager/catalog_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"os/signal"
"path"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -148,6 +149,29 @@ func SetEnv() {

if *validate {
ValidationMode = true
} else {
//Code to delete non-embedded catalogs
setCatalogDirectories := make(map[string]bool)
for _, cat := range catalogURL {
catalog := strings.Split(cat, "=")[0]
setCatalogDirectories[catalog] = true
}
//get all subdirs under catalogRoot, if they are not part of catalogDirectories then rm -rf
clonedCatalogDirectories, _ := ioutil.ReadDir(CatalogRootDir)
log.Debugf("Removing deleted catalogs\n")
for _, dir := range clonedCatalogDirectories {
clonedCatalog := dir.Name()
if !setCatalogDirectories[clonedCatalog] {
noPurge := path.Join(CatalogRootDir, clonedCatalog, ".nopurge")
_, err := os.Stat(noPurge)
if os.IsNotExist(err) {
err = os.RemoveAll(path.Join(CatalogRootDir, clonedCatalog))
if err != nil {
log.Errorf("Error %v removing directory %s", err, clonedCatalog)
}
}
}
}
}

if *logFile != "" {
Expand Down

0 comments on commit 7c52bf7

Please sign in to comment.