fix: dont overwrite symlink (#2131)

This commit is contained in:
Jakub Panek 2023-02-10 20:16:39 +01:00 committed by GitHub
parent 7186c2750c
commit eb4cde2f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -34,6 +34,7 @@
- [#2056](https://github.com/lapce/lapce/pull/2056): Fix default directory of remote session file picker
- [#2072](https://github.com/lapce/lapce/pull/2072): Fix connection issues from Windows to lapce proxy
- [#2069](https://github.com/lapce/lapce/pull/2045): Fix not finding git repositories in parent path
- [#2131](https://github.com/lapce/lapce/pull/2131): Fix overwriting symlink
## 0.2.5

View File

@ -54,20 +54,22 @@ pub fn save(&mut self, rev: u64) -> Result<()> {
ext
},
);
let tmp_path = &self.path.with_extension(tmp_extension);
let path = self.path.canonicalize()?;
let tmp_path = &path.with_extension(tmp_extension);
let mut f = File::create(tmp_path)?;
for chunk in self.rope.iter_chunks(..self.rope.len()) {
f.write_all(chunk.as_bytes())?;
}
if let Ok(metadata) = fs::metadata(&self.path) {
if let Ok(metadata) = fs::metadata(&path) {
let perm = metadata.permissions();
fs::set_permissions(tmp_path, perm)?;
}
fs::rename(tmp_path, &self.path)?;
self.mod_time = get_mod_time(&self.path);
fs::rename(tmp_path, &path)?;
self.mod_time = get_mod_time(&path);
Ok(())
}