use crate::runtime::CONTEXT;
use crate::runtime::driver::op::{Completable, CqeResult, Op};
use std::ffi::CString;
use std::io;
use std::path::Path;
pub(crate) struct RenameAt {
pub(crate) from: CString,
pub(crate) to: CString,
}
impl Op<RenameAt> {
pub(crate) fn rename_at(from: &Path, to: &Path, flags: u32) -> io::Result<Op<RenameAt>> {
use io_uring::{opcode, types};
let from = super::util::cstr(from)?;
let to = super::util::cstr(to)?;
CONTEXT.with(|x| {
x.handle()
.expect("Not in a runtime context")
.submit_op(RenameAt { from, to }, |rename| {
let from_ref = rename.from.as_c_str().as_ptr();
let to_ref = rename.to.as_c_str().as_ptr();
opcode::RenameAt::new(types::Fd(libc::AT_FDCWD), from_ref, types::Fd(libc::AT_FDCWD), to_ref)
.flags(flags)
.build()
})
})
}
}
impl Completable for RenameAt {
type Output = io::Result<()>;
fn complete(self, cqe: CqeResult) -> Self::Output {
cqe.result.map(|_| ())
}
}