Skip to content

Commit 9abcc68

Browse files
libstore-c: add nix_store_get_fs_closure
1 parent 07b96c1 commit 9abcc68

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/libstore-c/nix_api_store.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,36 @@ StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const c
126126
NIXC_CATCH_ERRS_NULL
127127
}
128128

129+
nix_err nix_store_get_fs_closure(
130+
nix_c_context * context,
131+
Store * store,
132+
const StorePath * store_path,
133+
bool flip_direction,
134+
bool include_outputs,
135+
bool include_derivers,
136+
void * userdata,
137+
void (*callback)(nix_c_context * context, void * userdata, const StorePath * store_path))
138+
{
139+
if (context)
140+
context->last_err_code = NIX_OK;
141+
try {
142+
const auto nixStore = store->ptr;
143+
144+
nix::StorePathSet set;
145+
nixStore->computeFSClosure(store_path->path, set, flip_direction, include_outputs, include_derivers);
146+
147+
if (callback) {
148+
for (const auto & path : set) {
149+
const StorePath tmp{path};
150+
callback(context, userdata, &tmp);
151+
if (context && context->last_err_code != NIX_OK)
152+
return context->last_err_code;
153+
}
154+
}
155+
}
156+
NIXC_CATCH_ERRS
157+
}
158+
129159
nix_err nix_store_realise(
130160
nix_c_context * context,
131161
Store * store,

src/libstore-c/nix_api_store.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,30 @@ void nix_derivation_free(nix_derivation * drv);
245245
*/
246246
nix_err nix_store_copy_closure(nix_c_context * context, Store * srcStore, Store * dstStore, StorePath * path);
247247

248+
/**
249+
* @brief Gets the closure of a specific store path
250+
*
251+
* @note The callback borrows each StorePath only for the duration of the call.
252+
*
253+
* @param[out] context Optional, stores error information
254+
* @param[in] store nix store reference
255+
* @param[in] store_path The path to compute from
256+
* @param[in] flip_direction
257+
* @param[in] include_outputs
258+
* @param[in] include_derivers
259+
* @param[in] callback The function to call for every store path, in no particular order
260+
* @param[in] userdata The userdata to pass to the callback
261+
*/
262+
nix_err nix_store_get_fs_closure(
263+
nix_c_context * context,
264+
Store * store,
265+
const StorePath * store_path,
266+
bool flip_direction,
267+
bool include_outputs,
268+
bool include_derivers,
269+
void * userdata,
270+
void (*callback)(nix_c_context * context, void * userdata, const StorePath * store_path));
271+
248272
// cffi end
249273
#ifdef __cplusplus
250274
}

0 commit comments

Comments
 (0)