Skip to content

fix: auto-rename on duplicate filename conflict#197

Merged
MaojiaSheng merged 1 commit intovolcengine:mainfrom
DevEverything01:fix/duplicate-filename-conflict
Feb 17, 2026
Merged

fix: auto-rename on duplicate filename conflict#197
MaojiaSheng merged 1 commit intovolcengine:mainfrom
DevEverything01:fix/duplicate-filename-conflict

Conversation

@DevEverything01
Copy link
Contributor

Problem

Closes #178

Uploading a file with the same name as an existing resource (e.g. uploading report.pdf twice) causes a 409 Conflict error from AGFS mkdir. This is especially problematic in multi-user (account) scenarios.

Root cause: TreeBuilder.finalize_from_temp() builds the final URI directly from the source filename without checking whether a resource at that URI already exists. The subsequent mkdir() call (without exist_ok=True) fails when the directory is already present.

Solution

Added _resolve_unique_uri() to TreeBuilder that:

  1. Checks if the target URI already exists via stat()
  2. If it does, appends _1, _2, … until a free name is found
  3. Behavior mirrors macOS Finder / Windows Explorer auto-rename

Example: uploading report.pdf three times produces:

  • viking://resources/report
  • viking://resources/report_1
  • viking://resources/report_2

Changes

  • openviking/parse/tree_builder.py: Added _resolve_unique_uri() method; updated finalize_from_temp() to use it
  • tests/misc/test_tree_builder_dedup.py: 5 new unit tests covering no-conflict, single conflict, multiple conflicts, max-attempts exceeded, and gap-in-sequence scenarios

Testing

pytest tests/misc/test_tree_builder_dedup.py -v
# 5 passed

When uploading a file with the same name as an existing resource,
TreeBuilder.finalize_from_temp() now auto-appends _1, _2, ... suffix
instead of crashing with a 409 Conflict from AGFS mkdir.

Root cause: finalize_from_temp built the final URI directly from the
source filename without checking whether a resource at that URI
already existed. The subsequent mkdir() call (without exist_ok=True)
failed when the directory was already present.

Fix: Add _resolve_unique_uri() that checks via stat() and finds the
first available name, similar to macOS Finder / Windows Explorer
behavior.

Closes volcengine#178
@CLAassistant
Copy link

CLAassistant commented Feb 17, 2026

CLA assistant check
All committers have signed the CLA.

@DevEverything01
Copy link
Contributor Author

Hi, I've signed the CLA and the workflow is awaiting approval.
Please let me know if any changes are needed. Thanks!

@MaojiaSheng MaojiaSheng merged commit 14795ff into volcengine:main Feb 17, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: 文件重名问题 < account 多用户场景下可能更明显>

3 participants