Skip to content

Commit

Permalink
Delete all parellagram files from tmp on closing
Browse files Browse the repository at this point in the history
Add signal listener that catches the SIGINT signal, and deletes the
contents of the tmp/parellagram directory.
  • Loading branch information
aaparella committed Jun 21, 2016
1 parent d9abf1b commit d4db006
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"log"
"net/http"
"os"
"os/signal"
"path"
"strings"
"syscall"

fswatch "github.com/andreaskoch/go-fswatch"
)
Expand Down Expand Up @@ -36,6 +38,16 @@ func buildWebsitePages(conf Config) {
}

func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT)

go func() {
_ = <-sigs
log.Println("Cleaning up...")
deleteTempDirectory()
os.Exit(0)
}()

conf := getConfig()
buildWebsitePages(conf)

Expand Down
8 changes: 7 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import (
func clearTempDirectory(conf Config) {
p := path.Join(os.TempDir(), "parellagram")
clearDirContents(p)
os.Mkdir(path.Join(p, conf.Resources.Posts), os.ModeTemporary)
os.Mkdir(path.Join(p, conf.Resources.Posts), os.ModeDir|os.ModeTemporary)
}

func deleteTempDirectory() {
p := path.Join(os.TempDir(), "parellagram")
clearDirContents(p)
os.Remove(p)
}

func getDirContents(dirpath string) ([]string, error) {
Expand Down

0 comments on commit d4db006

Please sign in to comment.