ReplaceStringInFile takes search and replace strings, an original path, and a dest path, returns error
(searchString string, replaceString string, origPath string, destPath string)
| 318 | |
| 319 | // ReplaceStringInFile takes search and replace strings, an original path, and a dest path, returns error |
| 320 | func ReplaceStringInFile(searchString string, replaceString string, origPath string, destPath string) error { |
| 321 | input, err := os.ReadFile(origPath) |
| 322 | if err != nil { |
| 323 | return err |
| 324 | } |
| 325 | |
| 326 | modifiedContent := bytes.ReplaceAll(input, []byte(searchString), []byte(replaceString)) |
| 327 | |
| 328 | // nolint: revive |
| 329 | if err = os.WriteFile(destPath, modifiedContent, 0666); err != nil { |
| 330 | return err |
| 331 | } |
| 332 | return nil |
| 333 | } |
| 334 | |
| 335 | // IsSameFile determines whether two paths refer to the same file/dir |
| 336 | func IsSameFile(path1 string, path2 string) (bool, error) { |
no outgoing calls