Skip to content

Commit 4b65704

Browse files
committed
Upload file
1 parent cbc7099 commit 4b65704

2 files changed

Lines changed: 37 additions & 34 deletions

File tree

pio/src/main/assets/home/bin/unpack_img

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,23 @@ mkdir -p "$OUTPUT/${namepv##*/}" $OUTPUT/config
160160
progress -1/0
161161
break
162162
fi
163-
[ "$number_kk" ] && progress $number_kk/100
164-
if [ -z "$number_kk" ]; then
165-
iv=$((iv+1))
166-
elif [ "${number_kk:-0}" == "${save_num:-1}" ]; then
163+
if [ -z "$number_kk" ] || [ "${number_kk:-0}" == "${save_num:-1}" ]; then
167164
iv=$((iv+1))
168165
else
169166
iv=0
167+
[ "$number_kk" ] && progress $number_kk/100
170168
fi
171169
save_num="$number_kk"
172-
[ "$iv" -ge 10 ] && echo "Warning: Possible extraction error (erofs), check log: $TMP/extract_erofs.log" >&2 && break
170+
if [ "$iv" -ge 40 ];then
171+
echo "Warning: Slow erofs extraction speed, Stop checking the percentage to avoid an endless loop." >> $TMP/extract_erofs.log
172+
progress -1/0
173+
break
174+
fi
173175
sleep 1
174176
done
175177
fi
176178
wait
177-
if [ -f $TMP/extract_erofs.log ];then
178-
sed -i 's/\x1b\[[^m]*m//g' $TMP/extract_erofs.log
179-
sed '/Extract: \[.*.\]/d' $TMP/extract_erofs.log
180-
echo
181-
fi
179+
[ -f $TMP/extract_erofs.log ] && sed -i 's/\x1b\[[^m]*m//g' $TMP/extract_erofs.log
182180
echo "$dang_file" > "$OUTPUT/config/${namepv##*/}_info"
183181
if [ -f $OUTPUT/config/exception.log ];then
184182
rm -fr "$OUTPUT/${namepv##*/}"

pio/src/main/assets/module/termux/py/contextpatch.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import sys
66
from re import sub
7+
from re import escape
78

89
fix_permission = {
910
"system/app/*/.apk": "u:object_r:system_file:s0",
@@ -18,20 +19,23 @@
1819
"/vendor/bin/hw/android.hardware.wifi@1.0": "u:object_r:hal_wifi_default_exec:s0"
1920
}
2021

22+
def str_to_selinux(s: str) -> str:
23+
return escape(s).replace('\\-', '-')
2124

2225
def scan_context(file) -> dict:
2326
context = {}
2427
with open(file, "r", encoding='utf-8') as file_:
2528
for i in file_.readlines():
2629
line = i.strip().replace('\\', '')
2730
if not line:
28-
continue # Bỏ qua dòng trống
31+
continue
2932
if line.startswith('#'):
3033
continue
3134
parts = line.split()
3235
if not parts:
33-
continue # An toàn thêm 1 lần
36+
continue
3437
filepath, *other = parts
38+
filepath = filepath.replace(r'\@', '@')
3539
context[filepath] = other
3640
return context
3741

@@ -54,32 +58,33 @@ def scan_dir(folder) -> list:
5458

5559
def context_patch(fs_file, filename) -> dict:
5660
new_fs = {}
57-
permission_d = fs_file.get(list(fs_file)[0])
61+
# Giữ logic cũ: lấy permission mặc định từ entry đầu
62+
permission_d = fs_file.get(next(iter(fs_file)))
5863
if not permission_d:
5964
permission_d = ['u:object_r:system_file:s0']
6065
for i in filename:
66+
selinux_path = str_to_selinux(i)
6167
if fs_file.get(i):
62-
new_fs[sub(r'([^-_/a-zA-Z0-9])', r'\\\1', i)] = fs_file[i]
63-
else:
64-
permission = permission_d
65-
if i:
66-
if not i.isprintable():
67-
tmp = ''
68-
for c in i:
69-
tmp += c if c.isprintable() else '*'
70-
i = tmp
71-
if i in fix_permission.keys():
72-
permission = fix_permission[i]
73-
else:
74-
# Tìm context từ thư mục gần nhất có trong fs_file
75-
tmp_path = os.path.dirname(i)
76-
while tmp_path != "/" and tmp_path:
77-
if tmp_path in fs_file:
78-
permission = fs_file[tmp_path]
79-
break
80-
tmp_path = os.path.dirname(tmp_path)
81-
print(f"ADD [{i}:{permission}]")
82-
new_fs[sub(r'([^-_/a-zA-Z0-9])', r'\\\1', i)] = permission
68+
new_fs[selinux_path] = fs_file[i]
69+
continue
70+
permission = permission_d
71+
if i:
72+
# giữ logic cũ: thay ký tự không printable bằng '*'
73+
if not i.isprintable():
74+
i = ''.join(c if c.isprintable() else '*' for c in i)
75+
# giữ logic cũ: fix_permission
76+
if i in fix_permission:
77+
permission = fix_permission[i]
78+
else:
79+
# giữ nguyên logic tìm thư mục cha
80+
tmp_path = os.path.dirname(i)
81+
while tmp_path and tmp_path != "/":
82+
if tmp_path in fs_file:
83+
permission = fs_file[tmp_path]
84+
break
85+
tmp_path = os.path.dirname(tmp_path)
86+
print(f"ADD [{i}:{permission}]")
87+
new_fs[selinux_path] = permission
8388
return new_fs
8489

8590

0 commit comments

Comments
 (0)