diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index fdab684..73ee3d1 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -4142,13 +4142,17 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** if ((ix = ILibString_IndexOf(param[ri], len, "=", 1)) > 2 && strncmp(param[ri], "--", 2) == 0) { - if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); } - 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; + if (agentHost->masterDb != NULL) + { + ILibSimpleDataStore_ReOpenReadOnly(agentHost->masterDb, MeshAgent_MakeAbsolutePath(agentHost->exePath, ".db")); + } } + if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); } + ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1)); ++ixr; } } diff --git a/microstack/ILibSimpleDataStore.c b/microstack/ILibSimpleDataStore.c index 4204a6d..bdab619 100644 --- a/microstack/ILibSimpleDataStore.c +++ b/microstack/ILibSimpleDataStore.c @@ -657,7 +657,24 @@ __EXPORT_TYPE ILibSimpleDataStore ILibSimpleDataStore_CreateEx2(char* filePath, if (retVal->dataFile != NULL) { ILibSimpleDataStore_RebuildKeyTable(retVal); } return retVal; } +void ILibSimpleDataStore_ReOpenReadOnly(ILibSimpleDataStore dataStore, char* filePath) +{ + ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore; + if (root->dataFile != NULL) + { +#ifdef _POSIX + flock(fileno(root->dataFile), LOCK_UN); +#endif + fclose(root->dataFile); + } + else + { + root->filePath = ILibString_Copy(filePath, (int)strnlen_s(filePath, ILibSimpleDataStore_MaxFilePath)); + } + root->dataFile = ILibSimpleDataStore_OpenFileEx2(root->filePath, 0, 1); + if (root->dataFile != NULL) { ILibSimpleDataStore_RebuildKeyTable(root); } +} void ILibSimpleDataStore_CacheClear_Sink(ILibHashtable sender, void *Key1, char* Key2, int Key2Len, void *Data, void *user) { if (Data != NULL) { free(Data); } diff --git a/microstack/ILibSimpleDataStore.h b/microstack/ILibSimpleDataStore.h index a4f16df..048ace2 100644 --- a/microstack/ILibSimpleDataStore.h +++ b/microstack/ILibSimpleDataStore.h @@ -46,6 +46,7 @@ __EXPORT_TYPE ILibSimpleDataStore ILibSimpleDataStore_CreateEx2(char* filePath, #define ILibSimpleDataStore_Create(filePath) ILibSimpleDataStore_CreateEx2(filePath, 0, 0) #define ILibSimpleDataStore_CreateEx(filePath, userExtraMemorySize) ILibSimpleDataStore_CreateEx2(filePath, userExtraMemorySize, 0) #define ILibSimpleDataStore_CreateCachedOnly() ILibSimpleDataStore_Create(NULL) +void ILibSimpleDataStore_ReOpenReadOnly(ILibSimpleDataStore dataStore, char* filePath); int ILibSimpleDataStore_IsCacheOnly(ILibSimpleDataStore ds); // Check if the data store exists