mmapstorage: refactor file unlinking
@@ -906,22 +906,13 @@ KeySet * copyKeySet (MmapHeader * mmapInfo, KeySet * unlinkKs, MmapHeader * mmap
return (KeySet *) dest;
}
-int elektraMmapstorageSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
-{
- // set all keys
- int errnosave = errno;
- DynArray * dynArray = 0;
-
- KeySet * mappedFiles = (KeySet *) elektraPluginGetData (handle);
- Key * parentCopy = keyDup (parentKey);
- Key * found = ksLookup (mappedFiles, parentCopy, KDB_O_POP);
- if (found)
+static void unlinkFile (Key * parentKey)
{
ELEKTRA_LOG_WARNING ("unlink: need to unlink old mapped memory from file");
const Key * cur;
- keyRewindMeta (found);
- while ((cur = keyNextMeta (found)) != 0)
+ keyRewindMeta (parentKey);
+ while ((cur = keyNextMeta (parentKey)) != 0)
{
void * toUnlinkMmap = hexStringToAddress (keyName (cur));
ELEKTRA_LOG_WARNING ("unlink: unlinking mmap str: %s", keyName (cur));
@@ -943,6 +934,21 @@ int elektraMmapstorageSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Ke
}
// keySetMeta (found, keyName (cur), ""); // delete
}
+}
+
+int elektraMmapstorageSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
+{
+ // set all keys
+ int errnosave = errno;
+ DynArray * dynArray = 0;
+
+ // check if file has open mappings and unlink them
+ KeySet * mappedFiles = (KeySet *) elektraPluginGetData (handle);
+ Key * parentCopy = keyDup (parentKey);
+ Key * found = ksLookup (mappedFiles, parentCopy, KDB_O_POP);
+ if (found)
+ {
+ unlinkFile (found);
keyDel (found);
}
keyDel (parentCopy);
