Skip to content

fix(server): 修复服务端文件名编码与终端乱码问题#79

Merged
yxsj245 merged 3 commits intoGSManagerXZ:mainfrom
hengwuming:feature/issue-75-mrpack-download-fix
Apr 7, 2026
Merged

fix(server): 修复服务端文件名编码与终端乱码问题#79
yxsj245 merged 3 commits intoGSManagerXZ:mainfrom
hengwuming:feature/issue-75-mrpack-download-fix

Conversation

@hengwuming
Copy link
Copy Markdown
Contributor

关联问题

Closes #78

变更内容

  • 为终端会话统一注入 UTF-8 locale,覆盖普通启动和 sudo/su 切换用户场景
  • 新增文件名编码检测工具,用于识别包含替换字符 的损坏文件名
  • ZIP 解压时优先使用 UTF-8;若解压失败或检测到损坏文件名,则自动回退到 GBK 重试

验证

  • cd server && npm run build
  • cd server && npm test -- --runInBand

说明

  • 这次修改主要防止后续继续产生乱码文件名

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

⚠ 本 PR 已进入自动化语法检查流程,请稍后

本次变更文件 (3 个):

  • server/src/modules/terminal/TerminalManager.ts (modified)
  • server/src/utils/filenameEncoding.ts (added)
  • server/src/utils/zipToolsManager.ts (modified)

正在进行 TypeScript 语法检查...

@yxsj245
Copy link
Copy Markdown
Collaborator

yxsj245 commented Apr 7, 2026

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b15d7142e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/src/utils/zipToolsManager.ts Outdated

// 确保目标目录存在
await fs.mkdir(targetDir, { recursive: true })
const tempBaseName = `.gsm3-zip-extract-${Date.now()}`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use collision-resistant temp dirs for ZIP retries

extractZip builds retry directories from Date.now() plus a fixed index, so two extractZip calls started in the same millisecond under the same parent can pick identical temp paths and race on rm/mkdir/extract. In that case one request can delete or overwrite the other request’s in-progress extraction, leading to intermittent failures or corrupted output in concurrent production workloads.

Useful? React with 👍 / 👎.

continue
}

await fs.copyFile(sourcePath, targetPath)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve symlinks when merging extracted files

The new merge step copies every non-directory entry with fs.copyFile, which does not preserve symlinks; symlink-to-file entries become regular files and symlink-to-directory entries can throw EISDIR. This means ZIPs containing symlinks (common in Unix-oriented packages) may now fail to extract or silently lose link structure, a regression from the previous direct extraction path.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

⚠ 本 PR 已进入自动化语法检查流程,请稍后

本次变更文件 (4 个):

  • server/src/__tests__/7z-extract-compress.test.ts (modified)
  • server/src/modules/terminal/TerminalManager.ts (modified)
  • server/src/utils/filenameEncoding.ts (added)
  • server/src/utils/zipToolsManager.ts (modified)

正在进行 TypeScript 语法检查...

@yxsj245
Copy link
Copy Markdown
Collaborator

yxsj245 commented Apr 7, 2026

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b25819be7a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +19 to +24
if (entry.isDirectory()) {
await mergeDirectoryContents(sourcePath, targetPath)
continue
}

await fs.copyFile(sourcePath, targetPath)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve symlink entries when merging extracted files

mergeDirectoryContents treats every non-directory entry as a regular file and calls fs.copyFile, which dereferences file symlinks and throws EISDIR for directory symlinks. That means ZIPs containing symlinks can now fail during finalize, or silently lose symlink semantics by turning links into plain files, whereas direct extraction previously kept the extractor’s output intact.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

符号链接问题可以暂时先不管

Comment thread server/src/utils/zipToolsManager.ts Outdated
Comment on lines +481 to +482
await mergeDirectoryContents(chosenTempDir, targetDir)
await fs.rm(chosenTempDir, { recursive: true, force: true })
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid duplicating the whole extracted tree before returning

After a successful decode attempt, the code always copies the entire temporary extraction tree into targetDir and only then deletes the temp directory. This introduces a guaranteed second full I/O pass and transiently requires roughly double disk space, so large ZIPs that used to fit can now fail with ENOSPC during the copy stage.

Useful? React with 👍 / 👎.

@yxsj245
Copy link
Copy Markdown
Collaborator

yxsj245 commented Apr 7, 2026

@hengwuming 接下来我来修复剩余问题

@hengwuming
Copy link
Copy Markdown
Contributor Author

@hengwuming 接下来我来修复剩余问题

我已经让gpt改好了

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

⚠ 本 PR 已进入自动化语法检查流程,请稍后

本次变更文件 (4 个):

  • server/src/__tests__/7z-extract-compress.test.ts (modified)
  • server/src/modules/terminal/TerminalManager.ts (modified)
  • server/src/utils/filenameEncoding.ts (added)
  • server/src/utils/zipToolsManager.ts (modified)

正在进行 TypeScript 语法检查...

@yxsj245
Copy link
Copy Markdown
Collaborator

yxsj245 commented Apr 7, 2026

@hengwuming 接下来我来修复剩余问题

我已经让gpt改好了

好 我看下

@yxsj245 yxsj245 merged commit 885d823 into GSManagerXZ:main Apr 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

中文乱码

2 participants