mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
backend: Add Delete() to restic.Backend interface
This commit is contained in:
parent
3736f33ebf
commit
0e722efb09
@ -275,7 +275,7 @@ func (b *Local) List(ctx context.Context, t restic.FileType) <-chan string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes the repository and all files.
|
// Delete removes the repository and all files.
|
||||||
func (b *Local) Delete() error {
|
func (b *Local) Delete(ctx context.Context) error {
|
||||||
debug.Log("Delete()")
|
debug.Log("Delete()")
|
||||||
return fs.RemoveAll(b.Path)
|
return fs.RemoveAll(b.Path)
|
||||||
}
|
}
|
||||||
|
@ -349,3 +349,34 @@ func (b *restBackend) Close() error {
|
|||||||
// same function.
|
// same function.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove keys for a specified backend type.
|
||||||
|
func (b *restBackend) removeKeys(ctx context.Context, t restic.FileType) error {
|
||||||
|
for key := range b.List(ctx, restic.DataFile) {
|
||||||
|
err := b.Remove(ctx, restic.Handle{Type: restic.DataFile, Name: key})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete removes all data in the backend.
|
||||||
|
func (b *restBackend) Delete(ctx context.Context) error {
|
||||||
|
alltypes := []restic.FileType{
|
||||||
|
restic.DataFile,
|
||||||
|
restic.KeyFile,
|
||||||
|
restic.LockFile,
|
||||||
|
restic.SnapshotFile,
|
||||||
|
restic.IndexFile}
|
||||||
|
|
||||||
|
for _, t := range alltypes {
|
||||||
|
err := b.removeKeys(ctx, t)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.Remove(ctx, restic.Handle{Type: restic.ConfigFile})
|
||||||
|
}
|
||||||
|
@ -499,3 +499,8 @@ func (r *SFTP) Close() error {
|
|||||||
<-r.result
|
<-r.result
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete removes all data in the backend.
|
||||||
|
func (r *SFTP) Delete(context.Context) error {
|
||||||
|
return r.c.RemoveDirectory(r.p)
|
||||||
|
}
|
||||||
|
@ -40,6 +40,9 @@ type Backend interface {
|
|||||||
// IsNotExist returns true if the error was caused by a non-existing file
|
// IsNotExist returns true if the error was caused by a non-existing file
|
||||||
// in the backend.
|
// in the backend.
|
||||||
IsNotExist(err error) bool
|
IsNotExist(err error) bool
|
||||||
|
|
||||||
|
// Delete removes all data in the backend.
|
||||||
|
Delete(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileInfo is returned by Stat() and contains information about a file in the
|
// FileInfo is returned by Stat() and contains information about a file in the
|
||||||
|
Loading…
Reference in New Issue
Block a user