diff options
| author | Richard Jones <rjones@redhat.com> | 2009-04-30 15:43:11 +0100 |
|---|---|---|
| committer | Richard Jones <rjones@redhat.com> | 2009-04-30 15:43:11 +0100 |
| commit | 3c5bcce927dfa9213469d1f641408a0105685291 (patch) | |
| tree | 3c3f8770d66aefe2ca99057dbd8fe039d8390d60 | |
| parent | abb447c32abdea467374edc30704818dd2883da7 (diff) | |
| download | libguestfs-3c5bcce927dfa9213469d1f641408a0105685291.tar.gz libguestfs-3c5bcce927dfa9213469d1f641408a0105685291.tar.xz libguestfs-3c5bcce927dfa9213469d1f641408a0105685291.zip | |
Updated the generator so it only overwrites files if they've changed.
| -rwxr-xr-x | src/generator.ml | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/generator.ml b/src/generator.ml index d680d424..be67807f 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -1804,6 +1804,13 @@ let rec string_split sep str = s' :: string_split sep s'' ) +let files_equal n1 n2 = + let cmd = sprintf "cmp -s %s %s" (Filename.quote n1) (Filename.quote n2) in + match Sys.command cmd with + | 0 -> true + | 1 -> false + | i -> failwithf "%s: failed with error code %d" cmd i + let rec find_map f = function | [] -> raise Not_found | x :: xs -> @@ -6227,8 +6234,17 @@ let output_to filename = let close () = close_out !chan; chan := stdout; - Unix.rename filename_new filename; - printf "written %s\n%!" filename; + + (* Is the new file different from the current file? *) + if Sys.file_exists filename && files_equal filename filename_new then + Unix.unlink filename_new (* same, so skip it *) + else ( + (* different, overwrite old one *) + (try Unix.chmod filename 0o644 with Unix.Unix_error _ -> ()); + Unix.rename filename_new filename; + Unix.chmod filename 0o444; + printf "written %s\n%!" filename; + ) in close |
