From 24ebf95f3373a2a977e5fc9cfcbcab8749067d30 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 2 Apr 2017 19:54:11 +0200 Subject: [PATCH] local: Automatically detect layout --- src/restic/backend/local/local.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/restic/backend/local/local.go b/src/restic/backend/local/local.go index 1f536e7d9..eace14ee0 100644 --- a/src/restic/backend/local/local.go +++ b/src/restic/backend/local/local.go @@ -22,9 +22,12 @@ type Local struct { // ensure statically that *Local implements restic.Backend. var _ restic.Backend = &Local{} +const defaultLayout = "default" + // Open opens the local backend as specified by config. 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 { 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 // backend at dir. Afterwards a new config blob should be created. 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{ Config: cfg, - Layout: &backend.DefaultLayout{ - Path: cfg.Path, - Join: filepath.Join, - }, + Layout: l, } // 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 { return nil, errors.New("config file already exists") }