7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
authorkhazra
Thu, 26 Apr 2012 12:04:29 -0700
changeset 12553 cf79383bbfaf
parent 12552 06a22aed06d1
child 12554 8ad224a1f882
7118100: (prefs) Inconsistency when using system and user preference on OSX Lion Summary: Enable user to read/write preferences to persistent storage Reviewed-by: alanb
jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java
jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java
--- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Wed Apr 25 12:31:31 2012 -0700
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Thu Apr 26 12:04:29 2012 -0700
@@ -231,8 +231,14 @@
             if (isRemoved())
                 throw new IllegalStateException("Node has been removed");
             // fixme! overkill
-            if (!MacOSXPreferencesFile.syncWorld()) {
-                throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+            if (isUser) {
+                if (!MacOSXPreferencesFile.syncUser()) {
+                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+                }
+            } else {
+                if (!MacOSXPreferencesFile.syncWorld()) {
+                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+                }
             }
         }
     }
--- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Wed Apr 25 12:31:31 2012 -0700
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Thu Apr 26 12:04:29 2012 -0700
@@ -192,6 +192,39 @@
     }
 
 
+    // Sync only current user preferences
+    static synchronized boolean syncUser() {
+        boolean ok = true;
+        if (cachedFiles != null  &&  !cachedFiles.isEmpty()) {
+            Iterator<WeakReference> iter = cachedFiles.values().iterator();
+            while (iter.hasNext()) {
+                WeakReference ref = iter.next();
+                MacOSXPreferencesFile f = (MacOSXPreferencesFile)ref.get();
+                if (f != null && f.user == cfCurrentUser) {
+                    if (!f.synchronize()) {
+                        ok = false;
+                    }
+                } else {
+                    iter.remove();
+                }
+            }
+        }
+        // Remove synchronized file from changed file list. The changed files were
+        // guaranteed to have been in the cached file list (because there was a strong
+        // reference from changedFiles.
+        if (changedFiles != null) {
+            Iterator<MacOSXPreferencesFile> iterChanged = changedFiles.iterator();
+            while (iterChanged.hasNext()) {
+                MacOSXPreferencesFile f = iterChanged.next();
+                if (f != null && f.user == cfCurrentUser)
+                    iterChanged.remove();
+             }
+        }
+        return ok;
+    }
+
+
+
     // Write all prefs changes to disk, but do not clear all cached prefs
     // values. Also kills any scheduled flush task.
     // There's no CFPreferencesFlush() (<rdar://problem/3049129>), so lots of cached prefs