From ea7899dd364e13b8181f68f43680f2404850754a Mon Sep 17 00:00:00 2001 From: kirawi <67773714+kirawi@users.noreply.github.com> Date: Thu, 4 Jan 2024 19:25:44 -0500 Subject: [PATCH] handle readonly --- helix-view/src/document.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 53e50e489ef43..f7c23a7f9c847 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -897,7 +897,12 @@ impl Document { } } - // TODO: Fail if path is read-only. + match rustix::fs::access(&path, rustix::fs::Access::WRITE_OK) { + Ok(_) => {} + Err(err) if err.kind() == std::io::ErrorKind::NotFound => {} + Err(_) => 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();