diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-01-29 22:13:51 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-01-29 22:13:51 +0000 |
commit | 9c4c0b93fea5dfab751d30d535b241e3d9b7d2e6 (patch) | |
tree | 981e3918c49ac11ce42bc0fe34432dfa6106649f | |
parent | 400ff91857b383362cac91ff185122dd8cee3ceb (diff) |
avoid updating file with same contents
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java b/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java index 8f089bfc8d6..7d2c780bcdb 100644 --- a/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java @@ -1,6 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa; +import java.nio.file.Files; +import java.nio.file.Path; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -9,6 +11,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintStream; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -84,7 +87,9 @@ public class VersionTagger { String className = format == Format.SIMPLE ? "VespaVersion" : "Vtag"; String outFile = dirName + "/" + className +".java"; - FileOutputStream out = new FileOutputStream(outFile); + Path outPath = Path.of(outFile); + Path tmpPath = Path.of(outFile + ".tmp"); + var out = Files.newOutputStream(tmpPath); OutputStreamWriter writer = new OutputStreamWriter(out); System.err.println("generating: " + outFile); @@ -129,6 +134,17 @@ public class VersionTagger { } writer.write("}\n"); writer.close(); + out.close(); + if (Files.exists(outPath)) { + byte[] tmpBytes = Files.readAllBytes(tmpPath); + byte[] oldBytes = Files.readAllBytes(outPath); + if (Arrays.equals(tmpBytes, oldBytes)) { + Files.delete(tmpPath); + return; + } + } + Files.deleteIfExists(outPath); + Files.move(tmpPath, outPath); } } |