Improve bulk symlink error handling

If the tempdir doesn't exist, we can get a cryptic error message when
using the bulk_symlink function. This change checks that the temp dir we
are to use exists prior to consuming it and throws a message indicating
the folder doesn't exist.

Change-Id: I3a4bf279d6d1c2c35c000e7b38b147a026cfcfb4
Closes-Bug: #1804527
This commit is contained in:
Alex Schultz 2018-11-21 14:47:13 -07:00
parent 09c8b52a40
commit e348fab951
1 changed files with 7 additions and 1 deletions

View File

@ -1110,7 +1110,12 @@ def bulk_symlink(log, src, dst, tmpd='/tmp'):
"""
log.debug("Symlinking %s to %s, via temp dir %s" %
(src, dst, tmpd))
tmp = None
try:
if not os.path.exists(tmpd):
raise exceptions.NotFound("{} does not exist. Cannot create a "
"temp folder using this path".format(
tmpd))
tmp = tempfile.mkdtemp(dir=tmpd)
subprocess.check_call(['mkdir', '-p', dst])
os.chmod(tmp, 0o755)
@ -1121,7 +1126,8 @@ def bulk_symlink(log, src, dst, tmpd='/tmp'):
except Exception:
raise
finally:
shutil.rmtree(tmp, ignore_errors=True)
if tmp:
shutil.rmtree(tmp, ignore_errors=True)
def run_command_and_log(log, cmd, cwd=None, env=None, retcode_only=True):