Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting a snapshot might delete a different snapshot with the same prefix #6694

Closed
castanearie opened this issue Nov 6, 2024 · 3 comments
Closed

Comments

@castanearie
Copy link
Contributor

When one snapshot's name consists of another snapshot's name followed by a dash, it might be erroneously selected during cleanup. The following shell history shows how I create two snapshots, foo and foo-bar, and then try to delete foo, but foo-bar is deleted instead.

$ ddev snapshot -n foo
$ ddev snapshot -n foo-bar
$ ddev snapshot -l
┌──────────┬────────────┐
│ SNAPSHOT │ CREATED    │
├──────────┼────────────┤
│ foo-bar  │ 2024-11-06 │
├──────────┼────────────┤
│ foo      │ 2024-11-06 │
└──────────┴────────────┘
$ ddev snapshot -n foo -C
$ ddev snapshot -l
┌──────────┬────────────┐
│ SNAPSHOT │ CREATED    │
├──────────┼────────────┤
│ foo      │ 2024-11-06 │
└──────────┴────────────┘
$ ddev -v
ddev version v1.23.5
@rfay
Copy link
Member

rfay commented Nov 6, 2024

Thanks for the concise description. I'm able to reproduce this.

@rfay
Copy link
Member

rfay commented Nov 6, 2024

This is due to a flaw in the logic at

for _, file := range files {
if strings.HasPrefix(file, name+"-") {
return file, nil
}
}

It only happens with snapshots with a - in them, there's a bad assumption that - is an official delimiter.

Are you interested in trying a PR to fix this @castanearie? We'd help all the way. https://ddev.readthedocs.io/en/stable/developers/building-contributing/

@castanearie
Copy link
Contributor Author

Never did anything in Go, but can certainly try! Will probably be able to put something together in the next couple days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants