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

Make shared.IsSnapshot() a bit more strict #14577

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

simondeziel
Copy link
Member

No description provided.

Avoid accessing slice out of bound if no `%d` is present in the pattern.
The snapshot pattern doesn't need `%d` to be escaped now that `Sprintf` isn't
used.

Signed-off-by: Simon Deziel <[email protected]>
Avoid accessing slice out of bound if no `%d` is present in the pattern.
The snapshot pattern doesn't need `%d` to be escaped now that `Sprintf` isn't
used.

Signed-off-by: Simon Deziel <[email protected]>
The validate.IsHostname() already rejects `/` so there is no need to explicitly
check for `/` in the instance name.

Signed-off-by: Simon Deziel <[email protected]>
parts := strings.SplitN(name, shared.SnapshotDelimiter, 2)
instanceName := parts[0]
snapshotName := parts[1]
if shared.IsSnapshot(name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just use api.GetParentAndSnapshotName everywhere (or at least in more places) and update it to use strings.Cut. This way we don't have to repeat the check for / in the string.

@@ -651,9 +651,10 @@ func (r BytesReadCloser) Close() error {
return nil
}

// IsSnapshot returns true if a given name contains the snapshot delimiter.
// IsSnapshot returns true if a given name contains a snapshot delimiter not at the end.
func IsSnapshot(name string) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should centralise the "is snapshot/extract snapshot parts" into api.GetParentAndSnapshotName instead.

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not gone through this in detail yet, but one comment is that we've consciously avoided using IsSnapshot or api.GetParentAndSnapshotName in the past in places where the variable being checked isn't representing a possible instance or volume fully qualified snapshot name.

I.e instance backups follows the same style but they represent different things and could evolve separately, so maybe we also need a separate function for other conceptual fully qualified entities.

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

Successfully merging this pull request may close these issues.

2 participants