Add exists feature

This commit is contained in:
Arnaud 2025-11-02 17:20:59 +01:00
parent 9aa9977982
commit 232fd381bb
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
3 changed files with 48 additions and 1 deletions

View File

@ -24,6 +24,10 @@ import (
static int cGoCodexStorageDelete(void* codexCtx, char* cid, void* resp) {
return codex_storage_delete(codexCtx, cid, (CodexCallback) callback, resp);
}
static int cGoCodexStorageExists(void* codexCtx, char* cid, void* resp) {
return codex_storage_exists(codexCtx, cid, (CodexCallback) callback, resp);
}
*/
import "C"
@ -142,3 +146,19 @@ func (node CodexNode) Delete(cid string) error {
_, err := bridge.wait()
return err
}
// Exists checks if a given cid exists in the local storage.
func (node CodexNode) Exists(cid string) (bool, error) {
bridge := newBridgeCtx()
defer bridge.free()
var cCid = C.CString(cid)
defer C.free(unsafe.Pointer(cCid))
if C.cGoCodexStorageExists(node.ctx, cCid, bridge.resp) != C.RET_OK {
return false, bridge.callError("cGoCodexStorageExists")
}
result, err := bridge.wait()
return result == "true", err
}

View File

@ -119,3 +119,30 @@ func TestDelete(t *testing.T) {
t.Fatal("expected manifests to be empty after deletion")
}
}
func TestExists(t *testing.T) {
codex := newCodexNode(t)
cid, _ := uploadHelper(t, codex)
exists, err := codex.Exists(cid)
if err != nil {
t.Fatal(err)
}
if !exists {
t.Fatal("expected cid to exist")
}
err = codex.Delete(cid)
if err != nil {
t.Fatal(err)
}
exists, err = codex.Exists(cid)
if err != nil {
t.Fatal(err)
}
if exists {
t.Fatal("expected cid to not exist after deletion")
}
}

2
vendor/nim-codex vendored

@ -1 +1 @@
Subproject commit a86d8586456d5eb6805b228e80e264ee736a6a90
Subproject commit 72e9a3f85dd6cf43240bf3e0fbdcf27e704d3ca6