isomorphic-git / isomorphic-git/lightning-fs
pfs.rename deletes file if oldFilepath and newFilepath are equal
- Dominant language
- JavaScript
- Stars
- 610
- Forks
- 62
- Avg merge
- 14h 47m
- Merged PRs (30d)
- 1
Description
This seems related to #23. If `oldFilepath` and `newFilepath` are equal, then the file is deleted; I'm not sure if this is the default node fs behavior, but we can see this is because the old file is deleted after the new file is inserted [here](https://github.com/isomorphic-git/lightning-fs/blob/master/src/CacheFS.js#L202):
```js
rename(oldFilepath, newFilepath) {
let basename = path.basename(newFilepath);
// Note: do both lookups before making any changes
// so if lookup throws, we don't lose data (issue #23)
// grab references
let entry = this._lookup(oldFilepath);
let destDir = this._lookup(path.dirname(newFilepath));
// insert into new parent directory
destDir.set(basename, entry);
// remove from old parent directory
this.unlink(oldFilepath)
}
```
A simple fix would be to check for that condition, and return without doing anything:
```js
rename(oldFilepath, newFilepath) {
if (oldFilepath == newFilepath)
return;
...
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.