Fixes: https://todo.sr.ht/~sircmpwn/hare/953
Signed-off-by: Alexey Yerin <yyp@disroot.org>
---
v1 -> v2: genbootstrap strikes again
cmd/hare/build.ha | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/cmd/hare/build.ha b/cmd/hare/build.ha
index bc6589a7..07b9553a 100644
--- a/cmd/hare/build.ha
+++ b/cmd/hare/build.ha
@@ -20,6 +20,7 @@ use os;
use path;
use strconv;
use strings;
+use time;
use unix::tty;
fn build(name: str, cmd: *getopt::command) (void | error) = {
@@ -194,6 +195,22 @@ fn build(name: str, cmd: *getopt::command) (void | error) = {
let dest = os::stdout_file;
if (output != "-") {
+ match (os::stat(output)) {
+ case let output_stat: fs::filestat =>
+ let output_mtime = output_stat.mtime;
+ match (os::stat(built)) {
+ case let built_stat: fs::filestat =>
+ let built_mtime = built_stat.mtime;
+ // Avoid replacing the destination file if it's
+ // already up-to-date
+ if (time::compare(output_mtime, built_mtime) >= 0) {
+ return;
+ };
+ case fs::error => void;
+ };
+ case fs::error => void;
+ };
+
let mode: fs::mode = 0o644;
if (ctx.goal == build::stage::BIN) {
mode |= 0o111;
--
2.47.1