func gitfsDir(logger log_driver.Logger) (string, error) { dir, err := ioutil.TempDir("", "gitfs") if err != nil { logger.Errorf("Failed to create a temporary dir due to %s", err) return "", err } return dir, nil }
func New(config *conf.Fuse, logger log_driver.Logger) (*GitFs, error) { gitfsDir, err := gitfsDir(logger) if err != nil { return nil, err } defaultfs := pathfs.NewDefaultFileSystem() gitfs := &GitFs{FileSystem: pathfs.NewReadonlyFileSystem(defaultfs), GitRepoDir: config.GitRepoDir, GitFsDir: gitfsDir, logger: logger} fs := pathfs.NewPathNodeFs(gitfs, nil) server, _, err := nodefs.MountRoot(gitfsDir, fs.Root(), nil) if err != nil { logger.Errorf("Failed to mount GitFS on %s due to %s", gitfsDir, err) return nil, err } logger.Debugf("Mount GitFs on %s", gitfsDir) gitfs.server = server server.SetDebug(config.Debug) gitfs.cache, err = cache.New(1024) if err != nil { logger.Errorf("Failed to initialize object cache due to %s\n", err) return nil, err } return gitfs, nil }