controller: lock when writing avatars. Fixes #476

This commit is contained in:
Hylke Bons 2011-12-11 21:00:40 +01:00
parent 20c6ac32d0
commit 3f70f08084
2 changed files with 8 additions and 3 deletions

View file

@ -523,7 +523,7 @@ namespace SparkleLib {
public void DisableWatching () public void DisableWatching ()
{ {
lock (watch_lock) { lock (this.watch_lock) {
this.watcher.EnableRaisingEvents = false; this.watcher.EnableRaisingEvents = false;
this.local_timer.Stop (); this.local_timer.Stop ();
} }
@ -532,7 +532,7 @@ namespace SparkleLib {
public void EnableWatching () public void EnableWatching ()
{ {
lock (watch_lock) { lock (this.watch_lock) {
this.watcher.EnableRaisingEvents = true; this.watcher.EnableRaisingEvents = true;
this.local_timer.Start (); this.local_timer.Start ();
} }

View file

@ -85,6 +85,8 @@ namespace SparkleShare {
private SparkleFetcherBase fetcher; private SparkleFetcherBase fetcher;
private List<string> failed_avatars = new List<string> (); private List<string> failed_avatars = new List<string> ();
private Object avatar_lock = new Object ();
// Short alias for the translations // Short alias for the translations
public static string _ (string s) public static string _ (string s)
@ -920,7 +922,10 @@ namespace SparkleShare {
// if not empty // if not empty
if (buffer.Length > 255) { if (buffer.Length > 255) {
avatar_fetched = true; avatar_fetched = true;
File.WriteAllBytes (avatar_file_path, buffer);
lock (this.avatar_lock)
File.WriteAllBytes (avatar_file_path, buffer);
SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar for " + email); SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar for " + email);
} }