allow no-op replacements in update tooling
This commit is contained in:
parent
2f252345d9
commit
9e52600b3f
@ -12,9 +12,12 @@ func ReplaceOnce(path string, re *regexp.Regexp, replace string) error {
|
||||
return err
|
||||
}
|
||||
orig := string(data)
|
||||
if !re.MatchString(orig) {
|
||||
return fmt.Errorf("pattern not found in %s", path)
|
||||
}
|
||||
out := re.ReplaceAllString(orig, replace)
|
||||
if out == orig {
|
||||
return fmt.Errorf("pattern not found in %s", path)
|
||||
return nil
|
||||
}
|
||||
return os.WriteFile(path, []byte(out), 0644)
|
||||
}
|
||||
@ -25,9 +28,12 @@ func ReplaceOnceFunc(path string, re *regexp.Regexp, fn func(string) string) err
|
||||
return err
|
||||
}
|
||||
orig := string(data)
|
||||
if !re.MatchString(orig) {
|
||||
return fmt.Errorf("pattern not found in %s", path)
|
||||
}
|
||||
out := re.ReplaceAllStringFunc(orig, fn)
|
||||
if out == orig {
|
||||
return fmt.Errorf("pattern not found in %s", path)
|
||||
return nil
|
||||
}
|
||||
return os.WriteFile(path, []byte(out), 0644)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user