提交 20b10590 编写于 作者: K khazra

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
上级 f9f7dfd9
......@@ -231,8 +231,14 @@ class MacOSXPreferences extends AbstractPreferences {
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 + "'");
}
}
}
}
......
......@@ -192,6 +192,39 @@ class MacOSXPreferencesFile {
}
// 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册