Files
rest-server/context.go
Chapuis Bertil b4d923ab26 small refactoring
2015-09-06 17:44:42 +02:00

27 lines
536 B
Go

package main
import (
"os"
"path/filepath"
"github.com/restic/restic/backend"
)
// A Context specifies the root directory where all repositories are stored
type Context struct {
path string
}
func NewContext(path string) Context {
path = filepath.Clean(path)
if _, err := os.Stat(path); err != nil {
os.MkdirAll(path, backend.Modes.Dir)
}
return Context{path}
}
func (c *Context) Repository(name string) (Repository, error) {
name, err := ParseRepositoryName(name)
return Repository{filepath.Join(c.path, name)}, err
}