Skip to content

Commit

Permalink
Fixes to file syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Cieslak committed Jan 7, 2025
1 parent cd207c7 commit d80c707
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ fn sync_to_disk(doc: &FullTextDocument, uri: &Uri) -> io::Result<()> {
.write(true)
.create(true)
.read(true)
.open(path.as_str())
.unwrap();
.truncate(true)
.open(path.as_str())?;

let mut buf = String::new();
file.read_to_string(&mut buf)?;
let file_hash = hash(&buf);
if doc_hash != file_hash {
println!(" Writing changes to disk");
file.write_all(content.as_bytes())?;
file.flush()?;
}
else {
println!(" No changes to sync");
Expand Down

0 comments on commit d80c707

Please sign in to comment.