Skip to content

Commit 078d41b

Browse files
committed
add helper function for memfs
1 parent 3aa3c9d commit 078d41b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/easy_sqlite3/memfs.nim

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const
1111
SHM_PAGE_SIZE = 32768
1212

1313
type
14-
FileKind = enum
14+
FileKind* = enum
1515
fk_main
1616
fk_temp
1717
fk_transient
@@ -38,6 +38,11 @@ type
3838
fileLock: Lock
3939
state: SqliteLockLevel
4040
shareds: int
41+
MemoryFileStat* = object
42+
name*: string
43+
kind*: FileKind
44+
size*: int
45+
refc*: int
4146
MemoryFileInfo = object
4247
base: SqliteFile
4348
data: ptr MemoryFile
@@ -145,6 +150,21 @@ proc writeBuffer(self: ptr MemoryFile, buffer: ptr UncheckedArray[byte], length:
145150
146151
var root = initTable[string, ptr MemoryFile]()
147152
153+
iterator listMemfs*(): MemoryFileStat =
154+
glock.withLock:
155+
for name, file in root:
156+
yield MemoryFileStat(name: name, kind: file.kind, size: file.size, refc: file.refc)
157+
158+
proc removeMemoryFile*(name: string): bool =
159+
glock.withLock:
160+
root.withValue(name, file) do:
161+
if file.refc != 0:
162+
return false
163+
`=destroy` file[]
164+
dealloc file
165+
root.del name
166+
return true
167+
148168
proc getMemoryFile(cname: cstring, filekind: FileKind): ptr MemoryFile =
149169
let name = $cname
150170
glock.withLock:

0 commit comments

Comments
 (0)