capuchin r57 - trunk/src/libcapuchin
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: capuchin r57 - trunk/src/libcapuchin
- Date: Fri, 7 Mar 2008 21:50:09 +0000 (GMT)
Author: sebp
Date: Fri Mar 7 21:50:09 2008
New Revision: 57
URL: http://svn.gnome.org/viewvc/capuchin?rev=57&view=rev
Log:
Lock access to dictionaries
Modified:
trunk/src/libcapuchin/AppObject.cs
trunk/src/libcapuchin/DownloadManager.cs
Modified: trunk/src/libcapuchin/AppObject.cs
==============================================================================
--- trunk/src/libcapuchin/AppObject.cs (original)
+++ trunk/src/libcapuchin/AppObject.cs Fri Mar 7 21:50:09 2008
@@ -184,7 +184,9 @@
int dlid = Globals.DLM.DownloadFile(this.RepoItems[plugin_id].Url, this.InstallPath, this.RepoItems[plugin_id].Signature, this.RepoItems[plugin_id].Checksum);
- this.DownloadToPluginId.Add(dlid, plugin_id);
+ lock (this) {
+ this.DownloadToPluginId.Add(dlid, plugin_id);
+ }
}
/// <summary>
@@ -226,7 +228,7 @@
{
return this.RepoItems[plugin_id].Changelog[version];
} else {
- return "";
+ return String.Empty;
}
}
@@ -366,28 +368,33 @@
private void OnDownloadStatus (int dlid, double progress, int speed)
{
- if (!this.DownloadToPluginId.ContainsKey(dlid))
- throw new ArgumentException ("Could not find download with id "+dlid);
-
if (dlid == this.repo_dlid)
{
this.OnStatus (ActionType.UpdatingRepo, "", progress, speed);
} else {
- this.OnStatus (ActionType.DownloadingPlugin, this.DownloadToPluginId[dlid], progress, speed);
+ lock (this) {
+ if (!this.DownloadToPluginId.ContainsKey(dlid))
+ throw new ArgumentException ("Could not find download with id "+dlid);
+
+ this.OnStatus (ActionType.DownloadingPlugin, this.DownloadToPluginId[dlid], progress, speed);
+ }
}
}
private void OnDownloadFinished (int dlid)
{
- if (!this.DownloadToPluginId.ContainsKey(dlid))
- throw new ArgumentException ("Could not find download with id "+dlid);
-
if (dlid == this.repo_dlid) {
this.LoadRepository();
return;
}
-
- string plugin_id = this.DownloadToPluginId[dlid];
+
+ string plugin_id = null;
+ lock (this) {
+ if (!this.DownloadToPluginId.ContainsKey(dlid))
+ throw new ArgumentException ("Could not find download with id "+dlid);
+
+ plugin_id = this.DownloadToPluginId[dlid];
+ }
string local_file = Path.Combine( this.InstallPath, Path.GetFileName(this.RepoItems[plugin_id].Url) );
// Check file
@@ -405,7 +412,9 @@
Log.Info("Updated plugin with id '{0}'", plugin_id);
this.OnInstallFinished(plugin_id);
- this.DownloadToPluginId.Remove(dlid);
+ lock (this) {
+ this.DownloadToPluginId.Remove(dlid);
+ }
}
/// <summary>Check whether first argument is newer as second one</summary>
Modified: trunk/src/libcapuchin/DownloadManager.cs
==============================================================================
--- trunk/src/libcapuchin/DownloadManager.cs (original)
+++ trunk/src/libcapuchin/DownloadManager.cs Fri Mar 7 21:50:09 2008
@@ -49,9 +49,11 @@
Thread downloaderThread = new Thread( new ThreadStart(downloader.Download) );
dl.Downloader = downloaderThread;
- this.Downloads.Add( this.downloadsIndex, dl );
- this.downloadsIndex++;
- downloaderThread.Start();
+ lock (this) {
+ this.Downloads.Add( this.downloadsIndex, dl );
+ this.downloadsIndex++;
+ downloaderThread.Start();
+ }
Log.Info("Started downloading file {0} to {1} with id '{2}'", download_url, download_dest, this.downloadsIndex-1);
@@ -63,8 +65,10 @@
public virtual void PauseDownload(int id)
{
Log.Info("Paused download with id '{0}'", id);
- // Kill Downloader Thread
- this.Downloads[id].Downloader.Abort();
+ lock (this) {
+ // Kill Downloader Thread
+ this.Downloads[id].Downloader.Abort();
+ }
}
/// <summary>Abort download</summary>
@@ -73,9 +77,11 @@
{
Log.Info("Aborted download with id '{0}'", id);
- this.PauseDownload(id);
- File.Delete(this.Downloads[id].LocalFile);
- this.Downloads.Remove(id);
+ lock (this) {
+ this.PauseDownload(id);
+ File.Delete(this.Downloads[id].LocalFile);
+ this.Downloads.Remove(id);
+ }
}
/// <summary>Resume download</summary>
@@ -84,21 +90,23 @@
{
// Get file info
FileInfo f = new FileInfo( this.Downloads[id].LocalFile );
- // Get Downloader
- Downloaders.AbstractDownloader downloader = this.GetDownloader(id, this.Downloads[id]);
- // FIXME: Do we really need to connect the signals again?
- downloader.Status += new Downloaders.StatusHandler( this.OnDownloadStatus );
- downloader.Finished += new Downloaders.FinishedHandler( this.DownloadFinishedCallback );
- // Start Thread
- Thread downloaderThread = new Thread( new ParameterizedThreadStart(downloader.Download) );
- this.Downloads[id] = new Download ( id,
- this.Downloads[id].Url,
- this.Downloads[id].Destination,
- this.Downloads[id].Signature,
- this.Downloads[id].Checksum,
- downloaderThread);
- downloaderThread.Start(f.Length);
+ lock (this) {
+ // Get Downloader
+ Downloaders.AbstractDownloader downloader = this.GetDownloader(id, this.Downloads[id]);
+ // FIXME: Do we really need to connect the signals again?
+ downloader.Status += new Downloaders.StatusHandler( this.OnDownloadStatus );
+ downloader.Finished += new Downloaders.FinishedHandler( this.DownloadFinishedCallback );
+ // Start Thread
+ Thread downloaderThread = new Thread( new ParameterizedThreadStart(downloader.Download) );
+ this.Downloads[id] = new Download ( id,
+ this.Downloads[id].Url,
+ this.Downloads[id].Destination,
+ this.Downloads[id].Signature,
+ this.Downloads[id].Checksum,
+ downloaderThread);
+ downloaderThread.Start(f.Length);
+ }
Log.Info("Resuming download with id '{0}'", id);
}
@@ -121,8 +129,10 @@
{
Log.Info("Finished downloading file with id '{0}'", id);
- // Remove Download
- this.Downloads.Remove(id);
+ lock (this) {
+ // Remove Download
+ this.Downloads.Remove(id);
+ }
this.OnDownloadFinished(id);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]