1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-24 08:44:52 +00:00

local: Automatically detect layout

This commit is contained in:
Alexander Neumann 2017-04-02 19:54:11 +02:00
parent 54465c92cc
commit 24ebf95f33

View file

@ -22,9 +22,12 @@ type Local struct {
// ensure statically that *Local implements restic.Backend. // ensure statically that *Local implements restic.Backend.
var _ restic.Backend = &Local{} var _ restic.Backend = &Local{}
const defaultLayout = "default"
// Open opens the local backend as specified by config. // Open opens the local backend as specified by config.
func Open(cfg Config) (*Local, error) { func Open(cfg Config) (*Local, error) {
l, err := backend.ParseLayout(nil, cfg.Layout, cfg.Path) debug.Log("open local backend at %v (layout %q)", cfg.Path, cfg.Layout)
l, err := backend.ParseLayout(&backend.LocalFilesystem{}, cfg.Layout, defaultLayout, cfg.Path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -44,16 +47,20 @@ func Open(cfg Config) (*Local, error) {
// Create creates all the necessary files and directories for a new local // Create creates all the necessary files and directories for a new local
// backend at dir. Afterwards a new config blob should be created. // backend at dir. Afterwards a new config blob should be created.
func Create(cfg Config) (*Local, error) { func Create(cfg Config) (*Local, error) {
debug.Log("create local backend at %v (layout %q)", cfg.Path, cfg.Layout)
l, err := backend.ParseLayout(&backend.LocalFilesystem{}, cfg.Layout, defaultLayout, cfg.Path)
if err != nil {
return nil, err
}
be := &Local{ be := &Local{
Config: cfg, Config: cfg,
Layout: &backend.DefaultLayout{ Layout: l,
Path: cfg.Path,
Join: filepath.Join,
},
} }
// test if config file already exists // test if config file already exists
_, err := fs.Lstat(be.Filename(restic.Handle{Type: restic.ConfigFile})) _, err = fs.Lstat(be.Filename(restic.Handle{Type: restic.ConfigFile}))
if err == nil { if err == nil {
return nil, errors.New("config file already exists") return nil, errors.New("config file already exists")
} }