From 3101c6a0f4284c08614940f5593757794d3263bc Mon Sep 17 00:00:00 2001
From: Sebastien Luttringer <sebastien.luttringer@smartjog.com>
Date: Mon, 5 Dec 2011 14:22:22 +0100
Subject: [PATCH] prepare and unprepare chroot create resolf.conf only if /etc
 exists

---
 installsystems/tools.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/installsystems/tools.py b/installsystems/tools.py
index 1e7d5cb..7bf6570 100644
--- a/installsystems/tools.py
+++ b/installsystems/tools.py
@@ -375,12 +375,10 @@ def prepare_chroot(path, mount=True):
                     warn("Mount failed: %s.\n" % e)
     # trick resolv.conf
     try:
-        if os.path.exists("/etc/resolv.conf"):
+        if os.path.exists("/etc/resolv.conf") and os.path.exists(os.path.join(path, "etc")):
             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)
@@ -404,7 +402,7 @@ def unprepare_chroot(path, mount=True):
     Rollback preparation of a chroot environment inside a directory
     '''
     # untrick resolv.conf
-    if os.path.exists("/etc/resolv.conf"):
+    if os.path.exists("/etc/resolv.conf") and os.path.exists(os.path.join(path, "etc"))::
         resolv_path = os.path.join(path, "etc/resolv.conf")
         if os.path.exists(resolv_path):
             os.unlink(resolv_path)
-- 
GitLab