mirror of
https://git.telodendria.io/Telodendria/Cytoplasm.git
synced 2024-11-21 11:50:46 +03:00
[FIX/WIP] Temporary fix to the database system
It used to crash, my bad.
This commit is contained in:
parent
2b061f1226
commit
f6af2cd782
2 changed files with 17 additions and 21 deletions
13
src/Db/Db.c
13
src/Db/Db.c
|
@ -434,6 +434,7 @@ DbInit(Db *db)
|
|||
db->mostRecent = NULL;
|
||||
db->leastRecent = NULL;
|
||||
db->cacheSize = 0;
|
||||
db->maxCache = 0;
|
||||
|
||||
if (db->maxCache)
|
||||
{
|
||||
|
@ -460,15 +461,9 @@ DbRefInit(Db *db, DbRef *ref)
|
|||
ref->ts = UtilTsMillis();
|
||||
ref->size = 0;
|
||||
|
||||
if (db->mostRecent)
|
||||
{
|
||||
db->mostRecent->next = ref;
|
||||
}
|
||||
if (!db->leastRecent)
|
||||
{
|
||||
db->leastRecent = ref;
|
||||
}
|
||||
db->mostRecent = ref;
|
||||
/* TODO: Append the ref to the cache list.
|
||||
* I removed it because it broke everything and crashed all the time.
|
||||
* My bad! */
|
||||
}
|
||||
void
|
||||
StringArrayAppend(Array *arr, char *str)
|
||||
|
|
|
@ -106,7 +106,7 @@ FlatLock(Db *d, Array *dir)
|
|||
FlatDb *db = (FlatDb *) d;
|
||||
FlatDbRef *ref = NULL;
|
||||
size_t i;
|
||||
char *path;
|
||||
char *path = NULL;
|
||||
if (!d || !dir)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -126,6 +126,11 @@ FlatLock(Db *d, Array *dir)
|
|||
}
|
||||
|
||||
stream = StreamFd(fd);
|
||||
if (!stream)
|
||||
{
|
||||
ref = NULL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
|
@ -140,11 +145,11 @@ FlatLock(Db *d, Array *dir)
|
|||
}
|
||||
|
||||
ref = Malloc(sizeof(*ref));
|
||||
DbRefInit(d, &(ref->base));
|
||||
ref->fd = fd;
|
||||
ref->stream = stream;
|
||||
DbRefInit(d, (DbRef *) ref);
|
||||
ref->base.ts = UtilLastModified(path);
|
||||
ref->base.json = JsonDecode(stream);
|
||||
ref->stream = stream;
|
||||
ref->fd = fd;
|
||||
if (!ref->base.json)
|
||||
{
|
||||
Free(ref);
|
||||
|
@ -157,10 +162,7 @@ FlatLock(Db *d, Array *dir)
|
|||
ref->base.name = ArrayCreate();
|
||||
for (i = 0; i < ArraySize(dir); i++)
|
||||
{
|
||||
ArrayAdd(
|
||||
ref->base.name,
|
||||
StrDuplicate(ArrayGet(dir, i))
|
||||
);
|
||||
StringArrayAppend(ref->base.name, ArrayGet(dir, i));
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
@ -246,7 +248,6 @@ FlatCreate(Db *d, Array *dir)
|
|||
|
||||
/* FlatLock() will lock again for us */
|
||||
pthread_mutex_unlock(&d->lock);
|
||||
|
||||
ret = FlatLock(d, dir);
|
||||
|
||||
return ret;
|
||||
|
@ -255,7 +256,7 @@ FlatCreate(Db *d, Array *dir)
|
|||
static bool
|
||||
FlatDelete(Db *d, Array *dir)
|
||||
{
|
||||
bool ret = true;
|
||||
bool ret = false;
|
||||
char *file;
|
||||
FlatDb *db = (FlatDb *) d;
|
||||
if (!d || !dir)
|
||||
|
@ -273,7 +274,7 @@ FlatDelete(Db *d, Array *dir)
|
|||
}
|
||||
|
||||
Free(file);
|
||||
pthread_mutex_lock(&d->lock);
|
||||
pthread_mutex_unlock(&d->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -355,7 +356,7 @@ DbOpen(char *dir, size_t cache)
|
|||
return NULL;
|
||||
}
|
||||
db = Malloc(sizeof(*db));
|
||||
DbInit(&(db->base));
|
||||
DbInit((Db *) db);
|
||||
db->dir = dir;
|
||||
db->base.cacheSize = cache;
|
||||
|
||||
|
|
Loading…
Reference in a new issue