Skip to content

Follow-up from PR #8 / Issue #3: Copilot post-merge feedback on cross_copy_single #11

Description

@koraytaylan

Context
This is follow-up work from the late Copilot review on the already-merged PR #8 (which addressed the original #3 recursion risk in cross_copy_single).

Copilot posted three comments after the merge. They are all valid points that were not addressed in the original PR.

Copilot comments (all on backend/src/commands/file.rs):

  1. Cancellation granularity (line ~224)

    cross_copy_single can take a long time for a single large directory tree, but cancellation is only checked in run_cross_copy_loop/run_cross_move_loop between top-level paths. Once a deep/wide directory copy starts, a user cancellation request won’t be observed until the entire tree finishes. Consider threading cancel_flag into cross_copy_single and checking it inside the while let Some(...) loop (returning Cancelled/an error) so cross-disk copy/move remains cooperatively cancellable at a finer granularity.

  2. BFS memory usage for wide trees (line ~220)

    The new BFS work-queue enqueues (src_path, dst_path) strings for every discovered child before processing them. For very wide directory trees, this can substantially increase peak heap usage vs the prior depth-first walk (which only needed one child_dst at a time). If memory blow-up on wide trees is a concern, consider switching to an explicit DFS stack (LIFO) or a heap-backed recursion emulation that processes a child immediately while keeping only “iterator state” for pending siblings.

  3. Test comment accuracy (line ~1112)

    The test comment claims this depth “would have overflowed before”, but the historical overflow risk described in Eliminate deep recursion risk in cross-disk directory copy (cross_copy_single) #3 is at thousands of levels; ~60 levels is unlikely to reproduce the prior failure mode and may not fail under the old recursive implementation. Suggest rewording to say it’s a regression guard against reintroducing recursion (and/or increase the depth enough to actually exercise the previous limit, if feasible within test runtime).

Links

Acceptance criteria for this follow-up

  • Decide on approach for cancellation (pass Arc<AtomicBool> or similar into cross_copy_single and check inside the loop)
  • Decide whether to keep BFS + document the memory trade-off, switch to DFS stack, or add a hybrid/lazy strategy
  • Improve the deep-directory test comment (and optionally increase depth or add a note)
  • Keep all existing tests + clippy clean
  • No behavior change for callers (run_cross_*_loop, Tauri commands, progress, etc.)
  • Open PR with “Closes #X” (new issue number) + clear explanation of the three points and chosen resolutions

Out of scope

  • Changing the public API of the cross-copy functions beyond what is necessary for cancellation
  • Adding new dependencies

This issue was created because the original PR was merged before Copilot’s review arrived.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions