forked from Telodendria/Cytoplasm
Compare commits
No commits in common. "f6af2cd78235f148750c69c946a5e0090d846cc2" and "a90c66736c79a7486e575c93962c2f38406cbda3" have entirely different histories.
f6af2cd782
...
a90c66736c
3 changed files with 21 additions and 19 deletions
13
src/Db/Db.c
13
src/Db/Db.c
|
@ -434,7 +434,6 @@ DbInit(Db *db)
|
|||
db->mostRecent = NULL;
|
||||
db->leastRecent = NULL;
|
||||
db->cacheSize = 0;
|
||||
db->maxCache = 0;
|
||||
|
||||
if (db->maxCache)
|
||||
{
|
||||
|
@ -461,9 +460,15 @@ DbRefInit(Db *db, DbRef *ref)
|
|||
ref->ts = UtilTsMillis();
|
||||
ref->size = 0;
|
||||
|
||||
/* TODO: Append the ref to the cache list.
|
||||
* I removed it because it broke everything and crashed all the time.
|
||||
* My bad! */
|
||||
if (db->mostRecent)
|
||||
{
|
||||
db->mostRecent->next = ref;
|
||||
}
|
||||
if (!db->leastRecent)
|
||||
{
|
||||
db->leastRecent = ref;
|
||||
}
|
||||
db->mostRecent = ref;
|
||||
}
|
||||
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 = NULL;
|
||||
char *path;
|
||||
if (!d || !dir)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -126,11 +126,6 @@ FlatLock(Db *d, Array *dir)
|
|||
}
|
||||
|
||||
stream = StreamFd(fd);
|
||||
if (!stream)
|
||||
{
|
||||
ref = NULL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
|
@ -145,11 +140,11 @@ FlatLock(Db *d, Array *dir)
|
|||
}
|
||||
|
||||
ref = Malloc(sizeof(*ref));
|
||||
DbRefInit(d, (DbRef *) ref);
|
||||
DbRefInit(d, &(ref->base));
|
||||
ref->fd = fd;
|
||||
ref->stream = stream;
|
||||
ref->base.ts = UtilLastModified(path);
|
||||
ref->base.json = JsonDecode(stream);
|
||||
ref->stream = stream;
|
||||
ref->fd = fd;
|
||||
if (!ref->base.json)
|
||||
{
|
||||
Free(ref);
|
||||
|
@ -162,7 +157,10 @@ FlatLock(Db *d, Array *dir)
|
|||
ref->base.name = ArrayCreate();
|
||||
for (i = 0; i < ArraySize(dir); i++)
|
||||
{
|
||||
StringArrayAppend(ref->base.name, ArrayGet(dir, i));
|
||||
ArrayAdd(
|
||||
ref->base.name,
|
||||
StrDuplicate(ArrayGet(dir, i))
|
||||
);
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
@ -248,6 +246,7 @@ FlatCreate(Db *d, Array *dir)
|
|||
|
||||
/* FlatLock() will lock again for us */
|
||||
pthread_mutex_unlock(&d->lock);
|
||||
|
||||
ret = FlatLock(d, dir);
|
||||
|
||||
return ret;
|
||||
|
@ -256,7 +255,7 @@ FlatCreate(Db *d, Array *dir)
|
|||
static bool
|
||||
FlatDelete(Db *d, Array *dir)
|
||||
{
|
||||
bool ret = false;
|
||||
bool ret = true;
|
||||
char *file;
|
||||
FlatDb *db = (FlatDb *) d;
|
||||
if (!d || !dir)
|
||||
|
@ -274,7 +273,7 @@ FlatDelete(Db *d, Array *dir)
|
|||
}
|
||||
|
||||
Free(file);
|
||||
pthread_mutex_unlock(&d->lock);
|
||||
pthread_mutex_lock(&d->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -356,7 +355,7 @@ DbOpen(char *dir, size_t cache)
|
|||
return NULL;
|
||||
}
|
||||
db = Malloc(sizeof(*db));
|
||||
DbInit((Db *) db);
|
||||
DbInit(&(db->base));
|
||||
db->dir = dir;
|
||||
db->base.cacheSize = cache;
|
||||
|
||||
|
|
|
@ -184,8 +184,6 @@ HashMapDelete(HashMap * map, const char *key)
|
|||
if (bucket->hash == hash)
|
||||
{
|
||||
bucket->hash = 0;
|
||||
Free(bucket->key);
|
||||
bucket->key = NULL;
|
||||
return bucket->value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue