Skip to content

fix: allow strip_archive_path_components to strip a dir containing the same filename#6405

Merged
jdx merged 5 commits intojdx:mainfrom
risu729:untar-same-dir-file-names
Sep 25, 2025
Merged

fix: allow strip_archive_path_components to strip a dir containing the same filename#6405
jdx merged 5 commits intojdx:mainfrom
risu729:untar-same-dir-file-names

Conversation

@risu729
Copy link
Contributor

@risu729 risu729 commented Sep 25, 2025

mv .../age-plugin-yubikey/age-plugin-yubikey .../age-plugin-yubikey fails, so we need to rename the dir before moving the file.

Copilot AI review requested due to automatic review settings September 25, 2025 03:44
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 fixes an issue in the archive path stripping functionality where it previously failed when a directory contained a file with the same name as the directory. The fix implements a temporary rename strategy to avoid filename conflicts during the file moving process.

  • Replaces the previous two-phase approach (collect all files first, then move) with a safer single-phase approach
  • Introduces temporary directory renaming to prevent conflicts when moving files out of directories
  • Simplifies the logic by processing directories one at a time instead of collecting all entries first

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

risu729 and others added 4 commits September 25, 2025 13:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jdx
Copy link
Owner

jdx commented Sep 25, 2025

Bugbot run

"{}_tmp_strip",
path.file_name().unwrap().to_string_lossy()
));
fs::rename(&path, &temp_path)?;
Copy link

Choose a reason for hiding this comment

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

Bug: Temporary Directory Collision Blocks Extraction

The temporary directory name generated by appending _tmp_strip could collide with an existing file or directory. This collision causes fs::rename to fail, stopping the archive extraction.

Fix in Cursor Fix in Web

Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to rename the parent directory with a unique name, so I think we cannot directly use the tempfile crate.
We can use it to get a unique directory name, but it creates a tempdir and removes it immediately, so I think it's not good for performance.

Also, the directory name with _tmp_strip could collide, but I believe it's not a common case.

@jdx jdx merged commit a611841 into jdx:main Sep 25, 2025
18 checks passed
@jdx jdx mentioned this pull request Sep 25, 2025
@risu729 risu729 deleted the untar-same-dir-file-names branch September 26, 2025 01:05
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.

3 participants