[Pkg-privacy-commits] [tails-installer] 03/08: Save partial downloads as .part
Intrigeri
intrigeri at moszumanska.debian.org
Wed May 24 15:27:36 UTC 2017
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to tag 3.93.1
in repository tails-installer.
commit 42f9168402d822d44ad68ba02efd94b1966e53aa
Author: Martin Briza <mbriza at redhat.com>
Date: Thu Apr 21 12:01:57 2016 +0200
Save partial downloads as .part
---
liveusb/grabber.py | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/liveusb/grabber.py b/liveusb/grabber.py
index 12fd495..275fc4b 100644
--- a/liveusb/grabber.py
+++ b/liveusb/grabber.py
@@ -47,15 +47,17 @@ def chown_file(path):
else:
pass
-
def download(url, target_folder=find_downloads(), update_maximum = None, update_current = None):
CHUNK_SIZE = 1024 * 1024
current_size = 0
file_name = os.path.basename(url)
full_path = os.path.join(target_folder, file_name)
+ partial_path = full_path + ".part"
if os.path.exists(full_path):
- current_size = os.path.getsize(full_path)
+ return full_path
+ elif os.path.exists(partial_path):
+ current_size = os.path.getsize(partial_path)
bytes_read = current_size
if current_size > 0:
@@ -78,8 +80,8 @@ def download(url, target_folder=find_downloads(), update_maximum = None, update_
if update_maximum:
update_maximum(current_size + int(r.headers['Content-Length']))
- with open(full_path, mode) as f:
- chown_file(full_path)
+ with open(partial_path, mode) as f:
+ chown_file(partial_path)
for chunk in r.iter_content(CHUNK_SIZE):
f.write(chunk)
@@ -87,6 +89,8 @@ def download(url, target_folder=find_downloads(), update_maximum = None, update_
if update_current:
update_current(bytes_read)
+ os.rename(partial_path, full_path)
+
except requests.exceptions.ReadTimeout as e:
raise LiveUSBError("Your internet connection seems to be broken")
except requests.exceptions.ConnectTimeout as e:
--
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