From ae6735f470ec7aad773c3b76a398d6944d11a3b5 Mon Sep 17 00:00:00 2001 From: Igor Velkov <325961+iav@users.noreply.github.com> Date: Thu, 5 Mar 2026 11:13:40 +0200 Subject: [PATCH] patching: fix #9028 timestamp when multiple patches touch same file (#9489) If patch B sorts after patch A but has an older mtime, it would overwrite A's timestamp on the shared file, causing the kernel Makefile to skip recompilation. Fix: only call os.utime() when the new mtime is strictly greater than the file's current mtime. --- lib/tools/common/patching_utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tools/common/patching_utils.py b/lib/tools/common/patching_utils.py index d75cc80c27..544551e686 100755 --- a/lib/tools/common/patching_utils.py +++ b/lib/tools/common/patching_utils.py @@ -760,10 +760,13 @@ class PatchInPatchFile: files_to_touch = [f for f in files_to_touch if f not in self.deleted_file_names] for file_name in files_to_touch: - # log.debug(f"Setting mtime of '{file_name}' to '{final_mtime}'.") file_path = os.path.join(working_dir, file_name) try: - os.utime(file_path, (final_mtime, final_mtime)) + # Only bump mtime; never lower it. Multiple patches may touch the same file, + # and a later patch with an older timestamp must not override the timestamp + # set by an earlier patch with a newer one (#9028). + if final_mtime > os.path.getmtime(file_path): + os.utime(file_path, (final_mtime, final_mtime)) except FileNotFoundError: log.warning(f"File '{file_path}' not found in patch {self}, can't set mtime.")