Skip to content

Commit

Permalink
move faccess to helix-stdx
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Mar 15, 2024
1 parent 3c8cd95 commit 3e315ef
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
38 changes: 16 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions helix-stdx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
18 changes: 9 additions & 9 deletions helix-view/src/faccess.rs → helix-stdx/src/faccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ mod imp {
Ok(())
}

fn chown(p: &Path, uid: Option<u32>, gid: Option<u32>) -> anyhow::Result<()> {
fn chown(p: &Path, uid: Option<u32>, gid: Option<u32>) -> 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);
Expand Down Expand Up @@ -122,7 +123,7 @@ mod imp {
}

impl SecurityDescriptor {
fn for_path(p: &Path) -> std::io::Result<SecurityDescriptor> {
fn for_path(p: &Path) -> io::Result<SecurityDescriptor> {
let path = std::fs::canonicalize(p)?;
let pathos = path.into_os_string();
let mut pathw: Vec<u16> = Vec::with_capacity(pathos.len() + 1);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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)?;
Expand All @@ -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)
}
1 change: 1 addition & 0 deletions helix-stdx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod env;
pub mod faccess;
pub mod path;
pub mod rope;
1 change: 0 additions & 1 deletion helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions helix-view/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
pub mod macros;

pub mod base64;

mod faccess;

pub mod clipboard;
pub mod document;
pub mod editor;
Expand Down

0 comments on commit 3e315ef

Please sign in to comment.