[Pkg-privacy-commits] [tails-installer] 05/07: Windows didn't like deleting files that are open in a different thread

Intrigeri intrigeri at moszumanska.debian.org
Wed May 24 15:27:45 UTC 2017


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to tag 3.93.2
in repository tails-installer.

commit 1f6b10e41f1aa7d7df5f4d67879e313e30bbe6a7
Author: Martin Bříza <m at rtinbriza.cz>
Date:   Fri Apr 22 17:34:11 2016 +0200

    Windows didn't like deleting files that are open in a different thread
---
 liveusb/grabber.py | 15 ++++++++++-----
 liveusb/gui.py     | 19 ++++++++++++-------
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/liveusb/grabber.py b/liveusb/grabber.py
index 4bd52b3..e2ab601 100644
--- a/liveusb/grabber.py
+++ b/liveusb/grabber.py
@@ -63,7 +63,7 @@ def cancel_download(url, target_folder=find_downloads()):
     if os.path.exists(partial_path):
         os.remove(partial_path)
 
-def download(url, target_folder=find_downloads(), update_maximum = None, update_current = None):
+def download(parent, url, target_folder=find_downloads(), update_maximum = None, update_current = None):
     CHUNK_SIZE = 1024 * 1024
     current_size = 0
 
@@ -100,10 +100,15 @@ def download(url, target_folder=find_downloads(), update_maximum = None, update_
             chown_file(partial_path)
 
             for chunk in r.iter_content(CHUNK_SIZE):
-                f.write(chunk)
-                bytes_read += len(chunk)
-                if update_current:
-                    update_current(bytes_read)
+                if not parent.beingCancelled:
+                    f.write(chunk)
+                    bytes_read += len(chunk)
+                    if update_current:
+                        update_current(bytes_read)
+                else:
+                    f.close()
+                    cancel_download(url, target_folder)
+                    return None
 
         os.rename(partial_path, full_path)
 
diff --git a/liveusb/gui.py b/liveusb/gui.py
index 6dc8d9f..5522390 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -70,6 +70,8 @@ class ReleaseDownloadThread(QThread):
     downloadFinished = pyqtSignal(str)
     downloadError = pyqtSignal(str)
 
+    beingCancelled = False
+
     def __init__(self, progress, proxies):
         QThread.__init__(self)
         self.progress = progress
@@ -77,15 +79,18 @@ class ReleaseDownloadThread(QThread):
 
     def run(self):
         try:
-            filename = grabber.download(self.progress.release.url, update_maximum=self.progress.start, update_current=self.progress.update)
-            self.progress.end()
-            self.downloadFinished.emit(filename)
+            self.beingCancelled = False
+            filename = grabber.download(self, self.progress.release.url, update_maximum=self.progress.start, update_current=self.progress.update)
+            if filename:
+                self.progress.end()
+                self.downloadFinished.emit(filename)
         except LiveUSBError as e:
             self.downloadError.emit(e.args[0])
 
-    def terminate(self):
-        QThread.terminate(self)
-        grabber.cancel_download(self.progress.release.url)
+    @pyqtSlot()
+    def cancelDownload(self):
+        self.beingCancelled = True
+
 
 class ReleaseDownload(QObject):
     """ Wrapper for the iso download process.
@@ -158,7 +163,7 @@ class ReleaseDownload(QObject):
 
     @pyqtSlot()
     def cancel(self):
-        self._grabber.terminate()
+        self._grabber.cancelDownload()
         self.reset()
 
     @pyqtProperty(float, notify=maximumChanged)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/tails-installer.git



More information about the Pkg-privacy-commits mailing list