Skip to content
Merged
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
52 changes: 52 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: macOS

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
test:
name: macOS build and integration tests (${{ matrix.architecture }})
strategy:
fail-fast: false
matrix:
include:
- runner: macos-14
architecture: arm64
- runner: macos-15-intel
architecture: x86_64
runs-on: ${{ matrix.runner }}
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Install Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.2

- name: Build native CLI
run: cargo build --locked

- name: Build test-hook CLI
run: cargo build --locked --features test-hooks --target-dir target/test-hooks

- name: Run Rust tests
run: cargo test --locked

- name: Install JavaScript test dependencies
run: bun install --frozen-lockfile

- name: Type-check JavaScript harness
run: bun x tsc --noEmit

- name: Run macOS integration tests
run: bun test --max-concurrency=1 --timeout=30000
2 changes: 1 addition & 1 deletion bun.lock

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

90 changes: 49 additions & 41 deletions src/config_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,43 +87,7 @@ fn safe_temp_path(dir: &Path) -> Result<(PathBuf, fs::File)> {
Err(anyhow!("could not create a unique temporary config file"))
}

#[cfg(unix)]
#[allow(dead_code)]
fn publish_anchored(
directory: std::os::fd::RawFd,
name: &std::ffi::OsStr,
temp: &Path,
replace: bool,
) -> Result<()> {
use std::{ffi::CString, os::unix::ffi::OsStrExt};
let src = CString::new(
temp.file_name()
.ok_or_else(|| anyhow!("temporary config file has no name"))?
.as_bytes(),
)?;
let dst = CString::new(name.as_bytes())?;
let rc = if replace {
unsafe { libc::renameat(directory, src.as_ptr(), directory, dst.as_ptr()) }
} else {
unsafe {
libc::syscall(
libc::SYS_renameat2,
directory,
src.as_ptr(),
directory,
dst.as_ptr(),
libc::RENAME_NOREPLACE,
) as libc::c_int
}
};
if rc == 0 {
Ok(())
} else {
Err(std::io::Error::last_os_error().into())
}
}

#[cfg(unix)]
#[cfg(target_os = "linux")]
fn publish_missing_from_handle(
directory: std::os::fd::RawFd,
name: &std::ffi::OsStr,
Expand Down Expand Up @@ -151,6 +115,39 @@ fn publish_missing_from_handle(
}
}

#[cfg(target_os = "macos")]
fn publish_missing_from_path(
directory: std::os::fd::RawFd,
name: &std::ffi::OsStr,
temp: &Path,
) -> Result<()> {
use std::{ffi::CString, os::unix::ffi::OsStrExt};

let source = CString::new(
temp.file_name()
.ok_or_else(|| anyhow!("temporary config file has no name"))?
.as_bytes(),
)?;
let destination = CString::new(name.as_bytes())?;
let linked = unsafe {
libc::linkat(
directory,
source.as_ptr(),
directory,
destination.as_ptr(),
0,
)
};
if linked < 0 {
return Err(std::io::Error::last_os_error().into());
}
let removed = unsafe { libc::unlinkat(directory, source.as_ptr(), 0) };
if removed < 0 {
return Err(std::io::Error::last_os_error().into());
}
Ok(())
}

#[allow(unreachable_code)]
pub(crate) fn edit_config(a: &super::App, json: bool) -> Result<serde_json::Value> {
if json {
Expand Down Expand Up @@ -310,7 +307,9 @@ pub(crate) fn edit_config(a: &super::App, json: bool) -> Result<serde_json::Valu
let mut verified = Vec::new();
target.read_to_end(&mut verified)?;
if verified != edited {
return Err(anyhow!("published config bytes do not match the editor result"));
return Err(anyhow!(
"published config bytes do not match the editor result"
));
}
Ok(())
})();
Expand All @@ -331,7 +330,9 @@ pub(crate) fn edit_config(a: &super::App, json: bool) -> Result<serde_json::Valu
let mut verified = Vec::new();
target.read_to_end(&mut verified)?;
if verified != edited {
return Err(anyhow!("published config bytes do not match the editor result"));
return Err(anyhow!(
"published config bytes do not match the editor result"
));
}
Ok(())
})();
Expand All @@ -345,9 +346,11 @@ pub(crate) fn edit_config(a: &super::App, json: bool) -> Result<serde_json::Valu
#[cfg(not(any(unix, windows)))]
{
let _ = config_identity;
return Err(anyhow!("native config publication is unavailable on this platform"));
return Err(anyhow!(
"native config publication is unavailable on this platform"
));
}
#[cfg(unix)]
#[cfg(target_os = "linux")]
if original.is_none() {
use std::os::fd::AsRawFd;
publish_missing_from_handle(
Expand All @@ -356,6 +359,11 @@ pub(crate) fn edit_config(a: &super::App, json: bool) -> Result<serde_json::Valu
&staged_file,
)?;
}
#[cfg(target_os = "macos")]
if original.is_none() {
use std::os::fd::AsRawFd;
publish_missing_from_path(directory.as_raw_fd(), path.file_name().unwrap(), &staged)?;
}
Ok(())
})();
result?;
Expand Down
3 changes: 2 additions & 1 deletion src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ pub(crate) fn show(a: &App, relationship: &str) -> Result<serde_json::Value> {
);
validate_state_path(&a.recovery, &recovery, "recovery")?;
let meta = fs::symlink_metadata(&recovery)?;
if !meta.is_dir() || meta.file_type().is_symlink() || canonicalize_path(&recovery)? != recovery {
if !meta.is_dir() || meta.file_type().is_symlink() || canonicalize_path(&recovery)? != recovery
{
return Err(anyhow!("conflict recovery is not a canonical directory"));
}
let raw = fs::read(recovery.join("manifest.json"))
Expand Down
Loading
Loading