Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/libstore-c/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,31 @@ nix_err nix_store_copy_closure(nix_c_context * context, Store * srcStore, Store
}
NIXC_CATCH_ERRS
}

nix_err nix_store_get_fs_closure(
nix_c_context * context,
Store * store,
const StorePath * store_path,
bool flip_direction,
bool include_outputs,
bool include_derivers,
void * userdata,
void (*callback)(void * userdata, const StorePath * store_path))
{
if (context)
context->last_err_code = NIX_OK;
try {
const auto nixStore = store->ptr;

nix::StorePathSet set;
nixStore->computeFSClosure(store_path->path, set, flip_direction, include_outputs, include_derivers);

if (callback) {
for (const auto & path : set) {
const StorePath tmp{path};
callback(userdata, &tmp);
}
}
}
NIXC_CATCH_ERRS
}
24 changes: 24 additions & 0 deletions src/libstore-c/nix_api_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ nix_store_get_version(nix_c_context * context, Store * store, nix_get_string_cal
*/
nix_err nix_store_copy_closure(nix_c_context * context, Store * srcStore, Store * dstStore, StorePath * path);

/**
* @brief Gets the closure of a specific store path
*
* @note The callback borrows each StorePath only for the duration of the call.
*
* @param[out] context Optional, stores error information
* @param[in] store nix store reference
* @param[in] store_path The path to compute from
* @param[in] flip_direction
* @param[in] include_outputs
* @param[in] include_derivers
* @param[in] callback The function to call for every store path
* @param[in] userdata The userdata to pass to the callback
*/
nix_err nix_store_get_fs_closure(
nix_c_context * context,
Store * store,
const StorePath * store_path,
bool flip_direction,
bool include_outputs,
bool include_derivers,
void * userdata,
void (*callback)(void * userdata, const StorePath * store_path));
Comment on lines +241 to +242
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Fix ownership/const mismatch in callback parameter

Callback receives ownership but is declared with const StorePath *, which prevents calling nix_store_path_free(StorePath *) without a cast. Make the parameter non-const.

-    void * userdata,
-    void (*callback)(void * userdata, const StorePath * store_path));
+    void * userdata,
+    void (*callback)(void * userdata, StorePath * store_path));

Please update the implementation signature in src/libstore-c/nix_api_store.cc to match.


🏁 Script executed:

#!/bin/bash
# Verify header/impl callback constness and function name usage.
rg -n -C2 $'nix_store_get_fs_closure\\s*\\('
rg -n $'\\(\\*callback\\)\\(void \\* userdata, const StorePath \\* store_path\\)' src/libstore-c/nix_api_store.* || true

Length of output: 798


Fix ownership/const mismatch in callback parameter

Callback receives ownership but is declared const StorePath *, which prevents calling nix_store_path_free(StorePath *) without a cast — make the parameter non-const in both header and implementation.

Locations: src/libstore-c/nix_api_store.h:242, src/libstore-c/nix_api_store.cc:192

-    void * userdata,
-    void (*callback)(void * userdata, const StorePath * store_path));
+    void * userdata,
+    void (*callback)(void * userdata, StorePath * store_path));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void * userdata,
void (*callback)(void * userdata, const StorePath * store_path));
void * userdata,
void (*callback)(void * userdata, StorePath * store_path));
🤖 Prompt for AI Agents
In src/libstore-c/nix_api_store.h around line 242 and
src/libstore-c/nix_api_store.cc around line 192 the callback parameter is
declared as const StorePath * but the callback takes ownership and must call
nix_store_path_free(StorePath *), so change the callback signature in the header
from const StorePath * to StorePath * and update the matching implementation
signature and any forward declarations to use StorePath *; remove any const
casts inside the implementation, ensure callers and tests treat the StorePath as
owned (call nix_store_path_free when done), and update any related comments or
docs to reflect ownership semantics, then rebuild to verify no const-related
warnings remain.


// cffi end
#ifdef __cplusplus
}
Expand Down