Description
Background
I am currently looking into Issue MO-4341 regarding backend-based file duplication.
Current Issues
-
Insufficient Backend File Operations:
The backend's file system API in marimo/_server/api/endpoints/file_explorer.py currently supports create, delete, and move operations, but copy is missing.
-
Heavy Frontend Workload:
Because of the missing backend support, the handleDuplicate function in frontend/src/components/editor/file-tree/file-explorer.tsx currently performs a "download then upload" round-trip.
- It fetches the full file content from the backend to the frontend.
- It immediately sends it back to the backend as a new file with a different name.
This is highly inefficient for large files and consumes unnecessary network bandwidth and memory.
-
Session-Locked Copy Endpoint:
While there is an existing /api/kernel/copy endpoint in marimo/_server/api/endpoints/files.py, it is tied to an active notebook session (app_state.require_current_session()). This makes it unusable for general workspace operations in the file explorer where a session might not exist.
Suggested solution
Introduce a general-purpose copy endpoint in marimo/_server/api/endpoints/file_explorer.py that:
- Does not require an active notebook session.
- Supports both files and directories.
- Leverages server-side utilities like
shutil.copy2 and shutil.copytree via OSFileSystem.
[!NOTE]
Copy logic is already implemented in marimo/_server/files/os_file_system.py within the safe_move function as a fallback mechanism. This makes the implementation of a copy operation very straightforward and consistent with existing patterns in the codebase.
If this proposal is acceptable, I would like to submit a PR for these changes.
Are you willing to submit a PR? (You must receive approval from the team before submitting a PR.)
Alternatives
No response
Additional context
No response
Description
Background
I am currently looking into Issue MO-4341 regarding backend-based file duplication.
Current Issues
Insufficient Backend File Operations:
The backend's file system API in
marimo/_server/api/endpoints/file_explorer.pycurrently supportscreate,delete, andmoveoperations, butcopyis missing.Heavy Frontend Workload:
Because of the missing backend support, the
handleDuplicatefunction infrontend/src/components/editor/file-tree/file-explorer.tsxcurrently performs a "download then upload" round-trip.This is highly inefficient for large files and consumes unnecessary network bandwidth and memory.
Session-Locked Copy Endpoint:
While there is an existing
/api/kernel/copyendpoint inmarimo/_server/api/endpoints/files.py, it is tied to an active notebook session (app_state.require_current_session()). This makes it unusable for general workspace operations in the file explorer where a session might not exist.Suggested solution
Introduce a general-purpose
copyendpoint inmarimo/_server/api/endpoints/file_explorer.pythat:shutil.copy2andshutil.copytreeviaOSFileSystem.If this proposal is acceptable, I would like to submit a PR for these changes.
Are you willing to submit a PR? (You must receive approval from the team before submitting a PR.)
Alternatives
No response
Additional context
No response