StorePath should expect Rc<RefCell<Store>
This commit is contained in:
parent
47c79e7d53
commit
d70e6240fa
1 changed files with 15 additions and 13 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::ffi::{CString, c_void};
|
use std::ffi::{CString, c_void};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::Store;
|
use super::Store;
|
||||||
use crate::NixideResult;
|
use crate::NixideResult;
|
||||||
|
|
@ -15,7 +17,8 @@ use crate::util::wrappers::AsInnerPtr;
|
||||||
/// Represents a store path that can be realized, queried, or manipulated.
|
/// Represents a store path that can be realized, queried, or manipulated.
|
||||||
///
|
///
|
||||||
pub struct StorePath {
|
pub struct StorePath {
|
||||||
pub(crate) inner: NonNull<sys::StorePath>,
|
inner: NonNull<sys::StorePath>,
|
||||||
|
store: Rc<RefCell<Store>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for StorePath {
|
impl Clone for StorePath {
|
||||||
|
|
@ -25,7 +28,10 @@ impl Clone for StorePath {
|
||||||
panic_issue_call_failed!("nix_store_path_clone returned None for valid path")
|
panic_issue_call_failed!("nix_store_path_clone returned None for valid path")
|
||||||
});
|
});
|
||||||
|
|
||||||
StorePath { inner }
|
StorePath {
|
||||||
|
inner,
|
||||||
|
store: self.store.clone(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,17 +71,17 @@ impl StorePath {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error if the path cannot be parsed.
|
/// Returns an error if the path cannot be parsed.
|
||||||
pub fn parse(store: &Store, path: &str) -> NixideResult<Self> {
|
pub fn parse(store: Rc<RefCell<Store>>, path: &str) -> NixideResult<Self> {
|
||||||
let c_path = CString::new(path).or(Err(new_nixide_error!(StringNulByte)))?;
|
let c_path = CString::new(path).or(Err(new_nixide_error!(StringNulByte)))?;
|
||||||
|
|
||||||
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_store_parse_path(ctx.as_ptr(), store.as_ptr(), c_path.as_ptr())
|
sys::nix_store_parse_path(ctx.as_ptr(), store.borrow().as_ptr(), c_path.as_ptr())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Self { inner })
|
Ok(Self { inner, store })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fake_path(store: &Store) -> NixideResult<Self> {
|
pub fn fake_path(store: Rc<RefCell<Store>>) -> NixideResult<Self> {
|
||||||
Self::parse(store, "/nix/store/00000000000000000000000000000000-fake")
|
Self::parse(store, "/nix/store/00000000000000000000000000000000-fake")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,22 +114,18 @@ impl StorePath {
|
||||||
/// Not all types of stores support this operation.
|
/// Not all types of stores support this operation.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `context` [in] - Optional, stores error information
|
/// * `store` - nix store reference
|
||||||
/// * `store` [in] - nix store reference
|
|
||||||
/// * `path` [in] - the path to get the real path from
|
|
||||||
/// * `callback` [in] - called with the real path
|
|
||||||
/// * `user_data` [in] - arbitrary data, passed to the callback when it's called.
|
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `store` - The store containing the path
|
/// * `store` - The store containing the path
|
||||||
///
|
///
|
||||||
pub fn real_path(&self, store: &Store) -> NixideResult<PathBuf> {
|
pub fn real_path(&self) -> NixideResult<PathBuf> {
|
||||||
wrap::nix_pathbuf_callback!(
|
wrap::nix_pathbuf_callback!(
|
||||||
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_store_real_path(
|
sys::nix_store_real_path(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
store.inner.as_ptr(),
|
self.store.borrow().as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
userdata as *mut c_void,
|
userdata as *mut c_void,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue