Merge lp:~mvo/software-center/downloader-fix-race839462-again-5.2 into lp:software-center/5.2

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3079
Proposed branch: lp:~mvo/software-center/downloader-fix-race839462-again-5.2
Merge into: lp:software-center/5.2
Diff against target: 56 lines (+25/-6)
1 file modified
softwarecenter/utils.py (+25/-6)
To merge this branch: bzr merge lp:~mvo/software-center/downloader-fix-race839462-again-5.2
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+126189@code.launchpad.net

Description of the change

Backport of lp:~mvo/software-center/downloader-fix-race839462-again to the 5.2 branch.

If/once the lp:~mvo/software-center/downloader-fix-race839462-again merging this should just be a formality.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/utils.py'
2--- softwarecenter/utils.py 2012-08-28 13:39:02 +0000
3+++ softwarecenter/utils.py 2012-09-25 08:35:39 +0000
4@@ -837,11 +837,28 @@
5 f.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_SIZE, 0, 0,
6 self._cancellable,
7 self._check_url_reachable_and_then_download_cb,
8- None)
9-
10- def _check_url_reachable_and_then_download_cb(self, f, result,
11- user_data=None):
12+ url)
13+
14+ def _ensure_correct_url(self, want_url):
15+ """This function will ensure that the url we requested to download
16+ earlier matches that is now downloaded.
17+ """
18+ # this function is needed as there is a rance condition when the
19+ # operation is finished but the signal is not delivered yet (its
20+ # still in the gtk event loop). in this case there is nothing to
21+ # self._cancel but self.url/self.dest_file_path will still point to
22+ # the wrong file
23+ if self.url != want_url:
24+ self.LOG.warn("url changed from '%s' to '%s'" % (
25+ want_url, self.url))
26+ return False
27+ return True
28+
29+ def _check_url_reachable_and_then_download_cb(self, f, result, want_url):
30 self.LOG.debug("_check_url_reachable_and_then_download_cb: %s" % f)
31+ if not self._ensure_correct_url(want_url):
32+ return
33+ # normal operation
34 try:
35 info = f.query_info_finish(result)
36 etag = info.get_etag()
37@@ -851,15 +868,17 @@
38 etag))
39 # url is reachable, now download the file
40 f.load_contents_async(
41- self._cancellable, self._file_download_complete_cb, None)
42+ self._cancellable, self._file_download_complete_cb, want_url)
43 except GObject.GError as e:
44 self.LOG.debug("file *not* reachable %s" % self.url)
45 self.emit('file-url-reachable', False)
46 self.emit('error', GObject.GError, e)
47 del f
48
49- def _file_download_complete_cb(self, f, result, path=None):
50+ def _file_download_complete_cb(self, f, result, want_url):
51 self.LOG.debug("file download completed %s" % self.dest_file_path)
52+ if not self._ensure_correct_url(want_url):
53+ return
54 # The result from the download is actually a tuple with three
55 # elements (content, size, etag?)
56 # The first element is the actual content so let's grab that

Subscribers

People subscribed via source and target branches