Merge "cammount: enable share URL as arg (akin to -shared for camget)"

This commit is contained in:
mpl 2013-02-27 22:03:41 +00:00 committed by Gerrit Code Review
commit 2384f368f6
1 changed files with 43 additions and 16 deletions

View File

@ -22,6 +22,7 @@ import (
"log"
"os"
"os/signal"
"strings"
"syscall"
"camlistore.org/pkg/blobref"
@ -32,6 +33,12 @@ import (
"camlistore.org/third_party/code.google.com/p/rsc/fuse"
)
func usage() {
fmt.Fprint(os.Stderr, "usage: cammount [opts] <mountpoint> [<root-blobref>|<share URL>]\n")
flag.PrintDefaults()
os.Exit(2)
}
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
@ -40,36 +47,56 @@ func main() {
errorf := func(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg, args...)
os.Exit(2)
fmt.Fprint(os.Stderr, "\n")
usage()
}
if n := flag.NArg(); n < 1 || n > 2 {
errorf("usage: cammount <mountpoint> [<root-blobref>]\n")
nargs := flag.NArg()
if nargs < 1 || nargs > 2 {
usage()
}
mountPoint := flag.Arg(0)
var (
cl *client.Client
root *blobref.BlobRef // nil if only one arg
camfs *fs.CamliFileSystem
)
if nargs == 2 {
rootArg := flag.Arg(1)
// not trying very hard since NewFromShareRoot will do it better with a regex
if strings.HasPrefix(rootArg, "http://") ||
strings.HasPrefix(rootArg, "https://") {
if client.ExplicitServer() != "" {
errorf("Can't use an explicit blobserver with a share URL; the blobserver is implicit from the share URL.")
}
var err error
cl, root, err = client.NewFromShareRoot(rootArg)
if err != nil {
log.Fatal(err)
}
} else {
cl = client.NewOrFail() // automatic from flags
root = blobref.Parse(rootArg)
if root == nil {
log.Fatalf("Error parsing root blobref: %q\n", rootArg)
}
}
}
client := client.NewOrFail() // automatic from flags
diskCacheFetcher, err := cacher.NewDiskCache(client)
diskCacheFetcher, err := cacher.NewDiskCache(cl)
if err != nil {
errorf("Error setting up local disk cache: %v", err)
log.Fatalf("Error setting up local disk cache: %v", err)
}
defer diskCacheFetcher.Clean()
var camfs *fs.CamliFileSystem
if flag.NArg() == 2 {
root := blobref.Parse(flag.Arg(1))
if root == nil {
errorf("Error parsing root blobref: %q\n", root)
}
if root != nil {
var err error
camfs, err = fs.NewRootedCamliFileSystem(diskCacheFetcher, root)
if err != nil {
errorf("Error creating root with %v: %v", root, err)
log.Fatalf("Error creating root with %v: %v", root, err)
}
} else {
camfs = fs.NewCamliFileSystem(client, diskCacheFetcher)
camfs = fs.NewCamliFileSystem(cl, diskCacheFetcher)
log.Printf("starting with fs %#v", camfs)
}