use CutSuffix

This commit is contained in:
Denis Bilenko 2025-03-05 11:54:56 +01:00
parent 4a2485fcc9
commit e73dafca83
1 changed files with 2 additions and 2 deletions

View File

@ -52,8 +52,8 @@ func patchMetadata(r io.Reader, oldVersion, newVersion string) ([]byte, error) {
var buf bytes.Buffer
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, versionKey) {
foundVersion := strings.TrimSpace(line[len(versionKey):])
if versionValue, ok := strings.CutPrefix(line, versionKey); ok {
foundVersion := strings.TrimSpace(versionValue)
if foundVersion != oldVersion {
return nil, fmt.Errorf("Unexpected version in METADATA: %s (expected %s)", strings.TrimSpace(line), oldVersion)
}