[lxc-devel] [distrobuilder/master] shared/chroot: Fix parent directory symlink again

monstermunchkin on Github lxc-bot at linuxcontainers.org
Thu Jun 18 11:07:18 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200618/e4dd53f6/attachment.bin>
-------------- next part --------------
From 797e1813f34ebe0f7713a380fa09958e863dccbe Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 18 Jun 2020 13:06:59 +0200
Subject: [PATCH] shared/chroot: Fix parent directory symlink again

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/chroot.go | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/shared/chroot.go b/shared/chroot.go
index ff42b0c..263f707 100644
--- a/shared/chroot.go
+++ b/shared/chroot.go
@@ -92,24 +92,26 @@ func moveMounts(mounts []ChrootMount) error {
 		// If the target's parent directory is a symlink, we need to resolve that as well.
 		targetDir := filepath.Dir(target)
 
-		// Get information on current target
-		fi, err := os.Lstat(targetDir)
-		if err != nil {
-			return err
-		}
-
-		// If a symlink, resolve it
-		if fi.Mode()&os.ModeSymlink != 0 {
-			newTarget, err := os.Readlink(targetDir)
+		if lxd.PathExists(targetDir) {
+			// Get information on current target
+			fi, err := os.Lstat(targetDir)
 			if err != nil {
 				return err
 			}
 
-			targetDir = newTarget
+			// If a symlink, resolve it
+			if fi.Mode()&os.ModeSymlink != 0 {
+				newTarget, err := os.Readlink(targetDir)
+				if err != nil {
+					return err
+				}
+
+				targetDir = newTarget
+			}
 		}
 
 		// Create parent paths if missing
-		err = os.MkdirAll(targetDir, 0755)
+		err := os.MkdirAll(targetDir, 0755)
 		if err != nil {
 			return err
 		}


More information about the lxc-devel mailing list