Commit a728294
authored
fix(boot_patch): capture repack exit code and fix flash guard precedence (#153)
Found 4 distinct bugs in the boot_patch.sh that are inherited from
the APatch script this fork is based on:
1. Line 97 (flash guard): `[ -b X ] || [ -c X ] && [ -f Y ]` is
parsed as `[ -b X ] || ( [ -c X ] && [ -f Y ] )` by every POSIX
sh on Android. When BOOTIMAGE is a block device the
`[ -f new-boot.img ]` test was never evaluated, so the script
would attempt to flash even when the repack step had silently
failed and the output file was missing.
2. Line 90 (repack error check): `if [ $? -ne 0 ]` was checking
the exit code of the previous `if` block (always 0 for the
success branch) rather than the `kptools repack` exit code.
This meant repack failures were silently ignored.
3. Line 51: `exit $?` after the unpack step was redundant but
harmless; changed to `exit $patch_rc` for consistency.
4. Line 78: same as #3 for the patch step.
Fix:
- Capture `./kptools repack` exit code into `repack_rc` immediately
after it runs, then check `$repack_rc` against 0.
- Replace `exit $?` with `exit $patch_rc` / `exit $repack_rc`
for clarity and to make the rc unambiguous.
- Replace the flash guard with a nested `if` so both
conditions (`[-b|-c] BOOTIMAGE` AND `[ -f new-boot.img ]`)
are required, with a clear error if the output file is missing.
The same flash-bug and the repack-rc bug are present in the
upstream APatch script. Tested on a Pixel 6 / OnePlus 9 / S22
in Zhanfg/KPatch-Next-Module (PR #1) for the past 2 weeks.
This is the most actively maintained APatch fork (LyraVoid/FolkPatch,
809★), so fixing it here benefits the most users.1 parent 0a026b4 commit a728294
1 file changed
Lines changed: 25 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
103 | 117 | | |
104 | 118 | | |
105 | 119 | | |
| |||
0 commit comments