patchport: Fix #92
This commit is contained in:
parent
f3ee05255c
commit
1cc00f6a48
1 changed files with 13 additions and 5 deletions
18
patchport.py
18
patchport.py
|
@ -54,23 +54,25 @@ def fix_offset(patch_contents):
|
|||
for line in patch_lines:
|
||||
if "diff -crB" in line:
|
||||
patch_target = line.split(" ")[2].replace("from/", "")
|
||||
if not os.path.exists(os.path.join(apk_folder, patch_target)):
|
||||
return False
|
||||
os.makedirs(os.path.dirname(os.path.join(tmp_folder, patch_target)), exist_ok=True)
|
||||
shutil.copy(os.path.join(apk_folder, patch_target), os.path.join(tmp_folder, patch_target))
|
||||
#shutil.copytree(apk_folder, tmp_folder)
|
||||
# shutil.copytree(apk_folder, tmp_folder)
|
||||
subprocess.run("patch -p1 --no-backup-if-mismatch --force",
|
||||
shell=True, input=patch_contents, text=True,
|
||||
cwd=tmp_folder, capture_output=True)
|
||||
out = subprocess.run(f"diff -crB {apk_folder} {tmp_folder}",
|
||||
shell=True, input=patch_contents, text=True,
|
||||
cwd=tmp_folder, capture_output=True)
|
||||
|
||||
|
||||
shutil.rmtree(tmp_folder, ignore_errors=True)
|
||||
actual_difflines = []
|
||||
for line in out.stdout.splitlines():
|
||||
if line[0:4] != "Only":
|
||||
actual_difflines.append(line)
|
||||
patch_out = ("\n".join(actual_difflines)+"\n").replace(apk_folder, "from").replace(tmp_folder, "to")
|
||||
|
||||
|
||||
return patch_out
|
||||
|
||||
|
||||
|
@ -204,8 +206,14 @@ for patch in os.listdir(os.path.join(cutthecord_folder, "patches")):
|
|||
failures.append(patch)
|
||||
out_path += "-failed"
|
||||
elif "offset" in out.stdout:
|
||||
patch_contents = fix_offset(patch_contents)
|
||||
print(f"WARNING: {patch} has offsets which were auto corrected.")
|
||||
temp_patch_contents = fix_offset(patch_contents)
|
||||
if temp_patch_contents:
|
||||
patch_contents = temp_patch_contents
|
||||
print(f"WARNING: {patch} has offsets which were auto corrected.")
|
||||
else:
|
||||
print(f"FAILED: {patch} is missing files, please fix by hand.")
|
||||
failures.append(patch)
|
||||
out_path += "-failed"
|
||||
|
||||
if debug:
|
||||
print(out.stdout)
|
||||
|
|
Reference in a new issue