cmd/torrentfs: Ensure unmounting occurs for some errors
Restructured so other errors can be handled better too.
This commit is contained in:
parent
6065a55818
commit
0bd5bcd1a5
|
@ -76,14 +76,18 @@ func addTestPeer(client *torrent.Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
os.Exit(mainExitCode())
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainExitCode() int {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if flag.NArg() != 0 {
|
if flag.NArg() != 0 {
|
||||||
os.Stderr.WriteString("one does not simply pass positional args\n")
|
os.Stderr.WriteString("one does not simply pass positional args\n")
|
||||||
os.Exit(2)
|
return 2
|
||||||
}
|
}
|
||||||
if *mountDir == "" {
|
if *mountDir == "" {
|
||||||
os.Stderr.WriteString("y u no specify mountpoint?\n")
|
os.Stderr.WriteString("y u no specify mountpoint?\n")
|
||||||
os.Exit(2)
|
return 2
|
||||||
}
|
}
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
conn, err := fuse.Mount(*mountDir)
|
conn, err := fuse.Mount(*mountDir)
|
||||||
|
@ -100,7 +104,8 @@ func main() {
|
||||||
NoUpload: true, // Ensure that downloads are responsive.
|
NoUpload: true, // Ensure that downloads are responsive.
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Print(err)
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
// This is naturally exported via GOPPROF=http.
|
// This is naturally exported via GOPPROF=http.
|
||||||
http.DefaultServeMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
http.DefaultServeMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -108,7 +113,8 @@ func main() {
|
||||||
})
|
})
|
||||||
dw, err := dirwatch.New(*torrentPath)
|
dw, err := dirwatch.New(*torrentPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Printf("error watching torrent dir: %s", err)
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for ev := range dw.Events {
|
for ev := range dw.Events {
|
||||||
|
@ -154,4 +160,5 @@ func main() {
|
||||||
if err := conn.MountError; err != nil {
|
if err := conn.MountError; err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue