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
=== modified file 'softwarecenter/utils.py'
--- softwarecenter/utils.py 2012-08-28 13:39:02 +0000
+++ softwarecenter/utils.py 2012-09-25 08:35:39 +0000
@@ -837,11 +837,28 @@
837 f.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_SIZE, 0, 0,837 f.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_SIZE, 0, 0,
838 self._cancellable,838 self._cancellable,
839 self._check_url_reachable_and_then_download_cb,839 self._check_url_reachable_and_then_download_cb,
840 None)840 url)
841841
842 def _check_url_reachable_and_then_download_cb(self, f, result,842 def _ensure_correct_url(self, want_url):
843 user_data=None):843 """This function will ensure that the url we requested to download
844 earlier matches that is now downloaded.
845 """
846 # this function is needed as there is a rance condition when the
847 # operation is finished but the signal is not delivered yet (its
848 # still in the gtk event loop). in this case there is nothing to
849 # self._cancel but self.url/self.dest_file_path will still point to
850 # the wrong file
851 if self.url != want_url:
852 self.LOG.warn("url changed from '%s' to '%s'" % (
853 want_url, self.url))
854 return False
855 return True
856
857 def _check_url_reachable_and_then_download_cb(self, f, result, want_url):
844 self.LOG.debug("_check_url_reachable_and_then_download_cb: %s" % f)858 self.LOG.debug("_check_url_reachable_and_then_download_cb: %s" % f)
859 if not self._ensure_correct_url(want_url):
860 return
861 # normal operation
845 try:862 try:
846 info = f.query_info_finish(result)863 info = f.query_info_finish(result)
847 etag = info.get_etag()864 etag = info.get_etag()
@@ -851,15 +868,17 @@
851 etag))868 etag))
852 # url is reachable, now download the file869 # url is reachable, now download the file
853 f.load_contents_async(870 f.load_contents_async(
854 self._cancellable, self._file_download_complete_cb, None)871 self._cancellable, self._file_download_complete_cb, want_url)
855 except GObject.GError as e:872 except GObject.GError as e:
856 self.LOG.debug("file *not* reachable %s" % self.url)873 self.LOG.debug("file *not* reachable %s" % self.url)
857 self.emit('file-url-reachable', False)874 self.emit('file-url-reachable', False)
858 self.emit('error', GObject.GError, e)875 self.emit('error', GObject.GError, e)
859 del f876 del f
860877
861 def _file_download_complete_cb(self, f, result, path=None):878 def _file_download_complete_cb(self, f, result, want_url):
862 self.LOG.debug("file download completed %s" % self.dest_file_path)879 self.LOG.debug("file download completed %s" % self.dest_file_path)
880 if not self._ensure_correct_url(want_url):
881 return
863 # The result from the download is actually a tuple with three882 # The result from the download is actually a tuple with three
864 # elements (content, size, etag?)883 # elements (content, size, etag?)
865 # The first element is the actual content so let's grab that884 # The first element is the actual content so let's grab that

Subscribers

People subscribed via source and target branches