Skip to content

Commit bf8eefa

Browse files
committed
Use direct syscall renameat2 since musl does not expose it
1 parent f4158bb commit bf8eefa

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ FROM chef AS builder
2727
ARG BUILD_DEBUG=false
2828
ENV CARGO_PROFILE_RELEASE_DEBUG=$BUILD_DEBUG
2929
COPY --from=planner /recipe.json recipe.json
30-
RUN cargo chef cook --release --recipe-path recipe.json
30+
RUN cargo chef cook --release --recipe-path recipe.json -p libsql-server -p bottomless-cli
3131
COPY . .
3232
ARG ENABLE_FEATURES=""
3333
RUN if [ "$ENABLE_FEATURES" == "" ]; then \

libsql-server/src/replication/primary/logger.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -470,23 +470,33 @@ fn atomic_rename(p1: impl AsRef<Path>, p2: impl AsRef<Path>) -> anyhow::Result<(
470470

471471
#[cfg(target_os = "linux")]
472472
fn atomic_rename(p1: impl AsRef<Path>, p2: impl AsRef<Path>) -> anyhow::Result<()> {
473-
use anyhow::Context;
474-
use nix::fcntl::{renameat2, RenameFlags};
475-
476-
renameat2(
477-
None,
478-
p1.as_ref(),
479-
None,
480-
p2.as_ref(),
481-
RenameFlags::RENAME_EXCHANGE,
482-
)
483-
.with_context(|| {
484-
format!(
485-
"failed to perform snapshot file swap {} -> {}",
486-
p1.as_ref().display(),
487-
p2.as_ref().display()
473+
use std::ffi::CString;
474+
use std::os::unix::prelude::OsStrExt;
475+
476+
const RENAME_EXCHANGE: u32 = 2;
477+
478+
let cp1 = CString::new(p1.as_ref().as_os_str().as_bytes())?;
479+
let cp2 = CString::new(p2.as_ref().as_os_str().as_bytes())?;
480+
481+
let ret = unsafe {
482+
nix::libc::syscall(
483+
nix::libc::SYS_renameat2,
484+
nix::libc::AT_FDCWD,
485+
cp1.as_ptr(),
486+
nix::libc::AT_FDCWD,
487+
cp2.as_ptr(),
488+
RENAME_EXCHANGE,
488489
)
489-
})?;
490+
};
491+
492+
if ret != 0 {
493+
bail!(
494+
"failed to perform snapshot file swap {} -> {}: {ret}, errno: {}",
495+
p1.as_ref().display(),
496+
p2.as_ref().display(),
497+
std::io::Error::last_os_error()
498+
);
499+
}
490500

491501
Ok(())
492502
}

0 commit comments

Comments
 (0)