Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Jan 8, 2024
1 parent 3caecec commit 8341c91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use helix_core::{
};

use crate::editor::Config;
use crate::faccess::readonly;
use crate::{DocumentId, Editor, Theme, View, ViewId};

/// 8kB of buffer space for encoding and decoding `Rope`s.
Expand Down Expand Up @@ -914,6 +915,10 @@ impl Document {
}
}

if readonly(&path) {
bail!("File is readonly");
}

let (mut tmp_file, tmp_path) = tokio::task::spawn_blocking(
move || -> anyhow::Result<(File, tempfile::TempPath)> {
let (f, p) = tempfile::NamedTempFile::new()?.into_parts();
Expand All @@ -923,10 +928,14 @@ impl Document {
.await??;
to_writer(&mut tmp_file, encoding_with_bom_info, &text).await?;

let perms = tokio::fs::metadata(&path).await?.permissions();
tmp_file.set_permissions(perms).await?;
// chown(&path, &tmp_path).await?;
tokio::fs::rename(tmp_path, &path).await?;
{
let path = path.clone();
tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
tmp_path.persist(path)?;
Ok(())
})
}
.await??;

let event = DocumentSavedEvent {
revision: current_rev,
Expand Down
4 changes: 2 additions & 2 deletions helix-view/src/faccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod imp {
// TODO: Can be replaced by std::fs::FileTimes on 1.75
let atime = FileTime::from_last_access_time(&meta);
let mtime = FileTime::from_last_modification_time(&meta);
filetime::set_file_times(&to, atime, mtime)?;
filetime::set_file_times(to, atime, mtime)?;

Ok(())
}
Expand Down Expand Up @@ -404,7 +404,7 @@ mod imp {
// TODO: Can be replaced by std::fs::FileTimes on 1.75
let atime = FileTime::from_last_access_time(&meta);
let mtime = FileTime::from_last_modification_time(&meta);
filetime::set_file_times(&to, atime, mtime)?;
filetime::set_file_times(to, atime, mtime)?;

Ok(())
}
Expand Down

0 comments on commit 8341c91

Please sign in to comment.