mirror of
https://github.com/logos-storage/logos-storage-go-bindings.git
synced 2026-01-02 05:23:09 +00:00
Add exists feature
This commit is contained in:
parent
9aa9977982
commit
232fd381bb
@ -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
|
||||
}
|
||||
|
||||
@ -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
2
vendor/nim-codex
vendored
@ -1 +1 @@
|
||||
Subproject commit a86d8586456d5eb6805b228e80e264ee736a6a90
|
||||
Subproject commit 72e9a3f85dd6cf43240bf3e0fbdcf27e704d3ca6
|
||||
Loading…
x
Reference in New Issue
Block a user