Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patching: emit warnings when files in dt folder overwrite pre-existing files (DTs that landed upstream) #7271

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/tools/common/dt_makefile_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ def __init__(self):
self.name = "Not initted name"
self.description = "Not initted desc"
self.files = []
self.overwrites = []

def rich_name_status(self):
if len(self.overwrites) > 0:
return f"[bold][red]{self.name}"
return f"[bold][blue]{self.name}"

def rich_diffstats(self):
files_bare = []
# Always list all overwrites.
for one_file in self.overwrites:
files_bare.append(f"[OVERWRITTEN]{os.path.basename(one_file)}")
max_files_to_show = 15 # show max 15
for one_file in self.files[:max_files_to_show]:
files_bare.append(os.path.basename(one_file))
Expand Down Expand Up @@ -231,9 +237,14 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au
all_files_to_copy_dict[base_filename] = one_file
# do the actual copy
all_copied_files = []
overwritten_files = []
for one_file in all_files_to_copy_dict:
log.debug(f"Copy '{one_file}' (from {all_files_to_copy_dict[one_file]}) to '{full_path_target_dir}'...")
full_path_target_file = os.path.join(full_path_target_dir, one_file)
# If the target already exists, emit a warning; DTs land upstream all the time and we might forget to remove them from our 'dt' directory
if os.path.exists(full_path_target_file):
overwritten_files.append(full_path_target_file)
log.warning(f"Target file '{one_file}' already exists; will overwrite it; consider if it should be removed.")
shutil.copyfile(all_files_to_copy_dict[one_file], full_path_target_file)
all_copied_files.append(full_path_target_file)
if type == "dt":
Expand All @@ -246,7 +257,12 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au
desc = AutomaticPatchDescription()
desc.name = f"Armbian Bare {type.upper()} auto-patch"
desc.description = f"Armbian Bare {type.upper()} files for {target_dir}"
# if overwritten files, add to description and name
if len(overwritten_files) > 0:
desc.description += f" (overwriting {len(overwritten_files)} files)"
desc.name += f" (overwriting {len(overwritten_files)} files)"
desc.files = all_copied_files
desc.overwrites = overwritten_files
ret_desc_list.append(desc)

if autopatcher_params.apply_patches_to_git and len(all_copied_files) > 0:
Expand Down