Skip to content

Scripts: Fallback to CP + rm for cross-disk dir move in generate task#34755

Merged
JReinhold merged 1 commit into
nextfrom
fix/generate_movedir
May 12, 2026
Merged

Scripts: Fallback to CP + rm for cross-disk dir move in generate task#34755
JReinhold merged 1 commit into
nextfrom
fix/generate_movedir

Conversation

@huang-julien
Copy link
Copy Markdown
Contributor

@huang-julien huang-julien commented May 9, 2026

Closes #

What I did

This PR fallback rename to cp + rm. rename() can throw if it tries to rename dir across disk volumes, especially on windows

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Try a generate task on windows but with temp dir being on C: and the storybook repo on another disk

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Chores
    • Improved sandbox generation reliability by enhancing directory movement logic to handle cross-device scenarios.

Review Change Stack

@huang-julien huang-julien added build Internal-facing build tooling & test updates ci:merged Run the CI jobs that normally run when merged. labels May 9, 2026
@huang-julien huang-julien changed the title Scripts: fallback to CP + rm for cross-disk dir move Scripts: Fallback to CP + rm for cross-disk dir move in generate task May 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

📝 Walkthrough

Walkthrough

The PR adds a moveDir helper function to handle cross-device rename failures in the sandbox generator, with a fallback to recursive copy and remove when rename fails with EXDEV error. The generator pipeline now uses this helper when moving the created before directory into its final location.

Changes

Sandbox Generation Robustness

Layer / File(s) Summary
Directory Move Helper
scripts/sandbox/generate.ts
New moveDir(from, to) function attempts rename first, then falls back to cp -r plus rm -rf on EXDEV cross-device errors.
Generator Integration
scripts/sandbox/generate.ts
Generator pipeline replaces rename(createBeforeDir, beforeDir) with moveDir(createBeforeDir, beforeDir) for robust directory transfer.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
scripts/sandbox/generate.ts (1)

88-100: 💤 Low value

LGTM! The cross-device fallback logic is sound.

The implementation correctly catches the EXDEV error from rename() and falls back to copy+remove, solving the cross-disk move issue described in the PR.

The approach is safe: only the specific cross-device error triggers the fallback, and all other errors are re-thrown. The non-atomicity of the fallback (cp → rm) is an inherent limitation but acceptable for this use case.

Optional: Consider adding debug logging for the fallback path.

Since the fallback happens silently, it may be helpful to log when the cross-device scenario occurs for debugging and visibility, especially given the non-atomic nature of the fallback operation.

📝 Optional logging enhancement
 const moveDir = async (from: string, to: string): Promise<void> => {
   try {
     await rename(from, to);
   } catch (error) {
     // On some platforms (notably Windows), rename doesn't work across different disks volumes
     if ((error as NodeJS.ErrnoException).code !== 'EXDEV') {
       throw error;
     }
+    console.log(`⚠️  Cross-device move detected, falling back to copy+remove: ${from} → ${to}`);
 
     await cp(from, to, { recursive: true });
     await rm(from, { recursive: true, force: true });
   }
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/sandbox/generate.ts` around lines 88 - 100, Add a debug/info log in
moveDir to report when the EXDEV fallback path is taken and include the source
and destination paths and the caught error; specifically, inside the catch block
for rename in function moveDir, before calling cp and rm, emit a concise log
(using the project's logger convention or console if none exists) like "rename
EXDEV fallback: moving from {from} to {to}" plus the error details so operators
can see cross-device moves and the associated error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/sandbox/generate.ts`:
- Around line 88-100: Add a debug/info log in moveDir to report when the EXDEV
fallback path is taken and include the source and destination paths and the
caught error; specifically, inside the catch block for rename in function
moveDir, before calling cp and rm, emit a concise log (using the project's
logger convention or console if none exists) like "rename EXDEV fallback: moving
from {from} to {to}" plus the error details so operators can see cross-device
moves and the associated error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 41e6610b-33ba-4604-8a9b-e656fe7a150b

📥 Commits

Reviewing files that changed from the base of the PR and between b2167d6 and 11d2760.

📒 Files selected for processing (1)
  • scripts/sandbox/generate.ts

@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 11d2760, ran on 9 May 2026 at 12:08:58 UTC

The following packages have significant changes to their size or dependencies:

@storybook/cli

Before After Difference
Dependency count 194 194 0
Self size 906 KB 890 KB 🎉 -16 KB 🎉
Dependency size 84.49 MB 84.49 MB 🚨 +665 B 🚨
Bundle Size Analyzer Link Link

@huang-julien huang-julien requested a review from JReinhold May 11, 2026 07:44
@JReinhold JReinhold merged commit daa197d into next May 12, 2026
202 of 208 checks passed
@JReinhold JReinhold deleted the fix/generate_movedir branch May 12, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:human build Internal-facing build tooling & test updates ci:merged Run the CI jobs that normally run when merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants