Skip to content

Cli/extract/fix symlink extract#2947

Merged
ChanTsune merged 2 commits into
mainfrom
cli/extract/fix-symlink-extract
Apr 12, 2026
Merged

Cli/extract/fix symlink extract#2947
ChanTsune merged 2 commits into
mainfrom
cli/extract/fix-symlink-extract

Conversation

@ChanTsune

@ChanTsune ChanTsune commented Apr 12, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Refactor
    • Improved internal extraction logic by introducing more specialized handling for different entry types, enhancing code maintainability and clarity while preserving existing functionality.

Split the monolithic extract_entry function into four helper functions
organized by DataKind:

- prepare_extraction: shared preamble (path build + overwrite check)
- extract_file_entry: regular file extraction (safe writes, timestamps)
- extract_directory_entry: directory structure + metadata restoration
- extract_link_entry: symbolic and hard link extraction

All dispatch sites in run_extract_archive_reader (streaming non-WASM,
WASM fast_read/normal) and run_extract_archive (memmap) now call the
type-specific handler directly. WASM closures gained a new Directory
branch that previously fell through to extract_entry.

Pure refactoring — no behavior change. The deferred directory metadata
fix is introduced in a follow-up commit.
Replace debug_assert with unreachable! for DataKind validation in
extract_link_entry and add equivalent checks to extract_file_entry
and extract_directory_entry to restore compile-time safety lost
during the extract_entry decomposition.
@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR refactors extraction logic in cli/src/command/extract.rs by replacing a unified extract_entry() function with three specialized extractors for files, directories, and links, plus a shared prepare_extraction() helper for common preprocessing tasks.

Changes

Cohort / File(s) Summary
Extraction Function Refactoring
cli/src/command/extract.rs
Removed unified extract_entry() and introduced extract_file_entry(), extract_directory_entry(), and extract_link_entry() to handle each entry type separately. Added prepare_extraction() helper to centralize output-path building, overwrite-policy decisions, and target preparation. Updated callsites to explicitly route entries based on DataKind instead of conditional branching within a single function. Error handling and metadata restoration logic preserved across new functions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

cli

Poem

🐰 One function splits in three,
File, dir, and link set free,
Each path now clear and true,
Extraction work, refined and new! 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title refers to fixing symlink extraction, but the changeset primarily refactors the extraction implementation into separate file, directory, and link handlers with significant structural reorganization beyond just symlink fixes. Consider a more accurate title like 'Refactor extraction into type-specific handlers' or 'Separate file, directory, and link extraction logic' to better reflect the comprehensive refactoring.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli/extract/fix-symlink-extract

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the archive extraction logic by decomposing the extract_entry function into specialized handlers for files, directories, and links, supported by a new prepare_extraction helper. The review feedback recommends replacing unreachable! macros with explicit io::Error returns in the file and directory extraction functions to enhance error handling and prevent potential panics if new data types are introduced.

Comment thread cli/src/command/extract.rs
Comment thread cli/src/command/extract.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cli/src/command/extract.rs (1)

1364-1420: ⚠️ Potential issue | 🔴 Critical

Validate the link target before mutating the destination.

prepare_extraction() can remove an existing path or create parent directories before the link payload is even read. If the symlink is rejected at Lines 1381-1386, or the hardlink is skipped at Lines 1395-1402 / 1406-1410, extraction returns successfully after already changing the filesystem. In overwrite flows that can silently delete the previous entry at path without replacing it.

Please resolve and validate the link target first, then run the mutating prepare/remove step.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/src/command/extract.rs` around lines 1364 - 1420, prepare_extraction
currently mutates the filesystem before the link target is validated, which can
delete the existing entry at path even if the symlink/hardlink is later
rejected; to fix, defer or avoid the mutating steps until after validating the
link target: first open the payload with
item.reader(ReadOptions::with_password(password)) and run
pathname_editor.edit_symlink(...) or pathname_editor.edit_hardlink(...) and
is_unsafe_link checks (and handle the None case for edit_hardlink and
warned_lead_slash logic) to decide whether to proceed, and only after those
validations call the mutating prepare/remove logic (the code that uses
remove_existing, utils::fs::remove_path(...) and safe_writes) and finally create
the link with utils::fs::symlink(...) or fs::hard_link(...).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@cli/src/command/extract.rs`:
- Around line 1364-1420: prepare_extraction currently mutates the filesystem
before the link target is validated, which can delete the existing entry at path
even if the symlink/hardlink is later rejected; to fix, defer or avoid the
mutating steps until after validating the link target: first open the payload
with item.reader(ReadOptions::with_password(password)) and run
pathname_editor.edit_symlink(...) or pathname_editor.edit_hardlink(...) and
is_unsafe_link checks (and handle the None case for edit_hardlink and
warned_lead_slash logic) to decide whether to proceed, and only after those
validations call the mutating prepare/remove logic (the code that uses
remove_existing, utils::fs::remove_path(...) and safe_writes) and finally create
the link with utils::fs::symlink(...) or fs::hard_link(...).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a45dc65-2a5c-486b-aeb7-7f3634616a30

📥 Commits

Reviewing files that changed from the base of the PR and between e6503ae and 95e3bfe.

📒 Files selected for processing (1)
  • cli/src/command/extract.rs

@github-actions github-actions Bot added the cli This issue is about cli application label Apr 12, 2026
@ChanTsune
ChanTsune merged commit f7ada40 into main Apr 12, 2026
110 checks passed
@ChanTsune
ChanTsune deleted the cli/extract/fix-symlink-extract branch April 12, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli This issue is about cli application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant