src/macosx/native/java/util/MacOSXPreferencesFile.m

Print this page

        

@@ -639,11 +639,11 @@
     if (name) CFRelease(name);
 }
 
 
 // child must end with '/'
-JNIEXPORT void JNICALL
+JNIEXPORT Boolean JNICALL
 Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
  jobject jname, jlong juser, jlong jhost)
 {
     // like addNode, but can put a three-level-deep dict into the root file

@@ -654,22 +654,26 @@
     CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
     CFMutableDictionaryRef parent;
     CFDictionaryRef node;
     CFStringRef topKey;
     CFMutableDictionaryRef topValue;
+    Boolean beforeAdd = false;
 
     if (!path  ||  !child  ||  !name) goto badparams;
 
     node = createEmptyNode();
     throwIfNull(node, "createEmptyNode failed");
 
     // copyMutableNode creates the node if necessary
     parent = copyMutableNode(path, name, user, host, &topKey, &topValue);
     throwIfNull(parent, "copyMutableNode failed");
-
+    beforeAdd = CFDictionaryContainsKey(parent, child);
     CFDictionaryAddValue(parent, child, node);
-
+    if (!beforeAdd)
+        beforeAdd = CFDictionaryContainsKey(parent, child);
+    else
+        beforeAdd = false;
     CFPreferencesSetValue(topKey, topValue, name, user, host);
 
     CFRelease(parent);
     if (topKey) CFRelease(topKey);
     if (topValue) CFRelease(topValue);

@@ -678,10 +682,11 @@
  badnode:
  badparams:
     if (path) CFRelease(path);
     if (child) CFRelease(child);
     if (name) CFRelease(name);
+    return beforeAdd;
 }
 
 
 JNIEXPORT void JNICALL
 Java_java_util_prefs_MacOSXPreferencesFile_removeChildFromNode