# Redesign Worktree save API and make test_rescan_simple pass · gitcafe/zed

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

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

Visibility: public

Requested revision: b7a4393f2904ffaa739459db15e5f51a4b58879b

Requested commit: b7a4393f2904ffaa739459db15e5f51a4b58879b

Commit: b7a4393f2904ffaa739459db15e5f51a4b58879b

Tree: 7f2ae1223748881a99bb89f546cec11c6c209bbc

Author: Nathan Sobo

Committer: Nathan Sobo

## Message

```
Redesign Worktree save API and make test_rescan_simple pass

This commit does too much. The first goal was to change our approach to saving new buffers so that we don't need to construct a File for an entry that doesn't exist. Rather than doing that, we call `Worktree::save_buffer_as` with the buffer handle, the path, and the contents. This then saves the buffer and returns a handle to a `File` that references an entry that actually exists. I needed to do this so that we can store an entry id on `File`.

In the process, I noticed intermittent test failures on `test_rescan_simple`, so I made some changes required to fix those related to our reuse of existing ids. Our previous approach of removing a path when inserting a new entry was broken, because of the recursive nature of `remove_path`. Instead, I simply recycle the id of an existing worktree entry with the same path if one is present, then allow it to be replaced.

```

## Parents

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

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