Skip to content

feat: backend-based file and directory duplication#9142

Merged
Light2Dark merged 5 commits intomarimo-team:mainfrom
daizutabi:feat-copy-endpoint
Apr 17, 2026
Merged

feat: backend-based file and directory duplication#9142
Light2Dark merged 5 commits intomarimo-team:mainfrom
daizutabi:feat-copy-endpoint

Conversation

@daizutabi
Copy link
Copy Markdown
Contributor

📝 Summary

Closes #9059

Implements a native server-side file and directory duplication feature. This addresses performance issues with large files and enables workspace-wide duplication independent of active notebook sessions.

This PR implements the functionality required for Issue #6877.

Changes

  • Backend (OSFileSystem):
    • Added copy_file_or_directory method using shutil for server-side operations.
  • API:
    • Added a new general-purpose /api/files/copy endpoint in file_explorer.py.
  • Frontend:
    • Added sendCopyFileOrFolder network request.
    • Updated RequestingTree to handle duplication and tree state synchronization.
  • WASM:
    • Updated PyodideBridge to support the new duplication functionality.

Testing

  • Backend: Added unit tests for _generate_unique_path in tests/_server/files/test_os_file_system.py. Added API integration tests in tests/_server/api/endpoints/test_file_explorer.py.
  • Frontend: Added unit tests for RequestingTree.copy in frontend/src/components/editor/file-tree/__tests__/requesting-tree.test.ts.
  • WASM: Added duplication test in tests/_pyodide/test_pyodide_session.py.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 14, 2026 11:52am

Request Review

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2026

Bundle Report

Changes will increase total bundle size by 2.66kB (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
marimo-esm 24.85MB 2.66kB (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: marimo-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-*.js 204 bytes 602.62kB 0.03%
assets/dist-*.js 4 bytes 164 bytes 2.5%
assets/dist-*.js -155 bytes 104 bytes -59.85%
assets/dist-*.js -204 bytes 183 bytes -52.71%
assets/dist-*.js -198 bytes 137 bytes -59.1%
assets/dist-*.js -16 bytes 387 bytes -3.97%
assets/dist-*.js 74 bytes 176 bytes 72.55% ⚠️
assets/dist-*.js 139 bytes 276 bytes 101.46% ⚠️
assets/dist-*.js -23 bytes 160 bytes -12.57%
assets/dist-*.js 87 bytes 256 bytes 51.48% ⚠️
assets/dist-*.js -46 bytes 137 bytes -25.14%
assets/dist-*.js 266 bytes 403 bytes 194.16% ⚠️
assets/dist-*.js 5 bytes 169 bytes 3.05%
assets/dist-*.js 158 bytes 335 bytes 89.27% ⚠️
assets/dist-*.js -2 bytes 102 bytes -1.92%
assets/dist-*.js 14 bytes 183 bytes 8.28% ⚠️
assets/dist-*.js 83 bytes 259 bytes 47.16% ⚠️
assets/dist-*.js -79 bytes 177 bytes -30.86%
assets/dist-*.js -107 bytes 169 bytes -38.77%
assets/worker-*.js 25 bytes 85.01kB 0.03%
assets/file-*.js 2.31kB 49.35kB 4.92%
assets/state-*.js 117 bytes 24.17kB 0.49%
assets/ttcn-*.js -7 bytes 57 bytes -10.94%
assets/ttcn-*.js 7 bytes 64 bytes 12.28% ⚠️

Files in assets/index-*.js:

  • ./src/core/network/requests-network.ts → Total Size: 11.39kB

  • ./src/core/network/requests-toasting.tsx → Total Size: 5.07kB

  • ./src/core/network/requests-static.ts → Total Size: 3.31kB

  • ./src/core/network/requests-lazy.ts → Total Size: 3.84kB

Files in assets/file-*.js:

  • ./src/components/editor/file-tree/requesting-tree.tsx → Total Size: 5.34kB

  • ./src/components/editor/file-tree/state.tsx → Total Size: 574 bytes

  • ./src/components/editor/file-tree/file-explorer.tsx → Total Size: 30.67kB

Files in assets/state-*.js:

  • ./src/core/wasm/bridge.ts → Total Size: 11.03kB

@Light2Dark Light2Dark added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Apr 12, 2026
@Light2Dark Light2Dark requested a review from Copilot April 12, 2026 16:36
Copy link
Copy Markdown
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

Implements a server-side file/directory duplication feature, exposing it via a new /api/files/copy endpoint and wiring it through the frontend file tree (including WASM/Pyodide) to avoid “download then upload” duplication for large files.

Changes:

  • Added backend filesystem + API support for copying files/directories (OSFileSystem.copy_file_or_directory, /api/files/copy).
  • Updated frontend request layer + file tree state to invoke backend copy and sync tree state.
  • Extended OpenAPI/WASM bridge types and added tests across backend, frontend, and Pyodide.

Reviewed changes

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

Show a summary per file
File Description
tests/_server/files/test_os_file_system.py Adds unit tests for unique-path generation helper used by filesystem operations.
tests/_server/api/endpoints/test_file_explorer.py Adds API integration tests for the new copy endpoint for both files and directories.
tests/_pyodide/test_pyodide_session.py Adds a Pyodide bridge test covering the new copy behavior.
packages/openapi/src/api.ts Adds generated OpenAPI client typings for /api/files/copy and copy request/response schemas.
packages/openapi/api.yaml Adds OpenAPI schema + path definition for /api/files/copy.
marimo/_server/models/files.py Introduces FileCopyRequest/FileCopyResponse models.
marimo/_server/files/os_file_system.py Implements copy_file_or_directory and factors unique-name logic into _generate_unique_path.
marimo/_server/files/file_system.py Extends the filesystem abstract interface with copy_file_or_directory.
marimo/_server/api/endpoints/file_explorer.py Adds /copy endpoint under the file explorer API router.
marimo/_pyodide/pyodide_session.py Exposes copy via the Pyodide session bridge.
marimo/_cli/development/commands.py Includes new copy request/response models in API schema generation.
frontend/src/core/wasm/worker/worker.ts Ensures copy operations are treated as requiring sync in the worker.
frontend/src/core/wasm/worker/types.ts Adds copy_file_or_directory to the RawBridge interface.
frontend/src/core/wasm/bridge.ts Adds sendCopyFileOrFolder implementation to the Pyodide bridge.
frontend/src/core/network/types.ts Exposes FileCopyRequest/FileCopyResponse types and adds copy to EditRequests.
frontend/src/core/network/requests-toasting.tsx Adds default error toast text for copy requests.
frontend/src/core/network/requests-static.ts Adds static (non-edit-mode) stub for copy requests.
frontend/src/core/network/requests-network.ts Adds network request implementation for /api/files/copy.
frontend/src/core/network/requests-lazy.ts Adds lazy-request action mapping for copy requests.
frontend/src/core/islands/bridge.ts Adds copy request stub for islands bridge.
frontend/src/components/editor/file-tree/state.tsx Wires copy request into RequestingTree construction.
frontend/src/components/editor/file-tree/requesting-tree.tsx Adds copy() method to perform copy + update tree state.
frontend/src/components/editor/file-tree/file-explorer.tsx Switches duplicate action to use backend copy via RequestingTree.copy.
frontend/src/components/editor/file-tree/tests/requesting-tree.test.ts Adds unit tests for RequestingTree.copy and error handling.
frontend/src/mocks/requests.ts Updates mocked request client with sendCopyFileOrFolder.

Comment thread marimo/_server/files/os_file_system.py
Comment thread marimo/_server/files/os_file_system.py
Comment thread frontend/src/components/editor/file-tree/requesting-tree.tsx
Comment thread marimo/_server/api/endpoints/file_explorer.py
daizutabi and others added 5 commits April 14, 2026 09:00
- Introduce /api/files/copy endpoint in file_explorer.py for session-independent duplication.
- Add copy_file_or_directory to FileSystem and implement it in OSFileSystem using shutil.copy2 and shutil.copytree.
- Refactor OSFileSystem to use standalone copy, delete, and check_new_path helpers, ensuring consistency between copy and move operations.
- Enhance file explorer tests with comprehensive copy scenarios and robust move verification.
- Fix logging typo in move endpoint.

fix: register FileCopy models in OpenAPI schema

This fixes the fe-codegen error by including FileCopyRequest and FileCopyResponse
in the OpenAPI schema generation list.

feat: implement file and folder copy functionality across the application

feat: implement file and directory copy functionality with unique naming

feat: add copy functionality for files and directories in tests and UI
@Light2Dark Light2Dark merged commit e4021a3 into marimo-team:main Apr 17, 2026
50 checks passed
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.2-dev42

@daizutabi daizutabi deleted the feat-copy-endpoint branch April 17, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend-based general-purpose file/directory duplication

4 participants