[lxc-devel] [distrobuilder/master] chroot: Resolve parent directory symlinks
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Wed Jun 17 06:33:53 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/20200616/3040d818/attachment.bin>
-------------- next part --------------
From 9200330b17dd49dd2a1f47814d6329825478963d Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 17 Jun 2020 08:31:49 +0200
Subject: [PATCH] chroot: Resolve parent directory symlinks
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
shared/chroot.go | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/shared/chroot.go b/shared/chroot.go
index f196d59..7ba07eb 100644
--- a/shared/chroot.go
+++ b/shared/chroot.go
@@ -89,8 +89,31 @@ func moveMounts(mounts []ChrootMount) error {
target = newTarget
}
+ // If the target's parent directory is a symlink, we need to resolve that as well.
+ targetDir := filepath.Dir(target)
+ for {
+ // Get information on current target
+ fi, err := os.Lstat(targetDir)
+ if err != nil {
+ break
+ }
+
+ // If not a symlink, we're done
+ if fi.Mode()&os.ModeSymlink == 0 {
+ break
+ }
+
+ // If a symlink, resolve it
+ newTarget, err := os.Readlink(targetDir)
+ if err != nil {
+ break
+ }
+
+ targetDir = newTarget
+ }
+
// Create parent paths if missing
- err := os.MkdirAll(filepath.Dir(target), 0755)
+ err := os.MkdirAll(targetDir, 0755)
if err != nil {
return err
}
More information about the lxc-devel
mailing list