StorageAPI: Rename pending_delete to deleted

This commit is contained in:
Maschell 2023-01-24 21:41:07 +01:00
parent e7d3027cd6
commit 90d1e51922
2 changed files with 30 additions and 26 deletions

View File

@ -34,7 +34,7 @@ typedef struct wups_storage_item_t_ {
char *key; char *key;
void *data; void *data;
uint32_t data_size; uint32_t data_size;
uint32_t pending_delete; uint32_t deleted;
wups_storage_type_t type; wups_storage_type_t type;
} wups_storage_item_t; } wups_storage_item_t;

View File

@ -25,7 +25,7 @@ void WUPS_InitStorage(wups_loader_init_storage_args_t args) {
rootItem.key = nullptr; rootItem.key = nullptr;
rootItem.data = nullptr; rootItem.data = nullptr;
rootItem.data_size = 0; rootItem.data_size = 0;
rootItem.pending_delete = false; rootItem.deleted = false;
rootItem.type = WUPS_STORAGE_TYPE_ITEM; rootItem.type = WUPS_STORAGE_TYPE_ITEM;
} }
@ -146,12 +146,16 @@ WUPSStorageError WUPS_DeleteItem(wups_storage_item_t *parent, const char *key) {
for (uint32_t i = 0; i < parent->data_size; i++) { for (uint32_t i = 0; i < parent->data_size; i++) {
wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i]; wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i];
if (item->pending_delete || item->type == WUPS_STORAGE_TYPE_INVALID) { if (item->deleted || item->type == WUPS_STORAGE_TYPE_INVALID) {
continue; continue;
} }
if (strcmp(item->key, key) == 0) { if (strcmp(item->key, key) == 0) {
item->pending_delete = true; free(item->data);
free(item->key);
item->key = nullptr;
item->data = nullptr;
item->deleted = true;
return WUPS_STORAGE_ERROR_SUCCESS; return WUPS_STORAGE_ERROR_SUCCESS;
} }
} }
@ -201,7 +205,7 @@ static wups_storage_item_t *addItem(wups_storage_item_t *parent, const char *key
for (uint32_t i = 0; i < parent->data_size; i++) { for (uint32_t i = 0; i < parent->data_size; i++) {
wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i]; wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i];
if (item->pending_delete) { if (item->deleted) {
free(item->data); free(item->data);
free(item->key); free(item->key);
item->data = nullptr; item->data = nullptr;
@ -239,7 +243,7 @@ static wups_storage_item_t *addItem(wups_storage_item_t *parent, const char *key
for (uint32_t j = parent->data_size; j < INCREASE_SIZE_BY; j++) { for (uint32_t j = parent->data_size; j < INCREASE_SIZE_BY; j++) {
auto curItem = &((wups_storage_item_t *) parent->data)[j]; auto curItem = &((wups_storage_item_t *) parent->data)[j];
memset(curItem, 0, sizeof(wups_storage_item_t)); memset(curItem, 0, sizeof(wups_storage_item_t));
curItem->pending_delete = true; curItem->deleted = true;
} }
foundItem = &((wups_storage_item_t *) parent->data)[parent->data_size]; foundItem = &((wups_storage_item_t *) parent->data)[parent->data_size];
@ -248,14 +252,14 @@ static wups_storage_item_t *addItem(wups_storage_item_t *parent, const char *key
foundItem->key = strdup(key); foundItem->key = strdup(key);
if (foundItem->key == nullptr) { if (foundItem->key == nullptr) {
foundItem->pending_delete = true; foundItem->deleted = true;
*error = WUPS_STORAGE_ERROR_MALLOC_FAILED; *error = WUPS_STORAGE_ERROR_MALLOC_FAILED;
return nullptr; return nullptr;
} }
} }
foundItem->type = type; foundItem->type = type;
foundItem->pending_delete = false; foundItem->deleted = false;
foundItem->data = nullptr; foundItem->data = nullptr;
foundItem->data_size = 0; foundItem->data_size = 0;
return foundItem; return foundItem;
@ -314,7 +318,7 @@ WUPSStorageError WUPS_GetSubItem(wups_storage_item_t *parent, const char *key, w
for (uint32_t i = 0; i < parent->data_size; i++) { for (uint32_t i = 0; i < parent->data_size; i++) {
wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i]; wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i];
if (item->pending_delete || item->type != WUPS_STORAGE_TYPE_ITEM) { if (item->deleted || item->type != WUPS_STORAGE_TYPE_ITEM) {
continue; continue;
} }
@ -358,7 +362,7 @@ WUPSStorageError WUPS_StoreString(wups_storage_item_t *parent, const char *key,
item->data = malloc(size); item->data = malloc(size);
if (item->data == nullptr) { if (item->data == nullptr) {
item->key = nullptr; item->key = nullptr;
item->pending_delete = true; item->deleted = true;
return WUPS_STORAGE_ERROR_MALLOC_FAILED; return WUPS_STORAGE_ERROR_MALLOC_FAILED;
} }
item->data_size = size; item->data_size = size;
@ -401,7 +405,7 @@ WUPSStorageError WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int
item->data = malloc(sizeof(int32_t)); item->data = malloc(sizeof(int32_t));
if (item->data == nullptr) { if (item->data == nullptr) {
item->key = nullptr; item->key = nullptr;
item->pending_delete = true; item->deleted = true;
return WUPS_STORAGE_ERROR_MALLOC_FAILED; return WUPS_STORAGE_ERROR_MALLOC_FAILED;
} }
item->data_size = sizeof(int32_t); item->data_size = sizeof(int32_t);
@ -440,7 +444,7 @@ WUPSStorageError WUPS_StoreBinary(wups_storage_item_t *parent, const char *key,
item->data = b64_encode((const uint8_t *) data, size); item->data = b64_encode((const uint8_t *) data, size);
if (item->data == nullptr) { if (item->data == nullptr) {
item->key = nullptr; item->key = nullptr;
item->pending_delete = true; item->deleted = true;
return WUPS_STORAGE_ERROR_MALLOC_FAILED; return WUPS_STORAGE_ERROR_MALLOC_FAILED;
} }
item->data_size = strlen((char *) data) + 1; item->data_size = strlen((char *) data) + 1;
@ -470,7 +474,7 @@ WUPSStorageError WUPS_GetString(wups_storage_item_t *parent, const char *key, ch
for (uint32_t i = 0; i < parent->data_size; i++) { for (uint32_t i = 0; i < parent->data_size; i++) {
wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i]; wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i];
if (item->pending_delete || item->type != WUPS_STORAGE_TYPE_STRING) { if (item->deleted || item->type != WUPS_STORAGE_TYPE_STRING) {
continue; continue;
} }
@ -516,7 +520,7 @@ WUPSStorageError WUPS_GetInt(wups_storage_item_t *parent, const char *key, int32
for (uint32_t i = 0; i < parent->data_size; i++) { for (uint32_t i = 0; i < parent->data_size; i++) {
wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i]; wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i];
if (item->pending_delete || item->type != WUPS_STORAGE_TYPE_INT) { if (item->deleted || item->type != WUPS_STORAGE_TYPE_INT) {
continue; continue;
} }
@ -551,7 +555,7 @@ WUPSStorageError WUPS_GetBinary(wups_storage_item_t *parent, const char *key, vo
for (uint32_t i = 0; i < parent->data_size; i++) { for (uint32_t i = 0; i < parent->data_size; i++) {
wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i]; wups_storage_item_t *item = &((wups_storage_item_t *) parent->data)[i];
if (item->pending_delete || item->type != WUPS_STORAGE_TYPE_STRING) { if (item->deleted || item->type != WUPS_STORAGE_TYPE_STRING) {
continue; continue;
} }