mirror of
https://github.com/NixOS/nix.git
synced 2024-10-31 06:10:59 +00:00
C API: if store doesn't have a version, return an empty string
This commit is contained in:
parent
dfdb90dc8e
commit
24c8f6864d
@ -72,11 +72,9 @@ nix_err nix_store_get_version(nix_c_context * context, Store * store, char * des
|
||||
context->last_err_code = NIX_OK;
|
||||
try {
|
||||
auto res = store->ptr->getVersion();
|
||||
if (res) {
|
||||
return nix_export_std_string(context, *res, dest, n);
|
||||
} else {
|
||||
return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "store does not have a version");
|
||||
}
|
||||
if (!res)
|
||||
res = "";
|
||||
return nix_export_std_string(context, *res, dest, n);
|
||||
}
|
||||
NIXC_CATCH_ERRS
|
||||
}
|
||||
|
@ -125,7 +125,8 @@ nix_err nix_store_build(
|
||||
void (*callback)(void * userdata, const char * outname, const char * out));
|
||||
|
||||
/**
|
||||
* @brief get the version of a nix store
|
||||
* @brief get the version of a nix store.
|
||||
* If the store doesn't have a version (like the dummy store), returns an empty string.
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] store nix store reference
|
||||
* @param[out] dest The allocated area to write the string to.
|
||||
|
@ -64,6 +64,11 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
|
||||
Store * store = nix_store_open(ctx, "dummy://", nullptr);
|
||||
ASSERT_EQ(NIX_OK, ctx->last_err_code);
|
||||
ASSERT_STREQ("dummy", store->ptr->getUri().c_str());
|
||||
|
||||
char value[256];
|
||||
nix_store_get_version(ctx, store, value, 256);
|
||||
ASSERT_STREQ("", value);
|
||||
|
||||
nix_store_unref(store);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user