1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-23 11:43:26 +00:00

Updated to better support readonly filesystems

This commit is contained in:
Bryan Roe
2020-07-18 00:32:35 -07:00
parent 1337c449cc
commit af9ce34a6f
2 changed files with 41 additions and 3 deletions

View File

@@ -4111,6 +4111,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
int ixr = 0; int ixr = 0;
int installFlag = 0; int installFlag = 0;
int fetchstate = 0; int fetchstate = 0;
int readonly = 0;
for (ri = 0; ri < paramLen; ++ri) for (ri = 0; ri < paramLen; ++ri)
{ {
@@ -4143,6 +4144,11 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
{ {
if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); } if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); }
ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1)); ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1));
if (ix - 2 == 8 && strncmp(param[ri] + 2, "readonly", 8) == 0 && strncmp(param[ri] + ix + 1, "1", 1) == 0)
{
// Read-only File System specified
readonly = 1;
}
++ixr; ++ixr;
} }
} }
@@ -4218,7 +4224,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
} }
else else
{ {
if (agentHost->masterDb == NULL || ILibSimpleDataStore_IsCacheOnly(agentHost->masterDb)) if (agentHost->masterDb == NULL || (ILibSimpleDataStore_IsCacheOnly(agentHost->masterDb) && readonly == 0))
{ {
void **data = (void**)ILibMemory_SmartAllocate(4 * sizeof(void*)); void **data = (void**)ILibMemory_SmartAllocate(4 * sizeof(void*));
data[0] = agentHost; data[0] = agentHost;

View File

@@ -106,6 +106,7 @@ typedef struct ILibSimpleDataStore_TableEntry
} ILibSimpleDataStore_TableEntry; } ILibSimpleDataStore_TableEntry;
typedef struct ILibSimpleDataStore_CacheEntry typedef struct ILibSimpleDataStore_CacheEntry
{ {
char valueHash[SHA384HASHSIZE];
int valueLength; int valueLength;
char value[]; char value[];
}ILibSimpleDataStore_CacheEntry; }ILibSimpleDataStore_CacheEntry;
@@ -146,6 +147,14 @@ void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int
ILibSimpleDataStore_CacheEntry *entry = (ILibSimpleDataStore_CacheEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_CacheEntry) + valueLen, 0, NULL, NULL); ILibSimpleDataStore_CacheEntry *entry = (ILibSimpleDataStore_CacheEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_CacheEntry) + valueLen, 0, NULL, NULL);
entry->valueLength = valueLen; entry->valueLength = valueLen;
if (valueLen > 0) { memcpy_s(entry->value, valueLen, value, valueLen); } if (valueLen > 0) { memcpy_s(entry->value, valueLen, value, valueLen); }
if (vhash != NULL)
{
memcpy_s(entry->valueHash, sizeof(entry->valueHash), vhash, SHA384HASHSIZE);
}
else
{
ILibSimpleDataStore_SHA384(value, valueLen, entry->valueHash);
}
ILibHashtable_Put(root->cacheTable, NULL, key, keyLen, entry); ILibHashtable_Put(root->cacheTable, NULL, key, keyLen, entry);
if (vhash != NULL) { ILibMemory_Free(key); } if (vhash != NULL) { ILibMemory_Free(key); }
@@ -883,9 +892,32 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen) __EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen)
{ {
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore; ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
ILibSimpleDataStore_TableEntry *entry; ILibSimpleDataStore_TableEntry *entry = NULL;
if (root == NULL) return NULL; if (root == NULL) return NULL;
if (root->cacheTable != NULL)
{
ILibSimpleDataStore_CacheEntry *centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, key, keyLen);
if (centry == NULL)
{
// Let's check if this is a compressed record entry
size_t tmplen = 0;
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, keyLen);
centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
if (centry != NULL)
{
ILibMemory_Free(tmpkey);
return(centry->valueHash);
}
}
if (centry != NULL)
{
return(centry->valueHash);
}
}
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, keyLen); entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, keyLen);
if (entry == NULL) if (entry == NULL)
{ {
@@ -1062,7 +1094,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_Compact(ILibSimpleDataStore dataStore)
void* state[2]; void* state[2];
int retVal = 0; int retVal = 0;
if (root == NULL || root->dirtySize < root->minimumDirtySize) return 1; // Error if (root == NULL || root->dirtySize < root->minimumDirtySize || root->filePath == NULL) return 1; // Error
tmp = ILibString_Cat(root->filePath, -1, ".tmp", -1); // Create the name of the temporary data store tmp = ILibString_Cat(root->filePath, -1, ".tmp", -1); // Create the name of the temporary data store
// Start by opening a temporary .tmp file. Will be used to write the compacted data store. // Start by opening a temporary .tmp file. Will be used to write the compacted data store.