Merge pull request #9 from codex-storage/feat/has-block

feat: exists feature
This commit is contained in:
Arnaud 2025-11-03 09:51:51 +04:00 committed by GitHub
commit 32f40d0c12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 eb2950b9d9840e9ef17f2c9eee025e9ed59505e6