# fs: Fix \`copy_recursive\` \(\#25317\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/1f257f4704a571998f79745e5569e454aa18d466)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 1f257f4704a571998f79745e5569e454aa18d466

Requested commit: 1f257f4704a571998f79745e5569e454aa18d466

Commit: 1f257f4704a571998f79745e5569e454aa18d466

Tree: 0d596471930786eaab56a1fd568130049e73f475

Author: 张小白

Committer: GitHub

## Message

```
fs: Fix `copy_recursive` (#25317)

Closes #24746

This PR modifies the implementation of `copy_recursive`. Previously, we
were copying and pasting simultaneously, which caused an issue when a
user copied a folder into one of its subfolders. This resulted in new
content being created in the folder while copying, and subsequent
recursive calls to `copy_recursive` would continue this process, leading
to an infinite loop.

In this PR, the approach has been changed: we now first collect the
paths of the files to be copied, and only then perform the copy
operation.

Additionally, I have added corresponding tests. On the main branch, this
test would previously run indefinitely.

Release Notes:

- Fixed `copy_recursive` runs infinitely when copying a folder into its
subfolder.
```

## Parents

- [f517050548fb81aaad159b44b0d6183961fc305d](https://git.cafe/gitcafe/zed/commit/f517050548fb81aaad159b44b0d6183961fc305d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/1f257f4704a571998f79745e5569e454aa18d466?format=markdown)
