Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-latest, windows-2019]
os: [ubuntu-22.04, macos-latest, windows-2019, ubuntu-20.04, ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
10 changes: 0 additions & 10 deletions rust/file_utils/src/safe_file_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ impl SafeFileCreator {
if let Some(metadata) = self.original_metadata.as_ref() {
set_file_metadata(&self.dest_path, metadata, false)?;
}
let original_permissions = if self.dest_path.exists() {
Some(fs::metadata(&self.dest_path)?.permissions())
} else {
None
};

// Set the original file's permissions to the new file if they exist
if let Some(permissions) = original_permissions {
fs::set_permissions(&self.dest_path, permissions.clone())?;
}

Ok(())
}
Expand Down
10 changes: 8 additions & 2 deletions rust/gitxetcore/src/git_integration/git_xet_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ impl GitXetRepo {
.map(|(_name, url)| url)
.collect())
}
pub fn open(config: XetConfig) -> Result<Self> {
let repo_path = config.repo_path()?.clone();
Self::open_at(config, repo_path)
}

/// Open the repository, assuming that the current directory is itself in the repository.
///
/// If we are running in a way that is not associated with a repo, then the XetConfig path
/// will not show we are in a repo.
pub fn open(config: XetConfig) -> Result<Self> {
let repo = open_libgit2_repo(config.repo_path()?)?;
pub fn open_at(mut config: XetConfig, repo_path: PathBuf) -> Result<Self> {
let repo = open_libgit2_repo(&repo_path)?;
config.repo_path_if_present = Some(repo_path);
let config = config;

let git_dir = repo.path().to_path_buf();
let repo_dir = repo_dir_from_repo(&repo);
Expand Down
10 changes: 0 additions & 10 deletions xetldfs/Cargo.lock

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

1 change: 0 additions & 1 deletion xetldfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ anyhow = "1"
tokio = { version = "1", features = ["full"] }
errno = "0.3.9"
ctor = "0.1"
redhook = "*"
openssl-probe = "0.1.5"
clap = { version = "3.1.6", features = ["derive"] }
path-absolutize = "3.1.1"
Expand Down
83 changes: 83 additions & 0 deletions xetldfs/src/interposing_linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// From redhook, https://github.com/geofft/redhook, modified to not crash on non-existent interposed.
use libc::{c_char, c_void};
#[allow(clippy::missing_safety_doc)]
#[link(name = "dl")]
extern "C" {
fn dlsym(handle: *const c_void, symbol: *const c_char) -> *const c_void;
}

const RTLD_NEXT: *const c_void = -1isize as *const c_void;

// NOTE: May be the null pointer.
#[allow(clippy::missing_safety_doc)]
pub unsafe fn dlsym_next(symbol: &'static str) -> *const u8 {
let ptr = dlsym(RTLD_NEXT, symbol.as_ptr() as *const c_char);
ptr as *const u8
}

#[macro_export]
macro_rules! hook {
(unsafe fn $real_fn:ident ( $($v:ident : $t:ty),* ) -> $r:ty => $hook_fn:ident $body:block) => {
#[allow(non_camel_case_types)]
pub struct $real_fn {__private_field: ()}
#[allow(non_upper_case_globals)]
static $real_fn: $real_fn = $real_fn {__private_field: ()};

impl $real_fn {
unsafe fn get_raw(&self) -> *const u8 {
use ::std::sync::Once;

static mut REAL: *const u8 = 0 as *const u8;
static mut ONCE: Once = Once::new();

unsafe {
ONCE.call_once(|| {
REAL = $crate::interposing_linux::dlsym_next(concat!(stringify!($real_fn), "\0"));
});
REAL
}
}

#[inline]
unsafe fn get(&self) -> unsafe extern fn ( $($v : $t),* ) -> $r {
::std::mem::transmute(self.get_raw())
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern fn $real_fn ( $($v : $t),* ) -> $r {
::std::panic::catch_unwind(|| $hook_fn ( $($v),* )).unwrap_or_else(|_| $real_fn.get() ( $($v),* ))
}
}

#[allow(clippy::missing_safety_doc)]
pub unsafe fn $hook_fn ( $($v : $t),* ) -> $r {
$body
}
};

(unsafe fn $real_fn:ident ( $($v:ident : $t:ty),* ) => $hook_fn:ident $body:block) => {
$crate::hook! { unsafe fn $real_fn ( $($v : $t),* ) -> () => $hook_fn $body }
};
}

#[macro_export]
macro_rules! real {
($real_fn:ident) => {{
if $real_fn.get_raw().is_null() {
panic!(
"XetLDFS: Attempting to call hook to non-existant function {}.",
stringify!($real_fn)
);
}

$real_fn.get()
}};
}

#[macro_export]
macro_rules! fn_is_valid {
($real_fn:ident) => {
!$real_fn.get_raw().is_null()
};
}
48 changes: 48 additions & 0 deletions xetldfs/src/interposing_osx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#[macro_export]
macro_rules! hook {
(unsafe fn $real_fn:ident ( $($v:ident : $t:ty),* ) -> $r:ty => $hook_fn:ident $body:block) => {
pub mod $real_fn {
#[allow(non_camel_case_types)]
pub struct $real_fn {
_new: *const (),
_old: *const (),
}

#[allow(dead_code)]
#[allow(non_upper_case_globals)]
#[link_section="__DATA,__interpose"]
pub static mut $real_fn: $real_fn = $real_fn {
_new: super::$hook_fn as *const (),
_old: super::$real_fn as *const (),
};
}

extern {
pub fn $real_fn ( $($v : $t),* ) -> $r;
}

#[allow(clippy::missing_safety_doc)]
pub unsafe extern fn $hook_fn ( $($v : $t),* ) -> $r {
::std::panic::catch_unwind(|| $body ).unwrap_or_else(|_| $real_fn ( $($v),* ))
}
};

(unsafe fn $real_fn:ident ( $($v:ident : $t:ty),* ) => $hook_fn:ident $body:block) => {
$crate::hook! { unsafe fn $real_fn ( $($v : $t),* ) -> () => $hook_fn $body }
};
}

#[macro_export]
macro_rules! real {
($real_fn:ident) => {
$real_fn
};
}

// Don't have to worry about this.
#[macro_export]
macro_rules! fn_is_valid {
($real_fn:ident) => {
true
};
}
Loading