1package local 2 3import ( 4 "context" 5 "errors" 6 "fmt" 7 "os" 8 "path/filepath" 9 10 "gitlab.com/gitlab-org/gitlab-pages/internal/config" 11 "gitlab.com/gitlab-org/gitlab-pages/internal/vfs" 12) 13 14var errNotDirectory = errors.New("path needs to be a directory") 15 16type VFS struct{} 17 18func (localFs VFS) Root(ctx context.Context, path string, cacheKey string) (vfs.Root, error) { 19 rootPath, err := filepath.Abs(path) 20 if err != nil { 21 return nil, err 22 } 23 24 rootPath, err = filepath.EvalSymlinks(rootPath) 25 if err != nil { 26 return nil, fmt.Errorf("could not evaluate symlinks: %w", err) 27 } 28 29 fi, err := os.Lstat(rootPath) 30 if err != nil { 31 return nil, err 32 } 33 34 if !fi.Mode().IsDir() { 35 return nil, errNotDirectory 36 } 37 38 return &Root{rootPath: rootPath}, nil 39} 40 41func (localFs *VFS) Name() string { 42 return "local" 43} 44 45func (localFs *VFS) Reconfigure(*config.Config) error { 46 // noop 47 return nil 48} 49