Unmountpoint is Go library to wait for the detached/unmounted state of a path.
DISCLAIMER: This project is under development and fully experimental mode.
$ go get -v github.com/dwisiswant0/unmountpoint/pkg/unmount
package main
import (
"log"
"os"
"time"
"github.com/dwisiswant0/unmountpoint/pkg/unmount"
)
func main() {
p := "/media/dw1/USB-BUS1" // Mountpoint path to watch
c := make(chan bool, 1)
e := unmount.Wait(c, p)
if e != nil {
log.Fatal(e)
}
go func() {
<-c
// Unmounted!
// Do stuff e.g. rm -rf /
log.Println("Path unmounted!")
os.Exit(1)
}()
log.Printf("Wait for %s path to detach/unmounted...\n", p)
for {
time.Sleep(10 * time.Second)
}
}
Basically like signal.Notify
. If /media/dw1/USB-BUS1
directory is unmounted; Wait
assigns channel value then do some stuff (if any).
See examples.
See TODO
.
- BusKill served as my inspiration.
Unmountpoint is distributed under Apache-2.0. See LICENSE
.