Example #1
0
func main() {
	c, err := fuse.Mount("/mnt")
	if err != nil {
		log.Fatal(err)
	}

	c.Serve(FS{})
}
Example #2
0
func mountslave() {
	stdout, _ := syscall.Dup(1)
	syscall.Dup2(2, 1)

	r := gob.NewDecoder(os.Stdin)
	if err := r.Decode(&z); err != nil {
		log.Fatalf("gob decode: %v", err)
	}

	fc, err := fuse.Mount(z.Mtpt)
	if err != nil {
		log.Fatal(err)
	}
	defer exec.Command("umount", z.Mtpt).Run()

	if *z.Debug {
		fuse.Debugf = log.Printf
	}

	syscall.Write(stdout, []byte("OK"))
	syscall.Close(stdout)
	fc.Serve(FS{})
}
Example #3
0
func mountslave() {
	stdout, _ := syscall.Dup(1)
	syscall.Dup2(2, 1)

	access, secret, err := keychain.UserPasswd("s3.amazonaws.com", "")
	if err != nil {
		log.Fatal(err)
	}
	auth := aws.Auth{AccessKey: access, SecretKey: secret}

	conn, err := arq.Dial(auth)
	if err != nil {
		log.Fatal(err)
	}

	comps, err := conn.Computers()
	if err != nil {
		log.Fatal(err)
	}

	fs := &fuse.Tree{}
	for _, c := range comps {
		fmt.Fprintf(os.Stderr, "scanning %s...\n", c.Name)

		// TODO: Better password protocol.
		_, pw, err := keychain.UserPasswd("arq.swtch.com", c.UUID)
		if err != nil {
			log.Fatal(err)
		}
		c.Unlock(pw)

		folders, err := c.Folders()
		if err != nil {
			log.Fatal(err)
		}

		lastDate := ""
		n := 0
		for _, f := range folders {
			if err := f.Load(); err != nil {
				log.Fatal(err)
			}
			trees, err := f.Trees()
			if err != nil {
				log.Fatal(err)
			}
			for _, t := range trees {
				y, m, d := t.Time.Date()
				date := fmt.Sprintf("%04d/%02d%02d", y, m, d)
				suffix := ""
				if date == lastDate {
					n++
					suffix = fmt.Sprintf(".%d", n)
				} else {
					n = 0
				}
				lastDate = date
				f, err := t.Root()
				if err != nil {
					log.Print(err)
				}
				// TODO: Pass times to fs.Add.
				// fmt.Fprintf(os.Stderr, "%v %s %x\n", t.Time, c.Name+"/"+date+suffix+"/"+t.Path, t.Score)
				fs.Add(c.Name+"/"+date+suffix+"/"+t.Path, &fuseNode{f})
			}
		}
	}

	fmt.Fprintf(os.Stderr, "mounting...\n")

	c, err := fuse.Mount(*mtpt)
	if err != nil {
		log.Fatal(err)
	}
	defer exec.Command("umount", *mtpt).Run()

	syscall.Write(stdout, []byte("OK"))
	syscall.Close(stdout)
	c.Serve(fs)
}