-
-
Notifications
You must be signed in to change notification settings - Fork 2k
sandydoo's libstore-c: add accessor-based path info API #16420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
roberth
wants to merge
9
commits into
NixOS:master
Choose a base branch
from
roberth:feat-query-path-info
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
714d2a8
libstore-c: add accessor-based path info API
sandydoo eefdfbc
libstore-c: rename PathInfo to nix_path_info
sandydoo d13d5a5
libstore-c: lint
sandydoo 1c9fee3
libstore-c: return nix_err in callbacks to allow early exit
sandydoo 1096494
libstore-c: expand path info tests
sandydoo 41ab9d6
libstore-c: improve callback error handling
sandydoo 26ce3cb
libstore-c: improve docs and add release note
sandydoo b02f3e8
libstore-c: clarify NAR never empty
roberth 5a123e1
libstore-c: return distinct code NIX_ERR_KEY when get_ca not CA
roberth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| synopsis: "C API: Add store path metadata accessors" | ||
| prs: [15675] | ||
| --- | ||
|
|
||
| The C API now includes functions for querying store path metadata: | ||
|
|
||
| - `nix_store_query_path_info()` - Query metadata for a store path | ||
| - `nix_path_info_get_nar_hash()` - Get the NAR hash | ||
| - `nix_path_info_get_nar_size()` - Get the NAR size | ||
| - `nix_path_info_get_references()` - Iterate over references | ||
| - `nix_path_info_get_deriver()` - Get the deriver | ||
| - `nix_path_info_get_sigs()` - Iterate over signatures | ||
| - `nix_path_info_get_ca()` - Get the content address | ||
| - `nix_path_info_free()` - Free store path metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #ifndef NIX_API_STORE_PATH_INFO_H | ||
| #define NIX_API_STORE_PATH_INFO_H | ||
| /** | ||
| * @defgroup libstore_pathinfo PathInfo | ||
| * @ingroup libstore | ||
| * @brief Store path metadata | ||
| * @{ | ||
| */ | ||
| /** @file | ||
| * @brief Path info operations for querying store object metadata | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #include "nix_api_util.h" | ||
| #include "nix_api_store/store_path.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
| // cffi start | ||
|
|
||
| /** @brief Opaque handle to store path metadata */ | ||
| typedef struct nix_path_info nix_path_info; | ||
|
|
||
| /** | ||
| * @brief Deallocate a nix_path_info | ||
| * | ||
| * Does not fail. | ||
| * @param[in] path_info the nix_path_info to free | ||
| */ | ||
| void nix_path_info_free(nix_path_info * path_info); | ||
|
|
||
| /** | ||
| * @brief Get the NAR hash of a store path | ||
| * | ||
| * Returns the hash as a string with algorithm prefix in Nix base-32 encoding, | ||
| * e.g. "sha256:1b8m03r63zqhnjf7l5nh...". This is the format used in narinfo files. | ||
| * | ||
| * @param[out] context Optional, stores error information | ||
| * @param[in] path_info the nix_path_info to read from | ||
| * @param[in] callback called with the hash string | ||
| * @param[in] user_data arbitrary data, passed to the callback when it's called | ||
| * @return NIX_OK on success, error code on failure | ||
| */ | ||
| nix_err nix_path_info_get_nar_hash( | ||
| nix_c_context * context, const nix_path_info * path_info, nix_get_string_callback callback, void * user_data); | ||
|
|
||
| /** | ||
| * @brief Get the NAR size of a store path | ||
| * | ||
| * @param[out] context Optional, stores error information | ||
| * @param[in] path_info the nix_path_info to read from | ||
| * @return NAR size in bytes, 0 on error. Note that a NAR always has a root object, | ||
| * so an actual NAR stream is never empty. | ||
| */ | ||
| uint64_t nix_path_info_get_nar_size(nix_c_context * context, const nix_path_info * path_info); | ||
|
|
||
| /** | ||
| * @brief Iterate over the references of a store path | ||
| * | ||
| * Calls the callback once for each reference. The StorePath passed to the | ||
| * callback is borrowed and only valid for the duration of the callback. | ||
| * Iteration stops if the callback returns with `context` in an error state. | ||
| * | ||
| * @param[out] context Optional, stores error information | ||
| * @param[in] path_info the nix_path_info to read from | ||
| * @param[in] user_data arbitrary data, passed to the callback | ||
| * @param[in] callback called for each referenced store path | ||
| * @return NIX_OK on success, error code on failure | ||
| */ | ||
| nix_err nix_path_info_get_references( | ||
| nix_c_context * context, | ||
| const nix_path_info * path_info, | ||
| void * user_data, | ||
| void (*callback)(nix_c_context * context, void * user_data, const StorePath * store_path)); | ||
|
|
||
| /** | ||
| * @brief Get the deriver of a store path | ||
| * | ||
| * @note Don't forget to free the result with nix_store_path_free()! | ||
| * @param[out] context Optional, stores error information | ||
| * @param[in] path_info the nix_path_info to read from | ||
| * @return owned StorePath of the deriver, or NULL if no deriver is known | ||
| */ | ||
| StorePath * nix_path_info_get_deriver(nix_c_context * context, const nix_path_info * path_info); | ||
|
|
||
| /** | ||
| * @brief Iterate over the signatures of a store path | ||
| * | ||
| * Calls the callback once for each signature string (format: "keyName:base64sig"). | ||
| * The `sig` data is borrowed and the callback must not assume that the buffer | ||
| * persists after it returns. | ||
| * | ||
| * Iteration stops if the callback returns with `context` in an error state. | ||
| * | ||
| * @param[out] context Optional, stores error information | ||
| * @param[in] path_info the nix_path_info to read from | ||
| * @param[in] user_data arbitrary data, passed to the callback | ||
| * @param[in] callback called for each signature string | ||
| * @return NIX_OK on success, error code on failure | ||
| */ | ||
| nix_err nix_path_info_get_sigs( | ||
| nix_c_context * context, | ||
| const nix_path_info * path_info, | ||
| void * user_data, | ||
| void (*callback)(nix_c_context * context, void * user_data, const char * sig, unsigned int sig_len)); | ||
|
|
||
| /** | ||
| * @brief Get the content address of a store path, if it has one | ||
| * | ||
| * If so, "returns" the hash as a string with method and algorithm prefix in Nix base-32 encoding, | ||
| * e.g. `"fixed:r:sha256:1i89icvvs2f3cym00414i3bbl1qidhg0b5yrmdlx9cjkj5is6ljg"`. | ||
| * | ||
| * If the store object referenced by `path_info` is not content-addressed, | ||
| * the return code is `NIX_ERR_KEY`, and the callback is not called. | ||
| * | ||
| * `NIX_ERR_KEY` is only returned when `path_info` is not content-addressed. | ||
| * | ||
| * Input-addressed store paths have a content hash (see `nix_path_info_get_nar_hash`, | ||
| * but no content *address*, so that results in NIX_ERR_KEY, distinguishable from | ||
| * other, perhaps more unexpected errors. | ||
| * | ||
| * @param[out] context Optional, stores error information | ||
| * @param[in] path_info the nix_path_info to read from | ||
| * @param[in] callback called with the content address string (only called when present) | ||
| * @param[in] user_data arbitrary data, passed to the callback when it's called | ||
| * @return NIX_OK on success, NIX_ERR_KEY if the path is not content-addressed, | ||
| * another error code on failure | ||
| */ | ||
| nix_err nix_path_info_get_ca( | ||
| nix_c_context * context, const nix_path_info * path_info, nix_get_string_callback callback, void * user_data); | ||
|
|
||
| // cffi end | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| /** | ||
| * @} | ||
| */ | ||
| #endif // NIX_API_STORE_PATH_INFO_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
known to be not false a few lines above.