changeset 5271:a7abba2b71b8

7184287: (prefs) BackingStoreException when calling flush on root node[macosx] Summary: Change implementation to enable user without administrative privileges to call flush Reviewed-by: alanb
author khazra
date Wed, 29 Aug 2012 11:13:10 -0700
parents aa5a30249beb
children eaf58bd0f505
files src/macosx/classes/java/util/prefs/MacOSXPreferences.java src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java
diffstat 2 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Wed Aug 29 11:13:10 2012 -0700
@@ -206,9 +206,14 @@
         // Flush should *not* check for removal, unlike sync, but should
         // prevent simultaneous removal.
         synchronized(lock) {
-            // fixme! overkill
-            if (!MacOSXPreferencesFile.flushWorld()) {
-                throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+            if (isUser) {
+                if (!MacOSXPreferencesFile.flushUser()) {
+                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+                }
+            } else {
+                if (!MacOSXPreferencesFile.flushWorld()) {
+                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+                }
             }
         }
     }
--- a/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Wed Aug 29 11:13:10 2012 -0700
@@ -223,7 +223,23 @@
         return ok;
     }
 
-
+    //Flush only current user preferences
+    static synchronized boolean flushUser() {
+        boolean ok = true;
+        if (changedFiles != null  &&  !changedFiles.isEmpty()) {
+            Iterator<MacOSXPreferencesFile> iterator = changedFiles.iterator();
+            while(iterator.hasNext()) {
+                MacOSXPreferencesFile f = iterator.next();
+                if (f.user == cfCurrentUser) {
+                    if (!f.synchronize())
+                        ok = false;
+                    else
+                        iterator.remove();
+                }
+            }
+        }
+        return ok;
+    }
 
     // Write all prefs changes to disk, but do not clear all cached prefs
     // values. Also kills any scheduled flush task.