Skip to content

Commit db692b3

Browse files
authored
Make the root_dir for the disk backend mandatory (#3)
1 parent 98f78f5 commit db692b3

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

internal/backend/disk/disk.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package disk
33

44
import (
55
"encoding/json"
6+
"fmt"
67
"os"
78
"path/filepath"
89
"time"
@@ -64,24 +65,22 @@ type Backend struct {
6465

6566
// New creates a new disk backend instance
6667
func New(cfg config.DiskConfig, logger *zap.Logger) (*Backend, error) {
67-
rootDir := cfg.RootDir
68-
if rootDir == "" {
69-
// Default to a temp directory if not specified
70-
rootDir = filepath.Join(os.TempDir(), "variobjectstorage")
68+
if cfg.RootDir == "" {
69+
return nil, fmt.Errorf("disk backend requires root_dir to be configured")
7170
}
7271

7372
// Ensure root directory exists
74-
if err := os.MkdirAll(rootDir, dirPermissions); err != nil {
73+
if err := os.MkdirAll(cfg.RootDir, dirPermissions); err != nil {
7574
return nil, err
7675
}
7776

7877
// Ensure locks directory exists
79-
if err := os.MkdirAll(filepath.Join(rootDir, locksDir), dirPermissions); err != nil {
78+
if err := os.MkdirAll(filepath.Join(cfg.RootDir, locksDir), dirPermissions); err != nil {
8079
return nil, err
8180
}
8281

8382
return &Backend{
84-
rootDir: rootDir,
83+
rootDir: cfg.RootDir,
8584
logger: logger.With(zap.String("backend", "disk")),
8685
}, nil
8786
}

0 commit comments

Comments
 (0)