A cross-vault secret mv that cannot remove the source fails (closes #159)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
When `secret mv` copied a secret into another vault but could not remove the source, it printed a warning and the usual "Moved" line and exited 0. It now fails. If the source secret's directory is still in place, the error says the copy holds all versions and the source remains. If the source left its vault and only the temporary directory it was moved into could not be deleted, the error says the secret is moved and names that directory, which the error of RemoveDirAtomic now does. The tests are in package cli and call moveSecret, because the state directory lock refuses the wrapped filesystems that make the removal fail. Model: opus-5-5
This commit was merged in pull request #185.
This commit is contained in:
@@ -149,7 +149,9 @@ func WriteDir(fs afero.Fs, dir string, write func(dir string) error) error {
|
||||
|
||||
// RemoveDirAtomic deletes the directory dir so that it disappears in one
|
||||
// rename: dir is moved into a new directory from TempDirFor, which is then
|
||||
// deleted. A crash part-way leaves only that temporary directory behind.
|
||||
// deleted. A crash part-way leaves only that temporary directory behind. If
|
||||
// only deleting the temporary directory fails, dir is already gone, and the
|
||||
// error names the temporary directory, which holds what is left of it.
|
||||
func RemoveDirAtomic(fs afero.Fs, dir string) error {
|
||||
tmp, err := TempDirFor(fs, dir)
|
||||
if err != nil {
|
||||
@@ -165,7 +167,8 @@ func RemoveDirAtomic(fs afero.Fs, dir string) error {
|
||||
|
||||
err = fs.RemoveAll(tmp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove %s: %w", dir, err)
|
||||
return fmt.Errorf("failed to remove %s after moving %s into it: %w",
|
||||
tmp, dir, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user