Skip to content

Commit

Permalink
fix: correct multipart image merge path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Dec 24, 2024
1 parent c4cfe1e commit 49b9d8b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions __frzr-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,19 @@ handle_multipart_image() {
# 首先检查新格式(.partN-T)
local first_part=$(find "$dir_name" -maxdepth 1 -type f -name "${base_name_no_ext}.part1-*.img.*" | head -n1)
if [ -n "$first_part" ]; then
# 获取去除部分(partN-T)的实际后缀名
local real_ext=$(echo "$first_part" | sed "s/.*${base_name_no_ext}\.part1-[0-9]\+//")

local merged_file_name="${dir_name}/${base_name_no_ext}${real_ext}"

# 从文件名中提取总部分数
local total_parts=$(echo "$first_part" | grep -o 'part1-[0-9]*' | cut -d'-' -f2)
echo "Found multipart image with $total_parts parts (new format)" >&2

# 检查所有部分是否存在
local missing_parts=0
for ((i=1; i<=$total_parts; i++)); do
if [ ! -f "${dir_name}/${base_name_no_ext}.part${i}-${total_parts}.img."* ]; then
if [ ! -f "${dir_name}/${base_name_no_ext}.part${i}-${total_parts}${real_ext}" ]; then
echo "Missing part $i of $total_parts" >&2
missing_parts=1
break
Expand All @@ -194,18 +199,18 @@ handle_multipart_image() {

# 合并文件
echo "Merging parts..." >&2
: > "$base_file" # 清空或创建目标文件
: > "$merged_file_name" # 清空或创建目标文件
for ((i=1; i<=$total_parts; i++)); do
cat "${dir_name}/${base_name_no_ext}.part${i}-${total_parts}.img."* >> "$base_file"
cat "${dir_name}/${base_name_no_ext}.part${i}-${total_parts}${real_ext}" >> "$merged_file_name"
done

# 清理分包文件
echo "Cleaning up part files..." >&2
for ((i=1; i<=$total_parts; i++)); do
rm -f "${dir_name}/${base_name_no_ext}.part${i}-${total_parts}.img."*
rm -f "${dir_name}/${base_name_no_ext}.part${i}-${total_parts}${real_ext}"
done

echo "$base_file"
echo "$merged_file_name"
return 0
fi

Expand Down

0 comments on commit 49b9d8b

Please sign in to comment.