[lxc-devel] [distrobuilder/master] sources: Fix OpenWrt env value

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Sep 10 08:57:58 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190910/9bc8a786/attachment.bin>
-------------- next part --------------
From 005f22ee0184a2cdfaad872d6634f80c2b144986 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 10 Sep 2019 10:57:03 +0200
Subject: [PATCH] sources: Fix OpenWrt env value

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 sources/openwrt-http.go | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/sources/openwrt-http.go b/sources/openwrt-http.go
index 144a434..7f6474b 100644
--- a/sources/openwrt-http.go
+++ b/sources/openwrt-http.go
@@ -142,9 +142,22 @@ func (s *OpenWrtHTTP) Run(definition shared.Definition, rootfsDir string) error
 		return fmt.Errorf("Failed to unpack SDK: %v", err)
 	}
 
+	currentDir, err := os.Getwd()
+	if err != nil {
+		return err
+	}
+	defer os.Chdir(currentDir)
+
 	// Set environment used in the lxd-openwrt scripts
 	os.Setenv("OPENWRT_ROOTFS", filepath.Join(fpath, fname))
-	os.Setenv("OPENWRT_ROOTFS_DIR", rootfsDir)
+
+	// Always use an absolute path
+	if strings.HasPrefix(rootfsDir, "/") {
+		os.Setenv("OPENWRT_ROOTFS_DIR", rootfsDir)
+	} else {
+		os.Setenv("OPENWRT_ROOTFS_DIR", filepath.Join(currentDir, rootfsDir))
+	}
+
 	os.Setenv("OPENWRT_SDK", fmt.Sprintf("build_dir/%s", strings.TrimSuffix(sdk, ".tar.xz")))
 	os.Setenv("OPENWRT_ARCH", definition.Image.Architecture)
 	os.Setenv("OPENWRT_VERSION", release)
@@ -215,12 +228,6 @@ index b7ee533..e89379f 100755
 -#pack_squashfs
 `
 
-	currentDir, err := os.Getwd()
-	if err != nil {
-		return err
-	}
-	defer os.Chdir(currentDir)
-
 	err = os.Chdir(tempScriptsDir)
 	if err != nil {
 		return err


More information about the lxc-devel mailing list