[game-data-packager] 01/01: check remaining free space before half-downloading same file repeatedly

Alexandre Detiste detiste-guest at moszumanska.debian.org
Wed Jan 6 15:50:18 UTC 2016


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

detiste-guest pushed a commit to branch master
in repository game-data-packager.

commit fbd951c9a3abbd936d4bf20d9e25be98f1b34cbf
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Wed Jan 6 16:49:28 2016 +0100

    check remaining free space before half-downloading same file repeatedly
---
 game_data_packager/build.py | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/game_data_packager/build.py b/game_data_packager/build.py
index 597de79..c20c28a 100644
--- a/game_data_packager/build.py
+++ b/game_data_packager/build.py
@@ -898,7 +898,23 @@ class PackagingTask(object):
                         continue
 
                     logger.debug('... %s', url)
-                    tmp = None
+
+                    if self.save_downloads is not None:
+                        tmp = os.path.join(self.save_downloads,
+                                wanted.name)
+                        tmpdir = os.path.dirname(tmp)
+                    else:
+                        tmp = os.path.join(self.get_workdir(),
+                                'tmp', wanted.name)
+                        tmpdir = os.path.dirname(tmp)
+                        mkdir_p(tmpdir)
+
+                    statvfs = os.statvfs(tmpdir)
+                    if wanted.size > statvfs.f_frsize * statvfs.f_bavail:
+                        logger.error("Out of space on %s, can't download %s.",
+                                      tmpdir, wanted.name)
+                        self.download_failed.add(url)
+                        return FillResult.IMPOSSIBLE
 
                     try:
                         rf = urllib.request.urlopen(urllib.request.Request(
@@ -906,15 +922,6 @@ class PackagingTask(object):
                         if rf is None:
                             continue
 
-                        if self.save_downloads is not None:
-                            tmp = os.path.join(self.save_downloads,
-                                    wanted.name)
-                        else:
-                            tmp = os.path.join(self.get_workdir(),
-                                    'tmp', wanted.name)
-                            tmpdir = os.path.dirname(tmp)
-                            mkdir_p(tmpdir)
-
                         wf = open(tmp, 'wb')
                         logger.info('downloading %s', url)
                         hf = HashedFile.from_file(url, rf, wf,
@@ -933,8 +940,7 @@ class PackagingTask(object):
                         logger.warning('Failed to download "%s": %s', url,
                                 e)
                         self.download_failed.add(url)
-                        if tmp is not None:
-                            os.remove(tmp)
+                        os.remove(tmp)
 
         providers = list(self.game.providers.get(wanted.name, ()))
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list