From 3cffbbf8a9dc08ea7aa95f05596b06d645790fd8 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Fri, 13 Aug 2021 13:40:26 -0400 Subject: [PATCH] add the ability to pass mount options to fusermount --- config.example.yaml | 4 ++++ fs/root.go | 10 +++++++--- main.go | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index 04b8dd2..ede3813 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -2,6 +2,10 @@ fs: # The mountpoint. Can be overwritten via the command line. #mountpoint: /mnt + # Mount options to pass to `fusermount` as its `-o` argument. Can be overwritten via the command line. + # See mount.fuse(8) for the full list of options. + #mountoptions: nodev,nosuid + gitlab: # The gitlab url. url: https://gitlab.com diff --git a/fs/root.go b/fs/root.go index 8cec0d9..9bcfc86 100644 --- a/fs/root.go +++ b/fs/root.go @@ -28,6 +28,9 @@ type FSParam struct { Git git.GitClonerPuller Gitlab gitlab.GitlabFetcher + RootGroupIds []int + UserIds []int + staticInoChan chan uint64 } @@ -70,17 +73,18 @@ func (n *rootNode) OnAdd(ctx context.Context) { fmt.Println("Mounted and ready to use") } -func Start(mountpoint string, rootGroupIds []int, userIds []int, param *FSParam, debug bool) error { +func Start(mountpoint string, mountoptions []string, param *FSParam, debug bool) error { fmt.Printf("Mounting in %v\n", mountpoint) opts := &fs.Options{} + opts.MountOptions.Options = mountoptions opts.Debug = debug param.staticInoChan = make(chan uint64) root := &rootNode{ param: param, - rootGroupIds: rootGroupIds, - userIds: userIds, + rootGroupIds: param.RootGroupIds, + userIds: param.UserIds, } go staticInoGenerator(root.param.staticInoChan) diff --git a/main.go b/main.go index 509d978..96d3359 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "path/filepath" + "strings" "github.com/badjware/gitlabfs/fs" "github.com/badjware/gitlabfs/git" @@ -20,7 +21,8 @@ type ( Git GitConfig `yaml:"git,omitempty"` } FSConfig struct { - Mountpoint string `yaml:"mountpoint,omitempty"` + Mountpoint string `yaml:"mountpoint,omitempty"` + MountOptions string `yaml:"mountoptions,omitempty"` } GitlabConfig struct { URL string `yaml:"url,omitempty"` @@ -53,7 +55,8 @@ func loadConfig(configPath string) (*Config, error) { config := &Config{ FS: FSConfig{ - Mountpoint: "", + Mountpoint: "", + MountOptions: "nodev,nosuid", }, Gitlab: GitlabConfig{ URL: "https://gitlab.com", @@ -136,8 +139,16 @@ func makeGitConfig(config *Config) (*git.GitClientParam, error) { } func main() { - configPath := flag.String("config", "", "the config file") - debug := flag.Bool("debug", false, "enable debug logging") + configPath := flag.String("config", "", "The config file") + mountoptionsFlag := flag.String("o", "", "Filesystem mount options. See mount.fuse(8)") + debug := flag.Bool("debug", false, "Enable debug logging") + + flag.Usage = func() { + fmt.Println("USAGE:") + fmt.Printf(" %s MOUNTPOINT\n\n", os.Args[0]) + fmt.Println("OPTIONS:") + flag.PrintDefaults() + } flag.Parse() config, err := loadConfig(*configPath) @@ -152,10 +163,21 @@ func main() { mountpoint = flag.Arg(0) } if mountpoint == "" { - fmt.Printf("usage: %s MOUNTPOINT\n", os.Args[0]) + fmt.Println("Mountpoint is not configured in config file and missing from command-line arguments") + flag.Usage() os.Exit(2) } + // Configure mountoptions + mountoptions := config.FS.MountOptions + if *mountoptionsFlag != "" { + mountoptions = *mountoptionsFlag + } + parsedMountoptions := make([]string, 0) + if mountoptions != "" { + parsedMountoptions = strings.Split(mountoptions, ",") + } + // Create the git client gitClientParam, err := makeGitConfig(config) if err != nil { @@ -175,9 +197,8 @@ func main() { // Start the filesystem err = fs.Start( mountpoint, - config.Gitlab.GroupIDs, - config.Gitlab.UserIDs, - &fs.FSParam{Git: gitClient, Gitlab: gitlabClient}, + parsedMountoptions, + &fs.FSParam{Git: gitClient, Gitlab: gitlabClient, RootGroupIds: config.Gitlab.GroupIDs, UserIds: config.Gitlab.UserIDs}, *debug, ) if err != nil {