Skip to content

Commit cef7f6b

Browse files
committed
fix(script): 解决 set_perm 函数处理含空格文件名时的解析错误
- 为所有文件路径和参数变量添加双引号,防止 Shell 单词拆分 - set_perm_recursive 中改用 find -print0 和 read -r -d '',确保特殊字符与空格路径被完整传递
1 parent df26747 commit cef7f6b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/module/customize.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ dir_not_empty() {
7878
[ -d "$1" ] && [ "$(ls -A "$1" 2> /dev/null)" ]
7979
}
8080

81+
set_perm() {
82+
chown "$2:$3" "$1" || return 1
83+
chmod "$4" "$1" || return 1
84+
local CON="$5"
85+
[ -z "$CON" ] && CON="u:object_r:system_file:s0"
86+
chcon "$CON" "$1" || return 1
87+
}
88+
89+
set_perm_recursive() {
90+
find "$1" -type d -print0 2>/dev/null | while IFS= read -r -d '' dir; do
91+
set_perm "$dir" "$2" "$3" "$4" "$6"
92+
done
93+
94+
find "$1" \( -type f -o -type l \) -print0 2>/dev/null | while IFS= read -r -d '' file; do
95+
set_perm "$file" "$2" "$3" "$5" "$6"
96+
done
97+
}
98+
8199
################################################################################
82100
# 核心函数
83101
################################################################################
@@ -464,4 +482,4 @@ else
464482
ui_print " 并在 GitHub Issues 反馈"
465483
ui_print ""
466484
exit 1
467-
fi
485+
fi

0 commit comments

Comments
 (0)