diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-02-14 12:06:18 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-02-14 12:06:18 +0000 |
commit | bd86f57bab1dadeb41d4a25bd42f45c9c1755559 (patch) | |
tree | b49c6a9abeca64ade336abca058fdac8f5e0c877 /morphlib/sourcemanager.py | |
parent | 827d23484b51bb266eedbc7c0fb70529e050acbc (diff) | |
download | morph-bd86f57bab1dadeb41d4a25bd42f45c9c1755559.tar.gz |
Fix potential out of memory errors when fetching large bundles.
Diffstat (limited to 'morphlib/sourcemanager.py')
-rw-r--r-- | morphlib/sourcemanager.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/morphlib/sourcemanager.py b/morphlib/sourcemanager.py index 45431cb1..e6198482 100644 --- a/morphlib/sourcemanager.py +++ b/morphlib/sourcemanager.py @@ -140,15 +140,21 @@ class SourceManager(object): # ex = morphlib.execute.Execute(self.cache_dir, msg=self.msg) # ex.runv(['wget', '-c', url]) # so we do it poorly in pure Python instead - f = urllib2.urlopen(url) - data = f.read() - f.close() t = urlparse.urlparse(url) path = t[2] basename = os.path.basename(path) saved_name = os.path.join(self.cache_dir, basename) - with open(saved_name, 'wb') as f: - f.write(data) + + source_handle = urllib2.urlopen(url) + target_handle = open(saved_name, 'wb') + + data = source_handle.read(4096) + while data: + target_handle.write(data) + data = source_handle.read(4096) + + source_handle.close() + target_handle.close() def _cache_git_from_base_urls(self, repo, ref): treeish = None |