NewLocal validates Root and returns a Local backend. Root must exist and be a directory; the backend never creates Root automatically because doing so masks misconfigured deployments (e.g. a stale directory inside a container).
(conf LocalConfig)
| 32 | // because doing so masks misconfigured deployments (e.g. a stale |
| 33 | // directory inside a container). |
| 34 | func NewLocal(conf LocalConfig) (*Local, error) { |
| 35 | if conf.Root == "" { |
| 36 | return nil, errors.New("fstable/local: root directory is required") |
| 37 | } |
| 38 | abs, err := filepath.Abs(conf.Root) |
| 39 | if err != nil { |
| 40 | return nil, fmt.Errorf("fstable/local: resolve root: %w", err) |
| 41 | } |
| 42 | info, err := os.Stat(abs) |
| 43 | if err != nil { |
| 44 | return nil, fmt.Errorf("fstable/local: stat root %q: %w", abs, err) |
| 45 | } |
| 46 | if !info.IsDir() { |
| 47 | return nil, fmt.Errorf("fstable/local: root %q is not a directory", abs) |
| 48 | } |
| 49 | return &Local{root: abs}, nil |
| 50 | } |
| 51 | |
| 52 | func (l *Local) Name() string { return "local" } |
| 53 |