github.com/hanwen/go-fuse@v1.0.0/example/unionfs/main.go (about)

     1  // Copyright 2016 the Go-FUSE Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"flag"
     9  	"fmt"
    10  	"log"
    11  	"os"
    12  	"time"
    13  
    14  	"github.com/hanwen/go-fuse/fuse/nodefs"
    15  	"github.com/hanwen/go-fuse/fuse/pathfs"
    16  	"github.com/hanwen/go-fuse/unionfs"
    17  )
    18  
    19  func main() {
    20  	debug := flag.Bool("debug", false, "debug on")
    21  	portable := flag.Bool("portable", false, "use 32 bit inodes")
    22  
    23  	entry_ttl := flag.Float64("entry_ttl", 1.0, "fuse entry cache TTL.")
    24  	negative_ttl := flag.Float64("negative_ttl", 1.0, "fuse negative entry cache TTL.")
    25  
    26  	delcache_ttl := flag.Float64("deletion_cache_ttl", 5.0, "Deletion cache TTL in seconds.")
    27  	branchcache_ttl := flag.Float64("branchcache_ttl", 5.0, "Branch cache TTL in seconds.")
    28  	deldirname := flag.String(
    29  		"deletion_dirname", "GOUNIONFS_DELETIONS", "Directory name to use for deletions.")
    30  
    31  	flag.Parse()
    32  	if len(flag.Args()) < 2 {
    33  		fmt.Println("Usage:\n  unionfs MOUNTPOINT RW-DIRECTORY RO-DIRECTORY ...")
    34  		os.Exit(2)
    35  	}
    36  
    37  	ufsOptions := unionfs.UnionFsOptions{
    38  		DeletionCacheTTL: time.Duration(*delcache_ttl * float64(time.Second)),
    39  		BranchCacheTTL:   time.Duration(*branchcache_ttl * float64(time.Second)),
    40  		DeletionDirName:  *deldirname,
    41  	}
    42  
    43  	ufs, err := unionfs.NewUnionFsFromRoots(flag.Args()[1:], &ufsOptions, true)
    44  	if err != nil {
    45  		log.Fatal("Cannot create UnionFs", err)
    46  		os.Exit(1)
    47  	}
    48  	nodeFs := pathfs.NewPathNodeFs(ufs, &pathfs.PathNodeFsOptions{ClientInodes: true})
    49  	mOpts := nodefs.Options{
    50  		EntryTimeout:    time.Duration(*entry_ttl * float64(time.Second)),
    51  		AttrTimeout:     time.Duration(*entry_ttl * float64(time.Second)),
    52  		NegativeTimeout: time.Duration(*negative_ttl * float64(time.Second)),
    53  		PortableInodes:  *portable,
    54  		Debug:           *debug,
    55  	}
    56  	mountState, _, err := nodefs.MountRoot(flag.Arg(0), nodeFs.Root(), &mOpts)
    57  	if err != nil {
    58  		log.Fatal("Mount fail:", err)
    59  	}
    60  
    61  	mountState.Serve()
    62  }