changeset 4976:b4a447259412

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
author khazra
date Thu, 03 May 2012 21:27:22 +0100
parents ddb615988fbf
children 8888021b9bae
files src/macosx/classes/java/util/prefs/MacOSXPreferences.java src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java
diffstat 2 files changed, 41 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Thu May 03 22:18:06 2012 +0400
+++ b/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Thu May 03 21:27:22 2012 +0100
@@ -228,8 +228,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/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Thu May 03 22:18:06 2012 +0400
+++ b/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Thu May 03 21:27:22 2012 +0100
@@ -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