diff options
| author | Kaushal Subedi | 2015-10-26 20:50:39 -0600 |
|---|---|---|
| committer | Kaushal Subedi | 2015-10-26 20:50:39 -0600 |
| commit | 1799db086bd74aa174292fb2655034018054af98 (patch) | |
| tree | fe983ed5301e39d56428c793153a993324255163 | |
| parent | c4a685316bb478e82cda6e8017689f4758ebfff4 (diff) | |
| download | gomove-1799db086bd74aa174292fb2655034018054af98.tar.bz2 | |
only write files if changes were made
| -rw-r--r-- | main.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -79,6 +79,7 @@ func ProcessFileNative(filePath string, from string, to string) { scanner := bufio.NewScanner(bytes.NewReader(fileContent)) scanLine := 0 + numChages := 0 isImportLine := false @@ -96,6 +97,7 @@ func ProcessFileNative(filePath string, from string, to string) { fmt.Println("Found Import On Line", scanLine) newImport := strings.Replace(line, from, to, -1) output += newImport + "\n" + numChages++ continue } @@ -113,6 +115,7 @@ func ProcessFileNative(filePath string, from string, to string) { newImport := strings.Replace(line, from, to, -1) fmt.Println("Replacing", line, "to", newImport, "on line", scanLine) output += newImport + "\n" + numChages++ continue } @@ -121,7 +124,10 @@ func ProcessFileNative(filePath string, from string, to string) { } - ioutil.WriteFile(filePath, []byte(output), os.ModePerm) + // Only write if changes were made + if numChages > 0 { + ioutil.WriteFile(filePath, []byte(output), os.ModePerm) + } } func ProcessFileAST(filePath string, from string, to string) { |
