Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// ConfigPath defines where the default configuration file is stored.
ConfigPath = "${HOME}/.gitfs/config.yml"
)
View Source
var StartCommand = &cobra.Command{ Use: "start", Short: "Starts the file system server.", Run: func(cmd *cobra.Command, args []string) { current, err := user.Current() if err != nil { fail("failed to determine current user") } props := ConfigPath if len(props) == 0 { fail("missing config file") } cfg, err := config.Load(os.ExpandEnv(props)) if err != nil { fail("failed to parse configuration: %v", err) } remote, err := remotes.ParseConfig(&rds.Configuration{ Accounts: cfg.Accounts, }) if err != nil { fail("failed to parse remote configuration: %v", err) } mountpoint := os.ExpandEnv(cfg.Mount) logrus.Infof("[main] configured mount point: %s", mountpoint) tree := gitfstree.NewTreeNode() logrus.Info("[main] fetching repositories") repositories, err := remote.ListRepositories() if err != nil { fail("failed to fetch repositories: %v", err) } logrus.Info("[main] parsing repositories into a directory structure") for _, repository := range repositories { url, err := urls.ParseURL(repository) if err != nil { logrus.Warnf("[main] failed to parse url: %v", err) continue } host := url.URL.Host fullPath := url.URL.Path ext := path.Ext(fullPath) fullPath = strings.TrimSuffix(fullPath, ext) fullPath = strings.TrimPrefix(fullPath, "/") parts := strings.Split(fullPath, "/") var fullPathParts []string fullPathParts = append(fullPathParts, host) fullPathParts = append(fullPathParts, parts...) tree.Insert(fullPathParts, url) } logrus.Infof("[main] attempting to mount %s", mountpoint) c, err := fuse.Mount(mountpoint) if err != nil { fail("failed to mount mountpoint: %v", err) } defer c.Close() uid, _ := strconv.Atoi(current.Uid) gid, _ := strconv.Atoi(current.Gid) cloner := urls.NewFileSystemAdapter(cfg.Clone) filesys := &filesystem.FileSystem{ UID: uint32(uid), GID: uint32(gid), Tree: tree, FSA: cloner, } logrus.Info("[main] now serving file system") if err := fs.Serve(c, filesys); err != nil { fail("failed to serve filesystem: %v", err) } <-c.Ready if err := c.MountError; err != nil { fail("file system failed to start: %v", err) } }, }
StartCommand defines the cobra.Command used to start the system.
View Source
var StopCommand = &cobra.Command{ Use: "stop", Short: "Stops the file system server.", Run: func(cmd *cobra.Command, args []string) { props := ConfigPath if len(props) == 0 { fail("missing config file") } cfg, err := config.Load(os.ExpandEnv(props)) if err != nil { fail("failed to parse configuration: %v", err) } mountpoint := os.ExpandEnv(cfg.Mount) logrus.Infof("Unmounting %s", mountpoint) _ = syscall.Unmount(mountpoint, unix.MNT_FORCE) logrus.Infof("Successfully unmounted %s", mountpoint) }, }
StopCommand defines the cobra.Command used to stop the system.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.