From 8936fda3915b8ffce196fea9a2b22a0280743ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Mon, 28 Oct 2013 13:14:21 +0200 Subject: [PATCH] Delete temporary downloaded installer zip files after installation of a tool finishes successfully. Closes https://github.com/kripken/emscripten/issues/1699 . --- emsdk | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/emsdk b/emsdk index 516ba49..ce1be52 100644 --- a/emsdk +++ b/emsdk @@ -50,6 +50,13 @@ def file_to_lf(filename): text = text.replace('\r\n', '\n') open(filename, 'wb').write(text) +# Removes a single file, suppressing exceptions on failure. +def rmfile(filename): + try: + os.remove(filename) + except: + pass + def fix_lineendings(filename): if WINDOWS: file_to_crlf(filename) @@ -498,6 +505,8 @@ class Tool: success = tool.install() if not success: return False + print "Done." + return True else: url = self.download_url() if hasattr(self, 'git_branch'): @@ -515,11 +524,20 @@ class Tool: return False print "Done." - # Sanity check that the installation succeeded. - if not self.is_installed(): + # Sanity check that the installation succeeded, and if so, remove unneeded leftover installation files. + if self.is_installed(): + self.cleanup_temp_install_files() + else: print "Warning: The installation of '" + str(self) + "' seems to have failed, but no error was detected. Either something went wrong with the installation, or this may indicate an internal emsdk error." return True + def cleanup_temp_install_files(self): + url = self.download_url() + if url.endswith('zip') or url.endswith('.tar') or url.endswith('.gz'): + file_name = url.split('/')[-1] + tempzipfile = os.path.join('zips/', file_name) + rmfile(tempzipfile) + def uninstall(self): if not self.is_installed(): print "Tool '" + str(self) + "' was not installed. No need to uninstall."