MCPcopy Create free account
hub / github.com/ddev/ddev / ReplaceStringInFile

Function ReplaceStringInFile

pkg/fileutil/files.go:320–333  ·  view source on GitHub ↗

ReplaceStringInFile takes search and replace strings, an original path, and a dest path, returns error

(searchString string, replaceString string, origPath string, destPath string)

Source from the content-addressed store, hash-verified

318
319// ReplaceStringInFile takes search and replace strings, an original path, and a dest path, returns error
320func 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
336func IsSameFile(path1 string, path2 string) (bool, error) {

Callers 3

enableDotEnvLoadingFunction · 0.92
TestComposeWithStreamsFunction · 0.92
TestReplaceStringInFileFunction · 0.92

Calls

no outgoing calls

Tested by 2

TestComposeWithStreamsFunction · 0.74
TestReplaceStringInFileFunction · 0.74