Fix #831: Disallow work dir being inside the pmbootstrap dir (#852)

This commit is contained in:
Oliver Smith 2017-11-04 02:04:55 +00:00 committed by GitHub
parent 01d1643477
commit 6962803fbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -42,6 +42,15 @@ def ask_for_work_path(args):
try:
ret = os.path.expanduser(pmb.helpers.cli.ask(
args, "Work path", None, args.work, False))
ret = os.path.realpath(ret)
# Work must not be inside the pmbootstrap path
if ret == pmb.config.pmb_src or ret.startswith(pmb.config.pmb_src +
"/"):
logging.fatal("ERROR: The work path must not be inside the"
" pmbootstrap path. Please specify another"
" location.")
continue
# Create the folder with a version file
if not os.path.exists(ret):

View File

@ -129,5 +129,6 @@ def test_questions(args, monkeypatch, tmpdir):
# Work path
tmpdir = str(tmpdir)
answers = ["/dev/null", tmpdir]
answers = ["/dev/null", os.path.dirname(__file__), pmb.config.pmb_src,
tmpdir]
assert pmb.config.init.ask_for_work_path(args) == tmpdir