Skip to content

Backend-based general-purpose file/directory duplication #9059

@daizutabi

Description

@daizutabi

Description

Background

I am currently looking into Issue MO-4341 regarding backend-based file duplication.

Current Issues

  1. 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.

  2. 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.
  3. 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.)

  • Yes

Alternatives

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions