2015-03-28 11:50:23 +01:00
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-08-31 22:39:36 +02:00
|
|
|
"restic"
|
2015-03-28 11:50:23 +01:00
|
|
|
|
2016-09-01 22:17:37 +02:00
|
|
|
"restic/errors"
|
2016-08-21 17:46:23 +02:00
|
|
|
|
2016-02-14 15:29:28 +01:00
|
|
|
"restic/backend"
|
|
|
|
"restic/debug"
|
2016-03-28 15:24:18 +02:00
|
|
|
"restic/fs"
|
2015-03-28 11:50:23 +01:00
|
|
|
)
|
|
|
|
|
2016-01-24 20:23:50 +01:00
|
|
|
// Local is a backend in a local directory.
|
2015-03-28 11:50:23 +01:00
|
|
|
type Local struct {
|
2017-03-25 13:20:03 +01:00
|
|
|
Config
|
2017-03-26 21:53:26 +02:00
|
|
|
backend.Layout
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 22:14:00 +02:00
|
|
|
// ensure statically that *Local implements restic.Backend.
|
2016-08-31 22:39:36 +02:00
|
|
|
var _ restic.Backend = &Local{}
|
|
|
|
|
2016-01-26 22:09:29 +01:00
|
|
|
// Open opens the local backend as specified by config.
|
2017-03-25 13:20:03 +01:00
|
|
|
func Open(cfg Config) (*Local, error) {
|
2017-03-26 21:53:26 +02:00
|
|
|
be := &Local{Config: cfg}
|
|
|
|
|
|
|
|
be.Layout = &backend.DefaultLayout{
|
|
|
|
Path: cfg.Path,
|
|
|
|
Join: filepath.Join,
|
|
|
|
}
|
|
|
|
|
2015-05-03 16:43:27 +02:00
|
|
|
// test if all necessary dirs are there
|
2017-03-26 21:53:26 +02:00
|
|
|
for _, d := range be.Paths() {
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
if _, err := fs.Stat(d); err != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return nil, errors.Wrap(err, "Open")
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
return be, nil
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create creates all the necessary files and directories for a new local
|
2015-05-04 20:39:45 +02:00
|
|
|
// backend at dir. Afterwards a new config blob should be created.
|
2017-03-25 13:20:03 +01:00
|
|
|
func Create(cfg Config) (*Local, error) {
|
2017-03-26 21:53:26 +02:00
|
|
|
be := &Local{
|
|
|
|
Config: cfg,
|
|
|
|
Layout: &backend.DefaultLayout{
|
|
|
|
Path: cfg.Path,
|
|
|
|
Join: filepath.Join,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-05-04 20:39:45 +02:00
|
|
|
// test if config file already exists
|
2017-03-26 21:53:26 +02:00
|
|
|
_, err := fs.Lstat(be.Filename(restic.Handle{Type: restic.ConfigFile}))
|
2015-03-28 11:50:23 +01:00
|
|
|
if err == nil {
|
2015-05-03 16:43:27 +02:00
|
|
|
return nil, errors.New("config file already exists")
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// create paths for data, refs and temp
|
2017-03-26 21:53:26 +02:00
|
|
|
for _, d := range be.Paths() {
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
err := fs.MkdirAll(d, backend.Modes.Dir)
|
2015-03-28 11:50:23 +01:00
|
|
|
if err != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return nil, errors.Wrap(err, "MkdirAll")
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
return be, nil
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Location returns this backend's location (the directory name).
|
|
|
|
func (b *Local) Location() string {
|
2017-03-25 13:20:03 +01:00
|
|
|
return b.Path
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2016-01-26 22:12:53 +01:00
|
|
|
// Save stores data in the backend at the handle.
|
2017-01-22 12:32:20 +01:00
|
|
|
func (b *Local) Save(h restic.Handle, rd io.Reader) (err error) {
|
|
|
|
debug.Log("Save %v", h)
|
2016-01-26 22:12:53 +01:00
|
|
|
if err := h.Valid(); err != nil {
|
2016-01-24 16:59:38 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
filename := b.Filename(h)
|
2016-01-24 16:59:38 +01:00
|
|
|
|
2016-01-24 21:13:24 +01:00
|
|
|
// create directories if necessary, ignore errors
|
2016-09-01 21:19:30 +02:00
|
|
|
if h.Type == restic.DataFile {
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
err = fs.MkdirAll(filepath.Dir(filename), backend.Modes.Dir)
|
2016-01-24 21:13:24 +01:00
|
|
|
if err != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return errors.Wrap(err, "MkdirAll")
|
2016-01-24 21:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
// create new file
|
|
|
|
f, err := fs.OpenFile(filename, os.O_CREATE|os.O_EXCL|os.O_WRONLY, backend.Modes.File)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "OpenFile")
|
|
|
|
}
|
|
|
|
|
|
|
|
// save data, then sync
|
|
|
|
_, err = io.Copy(f, rd)
|
|
|
|
if err != nil {
|
|
|
|
f.Close()
|
|
|
|
return errors.Wrap(err, "Write")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = f.Sync(); err != nil {
|
|
|
|
f.Close()
|
|
|
|
return errors.Wrap(err, "Sync")
|
|
|
|
}
|
2016-01-24 16:59:38 +01:00
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
err = f.Close()
|
2016-01-24 16:59:38 +01:00
|
|
|
if err != nil {
|
2017-03-26 21:53:26 +02:00
|
|
|
f.Close()
|
|
|
|
return errors.Wrap(err, "Close")
|
2016-01-24 16:59:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// set mode to read-only
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
fi, err := fs.Stat(filename)
|
2016-01-24 16:59:38 +01:00
|
|
|
if err != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return errors.Wrap(err, "Stat")
|
2016-01-24 16:59:38 +01:00
|
|
|
}
|
|
|
|
|
2016-01-26 22:12:53 +01:00
|
|
|
return setNewFileMode(filename, fi)
|
2016-01-24 01:15:35 +01:00
|
|
|
}
|
|
|
|
|
2017-01-23 18:11:10 +01:00
|
|
|
// Load returns a reader that yields the contents of the file at h at the
|
2017-01-22 22:01:12 +01:00
|
|
|
// given offset. If length is nonzero, only a portion of the file is
|
|
|
|
// returned. rd must be closed after use.
|
2017-01-23 18:11:10 +01:00
|
|
|
func (b *Local) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
|
|
|
debug.Log("Load %v, length %v, offset %v", h, length, offset)
|
2017-01-22 22:01:12 +01:00
|
|
|
if err := h.Valid(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if offset < 0 {
|
|
|
|
return nil, errors.New("offset is negative")
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
f, err := fs.Open(b.Filename(h))
|
2017-01-22 22:01:12 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if offset > 0 {
|
|
|
|
_, err = f.Seek(offset, 0)
|
|
|
|
if err != nil {
|
|
|
|
f.Close()
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if length > 0 {
|
|
|
|
return backend.LimitReadCloser(f, int64(length)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
2016-01-23 23:27:58 +01:00
|
|
|
// Stat returns information about a blob.
|
2016-08-31 22:39:36 +02:00
|
|
|
func (b *Local) Stat(h restic.Handle) (restic.FileInfo, error) {
|
2016-09-27 22:35:08 +02:00
|
|
|
debug.Log("Stat %v", h)
|
2016-01-23 23:27:58 +01:00
|
|
|
if err := h.Valid(); err != nil {
|
2016-08-31 22:39:36 +02:00
|
|
|
return restic.FileInfo{}, err
|
2016-01-23 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
fi, err := fs.Stat(b.Filename(h))
|
2016-01-23 23:27:58 +01:00
|
|
|
if err != nil {
|
2016-08-31 22:39:36 +02:00
|
|
|
return restic.FileInfo{}, errors.Wrap(err, "Stat")
|
2016-01-23 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2016-08-31 22:39:36 +02:00
|
|
|
return restic.FileInfo{Size: fi.Size()}, nil
|
2016-01-23 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2015-03-28 11:50:23 +01:00
|
|
|
// Test returns true if a blob of the given type and name exists in the backend.
|
2017-01-25 17:48:35 +01:00
|
|
|
func (b *Local) Test(h restic.Handle) (bool, error) {
|
|
|
|
debug.Log("Test %v", h)
|
2017-03-26 21:53:26 +02:00
|
|
|
_, err := fs.Stat(b.Filename(h))
|
2015-03-28 11:50:23 +01:00
|
|
|
if err != nil {
|
2016-08-29 19:18:57 +02:00
|
|
|
if os.IsNotExist(errors.Cause(err)) {
|
2015-03-28 11:50:23 +01:00
|
|
|
return false, nil
|
|
|
|
}
|
2016-08-29 21:54:50 +02:00
|
|
|
return false, errors.Wrap(err, "Stat")
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove removes the blob with the given name and type.
|
2017-01-25 17:48:35 +01:00
|
|
|
func (b *Local) Remove(h restic.Handle) error {
|
|
|
|
debug.Log("Remove %v", h)
|
2017-03-26 21:53:26 +02:00
|
|
|
fn := b.Filename(h)
|
2015-08-14 15:30:36 +02:00
|
|
|
|
2015-08-19 22:02:47 +02:00
|
|
|
// reset read-only flag
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
err := fs.Chmod(fn, 0666)
|
2015-08-19 22:02:47 +02:00
|
|
|
if err != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return errors.Wrap(err, "Chmod")
|
2015-08-19 22:02:47 +02:00
|
|
|
}
|
|
|
|
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
return fs.Remove(fn)
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2016-02-24 22:43:04 +01:00
|
|
|
func isFile(fi os.FileInfo) bool {
|
|
|
|
return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func readdir(d string) (fileInfos []os.FileInfo, err error) {
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 21:59:13 +02:00
|
|
|
f, e := fs.Open(d)
|
2016-02-24 22:43:04 +01:00
|
|
|
if e != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return nil, errors.Wrap(e, "Open")
|
2016-02-24 22:43:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
e := f.Close()
|
|
|
|
if err == nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
err = errors.Wrap(e, "Close")
|
2016-02-24 22:43:04 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return f.Readdir(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// listDir returns a list of all files in d.
|
|
|
|
func listDir(d string) (filenames []string, err error) {
|
|
|
|
fileInfos, err := readdir(d)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fi := range fileInfos {
|
|
|
|
if isFile(fi) {
|
|
|
|
filenames = append(filenames, fi.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filenames, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// listDirs returns a list of all files in directories within d.
|
|
|
|
func listDirs(dir string) (filenames []string, err error) {
|
|
|
|
fileInfos, err := readdir(dir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fi := range fileInfos {
|
|
|
|
if !fi.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := listDir(filepath.Join(dir, fi.Name()))
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
filenames = append(filenames, files...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return filenames, nil
|
|
|
|
}
|
|
|
|
|
2015-03-28 11:50:23 +01:00
|
|
|
// List returns a channel that yields all names of blobs of type t. A
|
2015-06-28 09:44:06 +02:00
|
|
|
// goroutine is started for this. If the channel done is closed, sending
|
2015-03-28 11:50:23 +01:00
|
|
|
// stops.
|
2016-08-31 22:39:36 +02:00
|
|
|
func (b *Local) List(t restic.FileType, done <-chan struct{}) <-chan string {
|
2016-09-27 22:35:08 +02:00
|
|
|
debug.Log("List %v", t)
|
2016-02-24 22:43:04 +01:00
|
|
|
lister := listDir
|
2016-08-31 22:39:36 +02:00
|
|
|
if t == restic.DataFile {
|
2016-02-24 22:43:04 +01:00
|
|
|
lister = listDirs
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ch := make(chan string)
|
2017-03-26 21:53:26 +02:00
|
|
|
items, err := lister(b.Dirname(restic.Handle{Type: t}))
|
2015-03-28 11:50:23 +01:00
|
|
|
if err != nil {
|
|
|
|
close(ch)
|
|
|
|
return ch
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer close(ch)
|
2016-02-24 22:43:04 +01:00
|
|
|
for _, m := range items {
|
2015-03-28 11:50:23 +01:00
|
|
|
if m == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case ch <- m:
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return ch
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete removes the repository and all files.
|
2015-08-14 15:30:36 +02:00
|
|
|
func (b *Local) Delete() error {
|
2016-09-27 22:35:08 +02:00
|
|
|
debug.Log("Delete()")
|
2017-03-25 13:20:03 +01:00
|
|
|
return fs.RemoveAll(b.Path)
|
2015-08-14 15:30:36 +02:00
|
|
|
}
|
2015-03-28 11:50:23 +01:00
|
|
|
|
2015-08-14 15:30:36 +02:00
|
|
|
// Close closes all open files.
|
|
|
|
func (b *Local) Close() error {
|
2016-09-27 22:35:08 +02:00
|
|
|
debug.Log("Close()")
|
2016-01-26 22:07:51 +01:00
|
|
|
// this does not need to do anything, all open files are closed within the
|
|
|
|
// same function.
|
2015-08-14 15:30:36 +02:00
|
|
|
return nil
|
|
|
|
}
|