From 9b8009cfaf6707d23a20494cd5467aed9c98513b Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Wed, 17 Jun 2020 19:40:24 +0200 Subject: [feat] cleanup temp dirs on quit --- pkg/backend/actions.go | 21 +++++++++++++++++++++ pkg/backend/api.go | 10 ++++------ pkg/backend/cleanup.go | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 pkg/backend/actions.go create mode 100644 pkg/backend/cleanup.go (limited to 'pkg') diff --git a/pkg/backend/actions.go b/pkg/backend/actions.go new file mode 100644 index 0000000..725a550 --- /dev/null +++ b/pkg/backend/actions.go @@ -0,0 +1,21 @@ +package backend + +import ( + "log" + "os" +) + +func startVPN() { + err := ctx.bm.StartVPN(ctx.Provider) + if err != nil { + log.Println(err) + os.Exit(1) + } +} + +func stopVPN() { + err := ctx.bm.StopVPN() + if err != nil { + log.Println(err) + } +} diff --git a/pkg/backend/api.go b/pkg/backend/api.go index 5cb0304..74220ed 100644 --- a/pkg/backend/api.go +++ b/pkg/backend/api.go @@ -1,4 +1,4 @@ -/* All the exported functions live here */ +/* All the exported functions should be added here */ package backend @@ -24,7 +24,7 @@ func SwitchOff() { } func Unblock() { - //TODO + //TODO - fmt.Println("unblock... [not implemented]") } @@ -34,6 +34,7 @@ func Quit() { ctx.cfg.SetUserStoppedVPN(true) stopVPN() } + cleanupTempDirs() } func DonateAccepted() { @@ -51,10 +52,7 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { func InitializeBitmaskContext() { p := bitmask.GetConfiguredProvider() - initOnce.Do(func() { - initializeContext( - p.Provider, p.AppName) - }) + initOnce.Do(func() { initializeContext(p.Provider, p.AppName) }) go ctx.updateStatus() go func() { diff --git a/pkg/backend/cleanup.go b/pkg/backend/cleanup.go new file mode 100644 index 0000000..77c55e6 --- /dev/null +++ b/pkg/backend/cleanup.go @@ -0,0 +1,16 @@ +package backend + +import ( + "log" + "os" + "path" + "path/filepath" +) + +func cleanupTempDirs() { + dirs, _ := filepath.Glob(path.Join(os.TempDir(), "leap-*")) + for _, d := range dirs { + log.Println("removing temp dir:", d) + os.RemoveAll(d) + } +} -- cgit v1.2.3