diff --git a/Cargo.lock b/Cargo.lock index 33c5c0946fbd..a79e6555c6d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,6 +445,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + [[package]] name = "flate2" version = "1.0.27" @@ -1330,12 +1342,15 @@ version = "23.10.0" name = "helix-stdx" version = "23.10.0" dependencies = [ + "bitflags 2.4.2", "dunce", "etcetera", "regex-cursor", "ropey", + "rustix", "tempfile", "which", + "windows-sys 0.52.0", ] [[package]] @@ -1445,8 +1460,6 @@ dependencies = [ "tokio-stream", "toml", "url", - "which", - "windows-sys 0.52.0", ] [[package]] @@ -1478,7 +1491,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows 0.48.0", + "windows", ] [[package]] @@ -2603,25 +2616,6 @@ dependencies = [ "windows-targets 0.48.0", ] -[[package]] -name = "windows" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" -dependencies = [ - "windows-core", - "windows-targets 0.52.0", -] - -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.0", -] - [[package]] name = "windows-sys" version = "0.45.0" diff --git a/helix-stdx/Cargo.toml b/helix-stdx/Cargo.toml index ed23f4e4ffd3..199dd06e4e30 100644 --- a/helix-stdx/Cargo.toml +++ b/helix-stdx/Cargo.toml @@ -17,6 +17,13 @@ etcetera = "0.8" ropey = { version = "1.6.1", default-features = false } which = "6.0" regex-cursor = "0.1.4" +bitflags = "2.4" + +[target.'cfg(windows)'.dependencies] +windows-sys = { version = "0.52", features = ["Win32_Security", "Win32_Security_Authorization"] } + +[target.'cfg(unix)'.dependencies] +rustix = { version = "0.38", features = ["fs"] } [dev-dependencies] tempfile = "3.10" diff --git a/helix-view/src/faccess.rs b/helix-stdx/src/faccess.rs similarity index 95% rename from helix-view/src/faccess.rs rename to helix-stdx/src/faccess.rs index d83c4144db46..0270c1f8a163 100644 --- a/helix-view/src/faccess.rs +++ b/helix-stdx/src/faccess.rs @@ -50,20 +50,21 @@ mod imp { Ok(()) } - fn chown(p: &Path, uid: Option, gid: Option) -> anyhow::Result<()> { + fn chown(p: &Path, uid: Option, gid: Option) -> io::Result<()> { let uid = uid.map(|n| unsafe { rustix::fs::Uid::from_raw(n) }); let gid = gid.map(|n| unsafe { rustix::fs::Gid::from_raw(n) }); rustix::fs::chown(p, uid, gid)?; Ok(()) } - pub fn copy_metadata(from: &Path, to: &Path) -> anyhow::Result<()> { + pub fn copy_metadata(from: &Path, to: &Path) -> io::Result<()> { let from_meta = std::fs::metadata(from)?; let to_meta = std::fs::metadata(to)?; let from_gid = from_meta.gid(); let to_gid = to_meta.gid(); let mut perms = from_meta.permissions(); + perms.set_mode(perms.mode() & 0o0777); if from_gid != to_gid && chown(to, None, Some(from_gid)).is_err() { let new_perms = (perms.mode() & 0o0707) | ((perms.mode() & 0o07) << 3); perms.set_mode(new_perms); @@ -122,7 +123,7 @@ mod imp { } impl SecurityDescriptor { - fn for_path(p: &Path) -> std::io::Result { + fn for_path(p: &Path) -> io::Result { let path = std::fs::canonicalize(p)?; let pathos = path.into_os_string(); let mut pathw: Vec = Vec::with_capacity(pathos.len() + 1); @@ -350,7 +351,7 @@ mod imp { } } - fn chown(p: &Path, sd: SecurityDescriptor) -> std::io::Result<()> { + fn chown(p: &Path, sd: SecurityDescriptor) -> io::Result<()> { let path = std::fs::canonicalize(p)?; let pathos = path.as_os_str(); let mut pathw = Vec::with_capacity(pathos.len() + 1); @@ -399,7 +400,7 @@ mod imp { } } - pub fn copy_metadata(from: &Path, to: &Path) -> std::io::Result<()> { + pub fn copy_metadata(from: &Path, to: &Path) -> io::Result<()> { let sd = SecurityDescriptor::for_path(from)?; chown(to, sd)?; @@ -436,7 +437,7 @@ mod imp { } } - pub fn copy_metadata(from: &path, to: &Path) -> std::io::Result<()> { + pub fn copy_metadata(from: &path, to: &Path) -> io::Result<()> { let meta = std::fs::metadata(from)?; let perms = meta.permissions(); std::fs::set_permissions(to, perms)?; @@ -453,7 +454,6 @@ pub fn readonly(p: &Path) -> bool { } } -pub fn copy_metadata(from: &Path, to: &Path) -> anyhow::Result<()> { - imp::copy_metadata(from, to)?; - Ok(()) +pub fn copy_metadata(from: &Path, to: &Path) -> io::Result<()> { + imp::copy_metadata(from, to) } diff --git a/helix-stdx/src/lib.rs b/helix-stdx/src/lib.rs index 68fe3ec37702..19602c205d0c 100644 --- a/helix-stdx/src/lib.rs +++ b/helix-stdx/src/lib.rs @@ -1,3 +1,4 @@ pub mod env; +pub mod faccess; pub mod path; pub mod rope; diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 02deaa5132f8..f1875ec47edf 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -53,7 +53,6 @@ parking_lot = "0.12.1" [target.'cfg(windows)'.dependencies] clipboard-win = { version = "5.2", features = ["std"] } -windows-sys = { version = "0.52", features = ["Win32_Security", "Win32_Security_Authorization"] } [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 35ef2962fc4d..fd08ae0e6665 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -10,6 +10,7 @@ use helix_core::encoding::Encoding; use helix_core::syntax::{Highlight, LanguageServerFeature}; use helix_core::text_annotations::{InlineAnnotation, TextAnnotations}; use helix_lsp::util::lsp_pos_to_pos; +use helix_stdx::faccess::{copy_metadata, readonly}; use helix_vcs::{DiffHandle, DiffProviderRegistry}; use ::parking_lot::Mutex; @@ -37,7 +38,6 @@ use helix_core::{ use crate::editor::Config; use crate::events::{DocumentDidChange, SelectionDidChange}; -use crate::faccess::{copy_metadata, readonly}; use crate::{DocumentId, Editor, Theme, View, ViewId}; /// 8kB of buffer space for encoding and decoding `Rope`s. diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index ada5004c140c..14b6e1ce8138 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -2,9 +2,6 @@ pub mod macros; pub mod base64; - -mod faccess; - pub mod clipboard; pub mod document; pub mod editor;