summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2016-02-02 16:14:46 +0100
committerVictor Häggqvist <[email protected]>2016-02-02 16:14:46 +0100
commitc9f5236ede31edf3ff171abf241069c8bdacdd1c (patch)
tree7981ccb2395da22987128b6e7fbaf7999f2d0fc2
parentbb0ed4de616dc7c07f68ee3015ff513d9243bb09 (diff)
add gc
-rw-r--r--goboom.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/goboom.go b/goboom.go
index 166f0e9..02e788b 100644
--- a/goboom.go
+++ b/goboom.go
@@ -47,6 +47,7 @@ var (
postPhase bool
launcher bool
stats bool
+ gc bool
dbFilePath string
config Config
)
@@ -187,11 +188,30 @@ func displayStats() {
}
}
+func runGC() int {
+ items := openDB()
+
+ cleanItems := make(map[string]int)
+ removedCount := 0
+
+ for runnable, count := range items {
+ if count > 1 {
+ cleanItems[runnable] = count
+ } else {
+ removedCount = removedCount + 1
+ }
+ }
+
+ writeDB(cleanItems)
+ return removedCount
+}
+
func main() {
flag.BoolVar(&prePhase, "pre", false, "Generate dmenu in")
flag.BoolVar(&launcher, "launcher", false, "Output launcher command")
flag.BoolVar(&postPhase, "post", false, "Update ranking DB")
flag.BoolVar(&stats, "stats", false, "View you statsB")
+ flag.BoolVar(&gc, "gc", false, "Run garbage collection of the DB")
flag.Parse()
loadIni()
@@ -210,9 +230,10 @@ func main() {
fmt.Print(input)
} else if launcher {
fmt.Print("dmenu " + config.DmenuParams)
-
} else if stats {
displayStats()
+ } else if gc {
+ fmt.Printf("Removed %d items\n", runGC())
} else {
fmt.Printf("goboom v%d (%s/%s/%s)\n", version, runtime.GOOS, runtime.GOARCH, runtime.Version())
fmt.Println("\nTo actually use goboom execute goboom_run\n")