Adding readonly flag

This commit is contained in:
Alex Yatskov 2015-06-23 17:55:42 +09:00
parent 2a4f274fbc
commit ea96970aa5
2 changed files with 11 additions and 8 deletions

View File

@ -70,7 +70,7 @@ func (db *database) load(dir string, index int, writable bool) error {
} }
if index >= 0 { if index >= 0 {
db.vers = db.vers[index:] db.vers = db.vers[:index]
} }
if lastVer := db.lastVersion(); lastVer != nil { if lastVer := db.lastVersion(); lastVer != nil {

17
vfs.go
View File

@ -41,6 +41,7 @@ func usage() {
func main() { func main() {
version := flag.Int("version", -1, "version index (specify -1 for latest)") version := flag.Int("version", -1, "version index (specify -1 for latest)")
readonly := flag.Bool("readonly", false, "mount filesystem as readonly")
flag.Usage = usage flag.Usage = usage
flag.Parse() flag.Parse()
@ -50,7 +51,7 @@ func main() {
} }
mount := flag.NArg() > 1 mount := flag.NArg() > 1
writable := mount && *version < 0 writable := mount && !*readonly && *version < 0
db, err := newDatabase(flag.Arg(0), *version, writable) db, err := newDatabase(flag.Arg(0), *version, writable)
if err != nil { if err != nil {
@ -58,6 +59,14 @@ func main() {
} }
if mount { if mount {
if writable {
defer func() {
if err := db.save(); err != nil {
log.Fatal(err)
}
}()
}
var options []fuse.MountOption var options []fuse.MountOption
if !writable { if !writable {
options = append(options, fuse.ReadOnly()) options = append(options, fuse.ReadOnly())
@ -78,12 +87,6 @@ func main() {
if err := conn.MountError; err != nil { if err := conn.MountError; err != nil {
log.Fatal(err) log.Fatal(err)
} }
if writable {
if err := db.save(); err != nil {
log.Fatal(err)
}
}
} else { } else {
db.dump() db.dump()
} }