Skip to content

Comments

导出日志时允许重名文件#4733

Merged
Glavo merged 6 commits intoHMCL-dev:mainfrom
Glavo:export-log
Jan 23, 2026
Merged

导出日志时允许重名文件#4733
Glavo merged 6 commits intoHMCL-dev:mainfrom
Glavo:export-log

Conversation

@Glavo
Copy link
Member

@Glavo Glavo commented Oct 28, 2025

No description provided.

Copilot AI review requested due to automatic review settings October 28, 2025 13:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for allowing duplicate filenames when exporting game logs to a ZIP file. When duplicate entries are encountered, the system will automatically append a numeric suffix (e.g., .1, .2) to avoid conflicts, with a maximum of 10 attempts before throwing an exception.

Key changes:

  • Modified Zipper class to optionally track entry names and handle duplicates by appending numeric suffixes
  • Updated LogExporter to enable duplicate entry handling when creating log export archives

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/Zipper.java Added duplicate entry handling mechanism with allowDuplicateEntry flag and newEntry() method to generate unique names
HMCL/src/main/java/org/jackhuang/hmcl/game/LogExporter.java Enabled duplicate entry support when creating the zipper for log exports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Glavo added 3 commits October 28, 2025 21:41
# Conflicts:
#	HMCL/src/main/java/org/jackhuang/hmcl/game/LogExporter.java
@Glavo Glavo requested a review from Copilot January 3, 2026 13:39
@Glavo Glavo linked an issue Jan 3, 2026 that may be closed by this pull request
@Glavo Glavo changed the title 导出游戏日志时允许重名文件 导出日志时允许重名文件 Jan 3, 2026
@Glavo Glavo marked this pull request as draft January 3, 2026 13:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Glavo Glavo requested a review from Copilot January 3, 2026 13:51
@Glavo Glavo marked this pull request as ready for review January 3, 2026 13:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 336 to 341
for (long i = 0; ; i++) {
String newName = name + "." + i;
if (entryNames.add(newName)) {
return newName;
}
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

This infinite loop could potentially run forever if there's an issue with the Set implementation or if Long.MAX_VALUE duplicates are encountered. While extremely unlikely in practice, consider adding a reasonable upper bound (e.g., 1000 or 10000) and throwing an exception if that limit is reached, similar to what's done in Zipper.newEntry(). This would make the behavior more predictable and prevent potential infinite loops.

Suggested change
for (long i = 0; ; i++) {
String newName = name + "." + i;
if (entryNames.add(newName)) {
return newName;
}
}
for (int i = 0; i < 10_000; i++) {
String newName = name + "." + i;
if (entryNames.add(newName)) {
return newName;
}
}
throw new IllegalStateException("Failed to generate unique entry name for \"" + name + "\" after 10000 attempts");

Copilot uses AI. Check for mistakes.
Comment on lines 336 to 340
for (long i = 0; ; i++) {
String newName = name + "." + i;
if (entryNames.add(newName)) {
return newName;
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

The duplicate naming strategy is inconsistent with Zipper.newEntry(), which uses a 1-based counter (e.g., "file.1", "file.2"). This implementation uses a 0-based counter (e.g., "file.0", "file.1"). For consistency and better user experience across the application, both implementations should use the same numbering scheme. Consider starting from 1 instead of 0 to match the Zipper implementation, or align both to start from 0.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

应当直接迁移导出日志的逻辑到 Zipper 以共享逻辑。

Copy link
Member Author

Choose a reason for hiding this comment

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

这里的逻辑更稳定,能够区分读取文件时发生的异常和写入文件时发生的异常,并在读取文件异常时跳过该文件处理其他文件。

这种稳定性对于导出启动器日志有意义,因为我们需要启动器日志才能 DEBUG,所以我们希望避免在导出启动器日志时发生任何意外,但是对于 Zipper 来说并没有这种需求,所以我不认为它们应该共享代码。

@Glavo Glavo merged commit 95eeae4 into HMCL-dev:main Jan 23, 2026
2 checks passed
@Glavo Glavo deleted the export-log branch January 23, 2026 14:41
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.

[Bug] 导出日志时报错 duplicate entry

2 participants