mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 12:32:06 +08:00
refactor: Simplify error handling in Cursor file modification logic
- Removed unnecessary curly braces in error handling blocks - Improved code readability by simplifying conditional statements - Maintained existing file modification and validation approach - Ensured consistent script error handling pattern
This commit is contained in:
parent
63beebef24
commit
d8810042f1
@ -230,7 +230,7 @@ modify_cursor_app_files() {
|
|||||||
if [ ! -f "$file" ]; then
|
if [ ! -f "$file" ]; then
|
||||||
log_warn "文件不存在: $file"
|
log_warn "文件不存在: $file"
|
||||||
continue
|
continue
|
||||||
}
|
fi
|
||||||
|
|
||||||
# 创建备份
|
# 创建备份
|
||||||
local backup_file="${file}.bak"
|
local backup_file="${file}.bak"
|
||||||
@ -258,7 +258,7 @@ modify_cursor_app_files() {
|
|||||||
log_warn "在文件 $file 中未找到 $uuid_pattern"
|
log_warn "在文件 $file 中未找到 $uuid_pattern"
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
continue
|
continue
|
||||||
}
|
fi
|
||||||
|
|
||||||
# 构建替换内容
|
# 构建替换内容
|
||||||
local replacement='case "IOPlatformUUID": return crypto.randomUUID();'
|
local replacement='case "IOPlatformUUID": return crypto.randomUUID();'
|
||||||
@ -268,28 +268,28 @@ modify_cursor_app_files() {
|
|||||||
log_error "处理文件内容失败: $file"
|
log_error "处理文件内容失败: $file"
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
continue
|
continue
|
||||||
}
|
fi
|
||||||
|
|
||||||
# 验证临时文件
|
# 验证临时文件
|
||||||
if [ ! -s "$temp_file" ]; then
|
if [ ! -s "$temp_file" ]; then
|
||||||
log_error "生成的文件为空: $file"
|
log_error "生成的文件为空: $file"
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
continue
|
continue
|
||||||
}
|
fi
|
||||||
|
|
||||||
# 验证文件内容是否包含必要的代码
|
# 验证文件内容是否包含必要的代码
|
||||||
if ! grep -q "crypto.randomUUID()" "$temp_file"; then
|
if ! grep -q "crypto.randomUUID()" "$temp_file"; then
|
||||||
log_error "修改后的文件缺少必要的代码: $file"
|
log_error "修改后的文件缺少必要的代码: $file"
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
continue
|
continue
|
||||||
}
|
fi
|
||||||
|
|
||||||
# 替换原文件
|
# 替换原文件
|
||||||
if ! mv "$temp_file" "$file"; then
|
if ! mv "$temp_file" "$file"; then
|
||||||
log_error "无法更新文件: $file"
|
log_error "无法更新文件: $file"
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
continue
|
continue
|
||||||
}
|
fi
|
||||||
|
|
||||||
# 设置权限
|
# 设置权限
|
||||||
chmod 644 "$file"
|
chmod 644 "$file"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user