From 0bd5bcd1a5c28e3c008049489abb694287157331 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 2 Aug 2016 11:19:41 +1000 Subject: [PATCH] cmd/torrentfs: Ensure unmounting occurs for some errors Restructured so other errors can be handled better too. --- cmd/torrentfs/main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/torrentfs/main.go b/cmd/torrentfs/main.go index b5fc23dc..018e3885 100644 --- a/cmd/torrentfs/main.go +++ b/cmd/torrentfs/main.go @@ -76,14 +76,18 @@ func addTestPeer(client *torrent.Client) { } func main() { + os.Exit(mainExitCode()) +} + +func mainExitCode() int { flag.Parse() if flag.NArg() != 0 { os.Stderr.WriteString("one does not simply pass positional args\n") - os.Exit(2) + return 2 } if *mountDir == "" { os.Stderr.WriteString("y u no specify mountpoint?\n") - os.Exit(2) + return 2 } log.SetFlags(log.LstdFlags | log.Lshortfile) conn, err := fuse.Mount(*mountDir) @@ -100,7 +104,8 @@ func main() { NoUpload: true, // Ensure that downloads are responsive. }) if err != nil { - log.Fatal(err) + log.Print(err) + return 1 } // This is naturally exported via GOPPROF=http. http.DefaultServeMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { @@ -108,7 +113,8 @@ func main() { }) dw, err := dirwatch.New(*torrentPath) if err != nil { - log.Fatal(err) + log.Printf("error watching torrent dir: %s", err) + return 1 } go func() { for ev := range dw.Events { @@ -154,4 +160,5 @@ func main() { if err := conn.MountError; err != nil { log.Fatal(err) } + return 0 } -- 2.48.1