Refuse a backup destination an unplugged volume left empty (closes #239)
check / check (push) Waiting to run
check / check (push) Waiting to run
Every backup writes vaultik-destination.txt at the destination root. While the local index holds snapshots stored there, a destination without it is not present: snapshot create refuses before writing, prune and snapshot purge fail, and snapshot list and snapshot remove act as for a destination that cannot be listed. snapshot create and snapshot remove check it first. remote nuke deletes the marker last. The file:// backend never creates its destination directory, which protects a directory on a removable volume, not a mount point. Tests back up into directories that exist; fixtures for a written destination carry the marker. Judgement call: the marker is rewritten on every backup. Deviation: for the complexity limit, two blocks moved, unchanged, into snapshotNamesToCreate and confirmRemoveSnapshot. Model: opus-5-5
This commit was merged in pull request #349.
This commit is contained in:
@@ -292,3 +292,43 @@ func TestFileStorerDeletePartialUploadsThroughSymlinkedDirectory(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestFileStorerPutMissingDestination checks that a write fails when the
|
||||
// destination directory has gone, even after earlier writes to it
|
||||
// succeeded, and that it does not create the directory again.
|
||||
func TestFileStorerPutMissingDestination(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
base := filepath.Join(t.TempDir(), "usbstick")
|
||||
|
||||
err := os.Mkdir(base, 0o750)
|
||||
if err != nil {
|
||||
t.Fatalf("Mkdir: %v", err)
|
||||
}
|
||||
|
||||
s, err := storage.NewFileStorer(base)
|
||||
if err != nil {
|
||||
t.Fatalf("NewFileStorer: %v", err)
|
||||
}
|
||||
|
||||
err = s.Put(ctx, "blobs/aa/bb/first", strings.NewReader("first"))
|
||||
if err != nil {
|
||||
t.Fatalf("first Put: %v", err)
|
||||
}
|
||||
|
||||
err = os.Rename(base, base+"-unplugged")
|
||||
if err != nil {
|
||||
t.Fatalf("Rename: %v", err)
|
||||
}
|
||||
|
||||
err = s.Put(ctx, "blobs/aa/bb/second", strings.NewReader("second"))
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
t.Errorf("Put = %v, want a not-exist error", err)
|
||||
}
|
||||
|
||||
_, err = os.Stat(base)
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
t.Errorf("Put created the destination directory again (Stat = %v)", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user