diff options
author | Jesse Dunietz | 2018-10-06 15:49:33 -0400 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-10-11 20:16:45 +0200 |
commit | 87d3ed9187cb9caccaa8df0769d4cb722cc5bd00 (patch) | |
tree | 14963c3f66b1277f0bf7904650665156e102929a /cli_args.go | |
parent | 57a5a8791f8a8c957aef87aecfa4fa318873b744 (diff) |
Add option for autounmount
Even though filesystem notifications aren't implemented for FUSE, I decided to
try my hand at implementing the autounmount feature (#128). I based it on the
EncFS autounmount code, which records filesystem accesses and checks every X
seconds whether it's idled long enough to unmount.
I've tested the feature locally, but I haven't added any tests for this flag.
I also haven't worked with Go before. So please let me know if there's
anything that should be done differently.
One particular concern: I worked from the assumption that the open files table
is unique per-filesystem. If that's not true, I'll need to add an open file
count and associated lock to the Filesystem type instead.
https://github.com/rfjakob/gocryptfs/pull/265
Diffstat (limited to 'cli_args.go')
-rw-r--r-- | cli_args.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/cli_args.go b/cli_args.go index dd00658..c073958 100644 --- a/cli_args.go +++ b/cli_args.go @@ -7,6 +7,7 @@ import ( "os" "strconv" "strings" + "time" "github.com/hanwen/go-fuse/fuse" "github.com/rfjakob/gocryptfs/internal/configfile" @@ -33,6 +34,8 @@ type argContainer struct { // Configuration file name override config string notifypid, scryptn int + // Idle time before autounmount + idle time.Duration // Helper variables that are NOT cli options all start with an underscore // _configCustom is true when the user sets a custom config file name. _configCustom bool @@ -187,6 +190,11 @@ func parseCliOpts() (args argContainer) { "successful mount - used internally for daemonization") flagSet.IntVar(&args.scryptn, "scryptn", configfile.ScryptDefaultLogN, "scrypt cost parameter logN. Possible values: 10-28. "+ "A lower value speeds up mounting and reduces its memory needs, but makes the password susceptible to brute-force attacks") + + flagSet.DurationVar(&args.idle, "i", 0, "Alias for -idle") + flagSet.DurationVar(&args.idle, "idle", 0, "Auto-unmount after specified idle duration (ignored in reverse mode). "+ + "Durations are specified like \"500s\" or \"2h45m\". 0 means stay mounted indefinitely.") + var dummyString string flagSet.StringVar(&dummyString, "o", "", "For compatibility with mount(1), options can be also passed as a comma-separated list to -o on the end.") // Actual parsing @@ -247,6 +255,10 @@ func parseCliOpts() (args argContainer) { tlog.Fatal.Printf("The options -extpass and -trezor cannot be used at the same time") os.Exit(exitcodes.Usage) } + if args.idle < 0 { + tlog.Fatal.Printf("Idle timeout cannot be less than 0") + os.Exit(exitcodes.Usage) + } return args } |