[vala/0.36] girwriter: Only replace existing GIR files if they changed
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.36] girwriter: Only replace existing GIR files if they changed
- Date: Tue, 13 Aug 2019 15:20:04 +0000 (UTC)
commit 4b2826357196bddc8efe29b411c8683443140e96
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed May 1 12:51:45 2019 +0200
girwriter: Only replace existing GIR files if they changed
Same how it is done in CodeWriter.write_file()
codegen/valagirwriter.vala | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 138d3593b..ebb028b0e 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -173,7 +173,15 @@ public class Vala.GIRWriter : CodeVisitor {
buffer.append_printf ("</repository>\n");
string filename = "%s%c%s".printf (directory, Path.DIR_SEPARATOR, gir_filename);
- stream = FileStream.open (filename, "w");
+ var file_exists = FileUtils.test (filename, FileTest.EXISTS);
+ var temp_filename = "%s.valatmp".printf (filename);
+
+ if (file_exists) {
+ stream = FileStream.open (temp_filename, "w");
+ } else {
+ stream = FileStream.open (filename, "w");
+ }
+
if (stream == null) {
Report.error (null, "unable to open `%s' for writing".printf (filename));
return;
@@ -199,6 +207,31 @@ public class Vala.GIRWriter : CodeVisitor {
stream.puts (buffer.str);
stream = null;
+ if (file_exists) {
+ var changed = true;
+
+ try {
+ var old_file = new MappedFile (filename, false);
+ var new_file = new MappedFile (temp_filename, false);
+ var len = old_file.get_length ();
+ if (len == new_file.get_length ()) {
+ if (Memory.cmp (old_file.get_contents (), new_file.get_contents (),
len) == 0) {
+ changed = false;
+ }
+ }
+ old_file = null;
+ new_file = null;
+ } catch (FileError e) {
+ // assume changed if mmap comparison doesn't work
+ }
+
+ if (changed) {
+ FileUtils.rename (temp_filename, filename);
+ } else {
+ FileUtils.unlink (temp_filename);
+ }
+ }
+
foreach (var ns in unannotated_namespaces) {
if (!our_namespaces.contains(ns)) {
Report.warning (ns.source_reference, "Namespace %s does not have a GIR
namespace and version annotation".printf (ns.name));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]