From a05e7d11c9b7ce83374d5dedb640afd443f53f32 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Tue, 8 Nov 2011 13:35:30 +0100 Subject: [PATCH] fix error when chrooting inside a root without /etc chroot failed when root is missing dirs before resolv.conf fil --- installsystems/tools.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/installsystems/tools.py b/installsystems/tools.py index 80cd2eb..36b5357 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -363,11 +363,16 @@ def prepare_chroot(path, mount=True): except CalledProcessError as e: warn("Mount failed: %s.\n" % e) # trick resolv.conf - if os.path.exists("/etc/resolv.conf"): - resolv_path = os.path.join(path, "etc/resolv.conf") - if os.path.exists(resolv_path): - os.rename(resolv_path, "%s.isbackup" % resolv_path) - shutil.copy("/etc/resolv.conf", resolv_path) + try: + if os.path.exists("/etc/resolv.conf"): + resolv_path = os.path.join(path, "etc/resolv.conf") + if os.path.exists(resolv_path): + os.rename(resolv_path, "%s.isbackup" % resolv_path) + if not os.path.exists(os.path.dirname(resolv_path)): + os.makedirs(os.path.dirname(resolv_path)) + shutil.copy("/etc/resolv.conf", resolv_path) + except Exception as e: + warn("resolv.conf tricks fail: %s" % e) # try to guest distro distro = guess_distro(path) # in case of debian disable policy -- GitLab