Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions internal/backend/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package disk

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -64,24 +65,22 @@ type Backend struct {

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

// Ensure root directory exists
if err := os.MkdirAll(rootDir, dirPermissions); err != nil {
if err := os.MkdirAll(cfg.RootDir, dirPermissions); err != nil {
return nil, err
}

// Ensure locks directory exists
if err := os.MkdirAll(filepath.Join(rootDir, locksDir), dirPermissions); err != nil {
if err := os.MkdirAll(filepath.Join(cfg.RootDir, locksDir), dirPermissions); err != nil {
return nil, err
}

return &Backend{
rootDir: rootDir,
rootDir: cfg.RootDir,
logger: logger.With(zap.String("backend", "disk")),
}, nil
}
Expand Down