Subject: Suggestion to revert touching files when the hash matches (problem with hardlinks)

From: Jan Niklas Böhm <[email-masked]>
Date: Mon, 31 Oct 2022 22:37:41 +0100

Hello again,

I would like to suggest reverting the change introduces in version 
1.23.0: Performance optimization: do not use target’s temporary output 
file at all, if its hash equals to already existing target’s one. Just 
touch existing target file instead.

Unfortunately, this breaks down as soon as hardlinks are used.  Since 
hardlinks and ctime do not play well together, this is all done with the 
environment variable set to REDO_INODE_TRUST=mtime.  Consider the 
following example: the do file "a.do" only has one line "echo aaa" and 
the file "b.do" is

	b.do
	---
	redo-ifchange a
	ln a $3

Calling "redo b" works as expected.  But when a is changed such that it 
is ood, but does not change its output (e.g. insert a comment), we get

	redo b
	redo . a (0.002s)
	err  b (0.006s): $1 was explicitly touched

This is because "a" is touched, which also touches the file "b" and thus 
goredo rightfully complains about it.  Even if it did not (which happens 
in my project because there is more indirection), the mtime is changed 
in the file, but the .rec file is not updated correspondingly.

Since I think it will be much more work to resolve all hardlinks and 
update the .rec file, I think it is more sensible to instead revert the 
behavior of touching the file and instead move $3 to the target location 
instead, which would avoid the problem outlined above.

Since both $3 and the final file are in the same directory, the moving 
should not be an expensive operation anyways I believe.

Let me know what you think!

Cheers
Nik