fix(sandbox): rollback EXDEV dir move on size-check failure to preserve source tree

This commit is contained in:
Cursor Agent 2026-03-19 02:11:27 +00:00
parent 535f914b70
commit 49a5b3ff69
No known key found for this signature in database

View File

@ -146,6 +146,14 @@ export const SANDBOX_PINNED_MUTATION_PYTHON = [
" try:",
" for child in os.listdir(src_dir_fd):",
" move_entry(src_dir_fd, child, temp_dir_fd, child)",
" except Exception:",
" # Rollback: move children from temp_dir back to source to preserve original tree.",
" # Without this, a size-check failure on a later child leaves earlier children stranded",
" # in the hidden temp dir and the source partially deleted.",
" for child in os.listdir(temp_dir_fd):",
" move_entry(temp_dir_fd, child, src_dir_fd, child)",
" remove_tree(dst_parent_fd, temp_dir_name)",
" raise",
" finally:",
" os.close(src_dir_fd)",
" os.close(temp_dir_fd)",