forked from distok/cutthecord
patchport: Fix #92
This commit is contained in:
parent
f3ee05255c
commit
1cc00f6a48
1 changed files with 13 additions and 5 deletions
12
patchport.py
12
patchport.py
|
@ -54,9 +54,11 @@ 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)
|
||||
|
@ -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)
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue