From aa248fdf5833cdd9be50b09ff2d4fce69f0a9202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 21 Mar 2024 17:17:12 +0100 Subject: [PATCH] drop all ffi functions not used by harmonia --- libnixstore/include/nix.h | 7 --- libnixstore/src/lib.rs | 107 -------------------------------------- libnixstore/src/nix.cpp | 90 -------------------------------- 3 files changed, 204 deletions(-) diff --git a/libnixstore/include/nix.h b/libnixstore/include/nix.h index a1fe8ebc..7d88d8ad 100644 --- a/libnixstore/include/nix.h +++ b/libnixstore/include/nix.h @@ -7,15 +7,8 @@ namespace libnixstore { void init(); bool is_valid_path(rust::Str path); rust::String query_path_hash(rust::Str path); -rust::String query_deriver(rust::Str path); InternalPathInfo query_path_info(rust::Str path, bool base32); -rust::String query_raw_realisation(rust::Str output_id); rust::String query_path_from_hash_part(rust::Str hash_part); -rust::Vec compute_fs_closure(bool flip_direction, - bool include_outputs, - rust::Vec paths); -rust::Vec topo_sort_paths(rust::Vec paths); -rust::String follow_links_to_store_path(rust::Str path); void export_paths(int32_t fd, rust::Vec paths); void import_paths(int32_t fd, bool dont_check_signs); rust::String hash_file(rust::Str algo, bool base32, rust::Str path); diff --git a/libnixstore/src/lib.rs b/libnixstore/src/lib.rs index e8c0517b..bf453bde 100644 --- a/libnixstore/src/lib.rs +++ b/libnixstore/src/lib.rs @@ -38,34 +38,16 @@ mod ffi { unsafe extern "C++" { include!("libnixstore/include/nix.h"); - // bindings that are also available in the perl bindings fn init(); fn is_valid_path(path: &str) -> Result; fn query_path_hash(path: &str) -> Result; - fn query_deriver(path: &str) -> Result; fn query_path_info(path: &str, base32: bool) -> Result; - fn query_raw_realisation(output_id: &str) -> Result; fn query_path_from_hash_part(hash_part: &str) -> Result; - fn compute_fs_closure( - flip_direction: bool, - include_outputs: bool, - paths: Vec<&str>, - ) -> Result>; - fn topo_sort_paths(paths: Vec<&str>) -> Result>; - fn follow_links_to_store_path(path: &str) -> Result; - fn export_paths(fd: i32, paths: Vec<&str>) -> Result<()>; - fn import_paths(fd: i32, dont_check_signs: bool) -> Result<()>; - fn hash_file(algo: &str, base32: bool, path: &str) -> Result; - fn hash_string(algo: &str, base32: bool, s: &str) -> Result; fn convert_hash(algo: &str, s: &str, to_base_32: bool) -> Result; fn sign_string(secret_key: &str, msg: &str) -> Result; fn check_signature(public_key: &str, sig: &str, msg: &str) -> Result; fn derivation_from_path(drv_path: &str) -> Result; - fn add_temp_root(store_path: &str) -> Result<()>; - fn get_bin_dir() -> String; fn get_store_dir() -> String; - - // additional but useful for harmonia fn get_build_log(derivation_path: &str) -> Result; fn get_nar_list(store_path: &str) -> Result; } @@ -157,16 +139,6 @@ pub fn query_path_hash(path: &str) -> Result { ffi::query_path_hash(path) } -#[inline] -#[must_use] -/// Return deriver of a valid path. It is permitted to omit the name part of the store path. -pub fn query_deriver(path: &str) -> Option { - match ffi::query_deriver(path) { - Ok(v) => string_to_opt(v), - Err(_) => None, - } -} - #[inline] /// Query information about a valid path. It is permitted to omit the name part of the store path. /// The `radix` field affects only the `narHash` field of the result. @@ -183,16 +155,6 @@ pub fn query_path_info(path: &str, radix: Radix) -> Result Option { - match ffi::query_raw_realisation(output_id) { - Ok(v) => string_to_opt(v), - Err(_) => None, - } -} - #[inline] #[must_use] /// Query the full store path given the hash part of a valid store path, or empty if the path @@ -204,61 +166,6 @@ pub fn query_path_from_hash_part(hash_part: &str) -> Option { } } -#[inline] -/// Returns all store paths in the file system closure of `storePath` -/// -/// That is, all paths than can be directly or indirectly reached from it. If `flip_direction` is -/// true, the set of paths that can reach `storePath` is returned; that is, the closures under the -/// `referrers` relation instead of the `references` relation is returned. If `include_outputs` is -/// `true` then closure will additionally include all outputs of every derivation in the closure. -pub fn compute_fs_closure( - flip_direction: bool, - include_outputs: bool, - paths: Vec<&str>, -) -> Result, cxx::Exception> { - ffi::compute_fs_closure(flip_direction, include_outputs, paths) -} - -#[inline] -/// Sort a set of paths topologically under the references relation. If `p` refers to `q`, then `p` -/// precedes `q` in this list. -pub fn topo_sort_paths(paths: Vec<&str>) -> Result, cxx::Exception> { - ffi::topo_sort_paths(paths) -} - -#[inline] -/// Follow symlinks until we end up with a path in the Nix store. Will transform the results to -/// store paths. -pub fn follow_links_to_store_path(path: &str) -> Result { - ffi::follow_links_to_store_path(path) -} - -#[inline] -/// Export multiple paths in the format expected by `nix-store --import`. -pub fn export_paths(fd: i32, paths: Vec<&str>) -> Result<(), cxx::Exception> { - ffi::export_paths(fd, paths) -} - -#[inline] -/// Import a sequence of NAR dumps created by `export_paths()` into the Nix store. Optionally, the -/// contents of the NARs are preloaded into the specified FS accessor to speed up subsequent -/// access. -pub fn import_paths(fd: i32, dont_check_signs: bool) -> Result<(), cxx::Exception> { - ffi::import_paths(fd, dont_check_signs) -} - -#[inline] -/// Compute the hash of the given file. -pub fn hash_file(algo: &str, radix: Radix, path: &str) -> Result { - ffi::hash_file(algo, matches!(radix, Radix::Base32), path) -} - -#[inline] -/// Compute the hash of the given string. -pub fn hash_string(algo: &str, radix: Radix, s: &str) -> Result { - ffi::hash_string(algo, matches!(radix, Radix::Base32), s) -} - #[inline] /// Parse the hash from a string representation in the format `[:]` or /// `-` to a string representation of the hash, in `base-16`, `base-32`. The result @@ -304,20 +211,6 @@ pub fn derivation_from_path(drv_path: &str) -> Result { }) } -#[inline] -/// Add a store path as a temporary root of the garbage collector. The root disappears as soon as -/// we exit. -pub fn add_temp_root(store_path: &str) -> Result<(), cxx::Exception> { - ffi::add_temp_root(store_path) -} - -#[inline] -#[must_use] -/// Return the path to the directory where the main programs are stored. -pub fn get_bin_dir() -> String { - ffi::get_bin_dir() -} - #[inline] #[must_use] /// Returns the path to the directory where nix store sources and derived files. diff --git a/libnixstore/src/nix.cpp b/libnixstore/src/nix.cpp index 3962d341..f3dfdf25 100644 --- a/libnixstore/src/nix.cpp +++ b/libnixstore/src/nix.cpp @@ -93,13 +93,6 @@ rust::String query_path_hash(rust::Str path) { ->narHash.to_string(nix::HashFormat::Nix32, true); } -rust::String query_deriver(rust::Str path) { - auto store = get_store(); - nix::ref info = - store->queryPathInfo(store->parseStorePath(STRING_VIEW(path))); - return extract_opt_path(info->deriver); -} - InternalPathInfo query_path_info(rust::Str path, bool base32) { auto store = get_store(); nix::ref info = @@ -128,85 +121,11 @@ InternalPathInfo query_path_info(rust::Str path, bool base32) { }; } -rust::String query_raw_realisation(rust::Str output_id) { - std::shared_ptr realisation = - get_store()->queryRealisation( - nix::DrvOutput::parse(STRING_VIEW(output_id))); - if (!realisation) { - // TODO(conni2461): Replace with option - return ""; - } - return realisation->toJSON().dump(); -} - rust::String query_path_from_hash_part(rust::Str hash_part) { return extract_opt_path( get_store()->queryPathFromHashPart(STRING_VIEW(hash_part))); } -rust::Vec compute_fs_closure(bool flip_direction, - bool include_outputs, - rust::Vec paths) { - auto store = get_store(); - nix::StorePathSet path_set; - for (auto &path : paths) { - store->computeFSClosure(store->parseStorePath(STRING_VIEW(path)), path_set, - flip_direction, include_outputs); - } - return extract_path_set(path_set); -} - -rust::Vec topo_sort_paths(rust::Vec paths) { - auto store = get_store(); - nix::StorePathSet path_set; - for (auto &path : paths) { - path_set.insert(store->parseStorePath(STRING_VIEW(path))); - } - nix::StorePaths sorted = store->topoSortPaths(path_set); - rust::Vec res; - res.reserve(sorted.size()); - for (auto &path : sorted) { - res.push_back(store->printStorePath(path)); - } - return res; -} - -rust::String follow_links_to_store_path(rust::Str path) { - auto store = get_store(); - return store->printStorePath( - store->followLinksToStorePath(STRING_VIEW(path))); -} - -void export_paths(int32_t fd, rust::Vec paths) { - auto store = get_store(); - nix::StorePathSet path_set; - for (auto &path : paths) { - path_set.insert(store->parseStorePath(STRING_VIEW(path))); - } - nix::FdSink sink(fd); - store->exportPaths(path_set, sink); -} - -void import_paths(int32_t fd, bool dont_check_signs) { - nix::FdSource source(fd); - get_store()->importPaths(source, dont_check_signs ? nix::NoCheckSigs - : nix::CheckSigs); -} - -rust::String hash_file(rust::Str algo, bool base32, rust::Str path) { - nix::Hash h = - nix::hashFile(nix::parseHashAlgo(STRING_VIEW(algo)), STRING_VIEW(path)); - return h.to_string(base32 ? nix::HashFormat::Nix32 : nix::HashFormat::Base16, - false); -} - -rust::String hash_string(rust::Str algo, bool base32, rust::Str s) { - nix::Hash h = - nix::hashString(nix::parseHashAlgo(STRING_VIEW(algo)), STRING_VIEW(s)); - return h.to_string(base32 ? nix::HashFormat::Nix32 : nix::HashFormat::Base16, - false); -} - rust::String convert_hash(rust::Str algo, rust::Str s, bool to_base_32) { nix::Hash h = nix::Hash::parseAny(STRING_VIEW(s), nix::parseHashAlgo(STRING_VIEW(algo))); @@ -269,15 +188,6 @@ InternalDrv derivation_from_path(rust::Str drv_path) { }; } -void add_temp_root(rust::Str store_path) { - auto store = get_store(); - store->addTempRoot(store->parseStorePath(STRING_VIEW(store_path))); -} - -rust::String get_bin_dir() { - return nix::settings.nixBinDir; -} - rust::String get_store_dir() { return nix::settings.nixStore; }