release-tools/do-copyright-year: Modify files with more care
authorRichard Levitte <levitte@openssl.org>
Fri, 26 May 2023 11:06:08 +0000 (13:06 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 26 May 2023 11:06:08 +0000 (13:06 +0200)
Files were modified by running a simple in-place sed (i.e. 'sed -i').
This turns out to update the modification time on every file, even those
that remain unmodified.

The effect is that time stamps in a source directory become unreliable,
causing configdata.pm to be "mysteriously" older than (unmodified) files it
depends on, which causes a spurious reconfiguration when running 'make'
again.

To mediate, the loop is modified to take copies of the original files, run
an in-place sed on those, and only move them back to the original files if
there were any actual modifications.  That should leave time stamps alone on
unmodified files.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/tools/pull/151)

release-tools/do-copyright-year

index 7c6a18e3a824b99cc75ed17107dac920bac6dd5a..e22dc031444841f6e3b188ef7e4d5b48ea1a62b0 100755 (executable)
@@ -47,8 +47,22 @@ git diff-tree -r --name-status `git rev-list -1 --before=$NYD HEAD`..HEAD | \
            if [ -d "$FILE" ]; then continue; fi
            (( count++ ))
            spin $count
-           sed -E -f /tmp/sed$$ -i "$FILE"
-           git add "$FILE"
+           # To avoid touching the original files when they aren't modified:
+           #
+           # 1. Copy the file, to make sure all permissions and other
+           #    copyable attributes are copied as well
+           # 2. Run sed on the copy
+           # 3. IF the copy has been modified, move it back to the original,
+           #    add and commit.
+           TMPFILE="$(dirname "$FILE")"/"__$(basename "$FILE").new"
+           cp "$FILE" "$TMPFILE"
+           sed -E -f /tmp/sed$$ -i "$TMPFILE"
+           if cmp -s "$FILE" "$TMPFILE"; then
+               rm "$TMPFILE"
+           else
+               mv "$TMPFILE" "$FILE"
+               git add "$FILE"
+           fi
        done
        endspin "Files considered: $count"
     )