From 47a50e981ac47e40254e0a2a78b8a1448978b0af Mon Sep 17 00:00:00 2001 From: Karchnu Date: Thu, 13 Oct 2022 01:23:13 +0200 Subject: [PATCH] Current-index is being taken care of. --- src/dodb.cl | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dodb.cl b/src/dodb.cl index e7e588b..f52da9d 100644 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -49,14 +49,26 @@ ; db/new ensures directory '/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