From dc5d54008e75849a8302bef51a3e2e6129145a03 Mon Sep 17 00:00:00 2001 From: Openkylin Developers Date: Tue, 6 Dec 2022 14:41:58 +0800 Subject: [PATCH] ensure that all mtime of modified files are equal when pushing Bug-Debian: https://bugs.debian.org/466360 Upstream-status: to be submitted This is intended to avoid time skew in build systems in some cases. See the discussion https://lists.debian.org/debian-policy/2008/02/msg00030.html for more context information. Gbp-Pq: Name push_timeskew --- quilt/push.in | 22 +++++++-- quilt/scripts/backup-files.in | 3 +- test/push_timeskew.test | 86 +++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 test/push_timeskew.test diff --git a/quilt/push.in b/quilt/push.in index e19b0a1..49c90c5 100644 --- a/quilt/push.in +++ b/quilt/push.in @@ -30,7 +30,8 @@ in the series file is applied. When a number is specified, apply the specified number of patches. When a patch name is specified, apply all patches up to and including the specified patch. Patch names may include the patches/ prefix, which means that filename completion can -be used. +be used. The mtime of all touched files will be exactly the same to +prevent time skews. -a Apply all patches in the series file. @@ -215,18 +216,29 @@ add_patch() touch "$QUILT_PC/$patch~refresh" fi - if [ -e "$QUILT_PC/$patch" ] + if ! [ -e "$QUILT_PC/$patch" ] then - touch "$QUILT_PC/$patch/.timestamp" - else mkdir "$QUILT_PC/$patch" fi + touch "$QUILT_PC/$patch/.timestamp" + + # Store the list of files to process + NONEMPTY_FILES=$(gen_tempfile) + trap "rm -f \"$NONEMPTY_FILES\"" EXIT + find "$QUILT_PC/$patch" -type f \ + -a ! -path "$QUILT_PC/$patch/.timestamp" -size +0 -print0 > "$NONEMPTY_FILES" + + if [ -s "$NONEMPTY_FILES" ]; then + xargs -0 touch -c -r "$QUILT_PC/$patch/.timestamp" < "$NONEMPTY_FILES" + fi + + rm -f $NONEMPTY_FILES if ! [ -e "$patch_file" ] then printf $"Patch %s does not exist; applied empty patch\n" \ "$(print_patch "$patch")" - elif [ -z "$(shopt -s nullglob ; echo "$QUILT_PC/$patch/"*)" ] + elif [ "$(shopt -s nullglob ; echo "$QUILT_PC/$patch/"*)" = "$QUILT_PC/$patch/.timestamp" ] then printf $"Patch %s appears to be empty; applied\n" \ "$(print_patch "$patch")" diff --git a/quilt/scripts/backup-files.in b/quilt/scripts/backup-files.in index 9b33b64..f491f4c 100644 --- a/quilt/scripts/backup-files.in +++ b/quilt/scripts/backup-files.in @@ -184,8 +184,9 @@ restore_all() done < "$NONEMPTY_FILES" fi + modif_time=`date +%m%d%H%M.%S` if [ -n "$OPT_TOUCH" ]; then - xargs -0 touch -c < "$NONEMPTY_FILES" + xargs -0 touch -t $modif_time -c < "$NONEMPTY_FILES" fi fi diff --git a/test/push_timeskew.test b/test/push_timeskew.test new file mode 100644 index 0000000..66420d0 --- /dev/null +++ b/test/push_timeskew.test @@ -0,0 +1,86 @@ +This test enforces that files touched by a patch have the exact same +mtime when pushing and poping the patch. +(To run, type `./run push_timeskew.test' in this directory.) + + $ mkdir patches d + + $ quilt new patch1 + > Patch %{P}patch1 is now on top + + $ cd d + $ mkdir dir + $ echo "This is file one." > dir/file1 + $ quilt add dir/file1 + > File d/dir/file1 added to patch %{_P}patch1 + + $ echo "This is file two." > dir/file2 + $ quilt add dir/file2 + > File d/dir/file2 added to patch %{_P}patch1 + + $ echo "More content to file one." >> dir/file1 + $ echo "More content to file two." >> dir/file2 + $ quilt refresh + > Refreshed patch %{_P}patch1 + + $ quilt pop -q + > Removing patch %{_P}patch1 + > No patches applied + + $ test dir/file1 -nt dir/file2 && echo "timeskew!" + $ test dir/file2 -nt dir/file1 && echo "timeskew!" + + $ quilt push -q + > Applying patch %{_P}patch1 + > Now at patch %{_P}patch1 + + $ test dir/file1 -nt dir/file2 && echo "timeskew!" + $ test dir/file2 -nt dir/file1 && echo "timeskew!" + + + + # And now, enforces that this timestamp fixup don't create unwanted files + $ quilt new patch2.diff + > Patch %{_P}patch2.diff is now on top + + $ echo "some content" > dir/file_removed + $ quilt add dir/file_removed + > File d/dir/file_removed added to patch %{_P}patch2.diff + + $ quilt add dir/file_created + > File d/dir/file_created added to patch %{_P}patch2.diff + + $ rm dir/file_removed + $ echo "some content" > dir/file_created + $ quilt refresh + > Refreshed patch %{_P}patch2.diff + + $ quilt diff --no-timestamps --no-index -p ab + > --- /dev/null + > +++ b/d/dir/file_created + > @@ -0,0 +1 @@ + > +some content + > --- a/d/dir/file_removed + > +++ /dev/null + > @@ -1 +0,0 @@ + > -some content + + $ quilt pop + > Removing patch %{_P}patch2.diff + > Removing d/dir/file_created + > Restoring d/dir/file_removed + > + > Now at patch %{_P}patch1 + + $ test -e dir/file_created && echo "Created file should not exist when patch is poped!" + $ test ! -e dir/file_removed && echo "Deleted file should exist when patch is poped!" + + $ quilt push + > Applying patch %{_P}patch2.diff + > patching file d/dir/file_created + > patching file d/dir/file_removed + > + > Now at patch %{_P}patch2.diff + + $ test ! -e dir/file_created && echo "Created file should exist when patch is pushed!" + $ test -e dir/file_removed && echo "Deleted file should not exist when patch is pushed!" +