Current-index is being taken care of.

draft
Karchnu 2022-10-13 01:23:13 +02:00
parent b7abc32ec0
commit 47a50e981a
1 changed files with 16 additions and 4 deletions

View File

@ -49,14 +49,26 @@
; db/new ensures directory '<path>/data/' exist,
; then loads values from existing files, if any, and puts them into db-data.
(defun db/new (struct-name path)
(ensure-directories-exist (concatenate 'string path "/data/"))
(let ((data (make-hash-table))
(data-dir-path (concatenate 'string path "/data/"))
(current-index 0))
(let ((data (make-hash-table)))
(loop for filename in (ls (concatenate 'string path "/data/"))
(ensure-directories-exist data-dir-path)
(loop for filename in (ls data-dir-path)
do (let ((id (filename->integer filename))
(value (util:read-object-from-file filename)))
(if (> id current-index)
(setf current-index id))
(setf (gethash id data) value)))
(make-db :struct-name struct-name :path path :data data)))
(format t "Max current index: ~A~&" current-index)
(make-db
:struct-name struct-name
:path path
:data data
:current-index current-index)))
; Example: ./storage/cars 18 -> ./storage/cars/data/000000000000018