[lxc-devel] [lxd/master] lxc: Always use HostPathFollow

stgraber on Github lxc-bot at linuxcontainers.org
Sun Sep 27 15:22:25 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200927/5f9aa945/attachment.bin>
-------------- next part --------------
From 2fc5e6a4a6afeba16c69e80b2d0d1a8adbaff4f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sun, 27 Sep 2020 11:21:51 -0400
Subject: [PATCH] lxc: Always use HostPathFollow
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #7937

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/config_trust.go   |  2 +-
 lxc/file.go           |  4 ++--
 lxc/image.go          | 20 ++++++++++----------
 lxc/import.go         |  2 +-
 lxc/manpage.go        |  2 +-
 lxc/storage_volume.go |  4 ++--
 6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lxc/config_trust.go b/lxc/config_trust.go
index 18857283aa..bd95a9bc40 100644
--- a/lxc/config_trust.go
+++ b/lxc/config_trust.go
@@ -84,7 +84,7 @@ func (c *cmdConfigTrustAdd) Run(cmd *cobra.Command, args []string) error {
 
 	// Add trust relationship
 	fname := args[len(args)-1]
-	x509Cert, err := shared.ReadCert(shared.HostPath(fname))
+	x509Cert, err := shared.ReadCert(shared.HostPathFollow(fname))
 	if err != nil {
 		return err
 	}
diff --git a/lxc/file.go b/lxc/file.go
index 77342ad370..dda9cc749b 100644
--- a/lxc/file.go
+++ b/lxc/file.go
@@ -181,7 +181,7 @@ func (c *cmdFileEdit) Run(cmd *cobra.Command, args []string) error {
 	fname := f.Name()
 	f.Close()
 	os.Remove(fname)
-	defer os.Remove(shared.HostPath(fname))
+	defer os.Remove(shared.HostPathFollow(fname))
 
 	// Extract current value
 	err = c.filePull.Run(cmd, append([]string{args[0]}, fname))
@@ -190,7 +190,7 @@ func (c *cmdFileEdit) Run(cmd *cobra.Command, args []string) error {
 	}
 
 	// Spawn the editor
-	_, err = shared.TextEditor(shared.HostPath(fname), []byte{})
+	_, err = shared.TextEditor(shared.HostPathFollow(fname), []byte{})
 	if err != nil {
 		return err
 	}
diff --git a/lxc/image.go b/lxc/image.go
index 587bb7102c..424173691d 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -492,13 +492,13 @@ func (c *cmdImageExport) Run(cmd *cobra.Command, args []string) error {
 	targetMeta := fingerprint
 	if len(args) > 1 {
 		target = args[1]
-		if shared.IsDir(shared.HostPath(args[1])) {
+		if shared.IsDir(shared.HostPathFollow(args[1])) {
 			targetMeta = filepath.Join(args[1], targetMeta)
 		} else {
 			targetMeta = args[1]
 		}
 	}
-	targetMeta = shared.HostPath(targetMeta)
+	targetMeta = shared.HostPathFollow(targetMeta)
 	targetRootfs := targetMeta + ".root"
 
 	// Prepare the files
@@ -560,9 +560,9 @@ func (c *cmdImageExport) Run(cmd *cobra.Command, args []string) error {
 	}
 
 	// Rename files
-	if shared.IsDir(shared.HostPath(target)) {
+	if shared.IsDir(shared.HostPathFollow(target)) {
 		if resp.MetaName != "" {
-			err := os.Rename(targetMeta, shared.HostPath(filepath.Join(target, resp.MetaName)))
+			err := os.Rename(targetMeta, shared.HostPathFollow(filepath.Join(target, resp.MetaName)))
 			if err != nil {
 				os.Remove(targetMeta)
 				os.Remove(targetRootfs)
@@ -572,7 +572,7 @@ func (c *cmdImageExport) Run(cmd *cobra.Command, args []string) error {
 		}
 
 		if resp.RootfsSize > 0 && resp.RootfsName != "" {
-			err := os.Rename(targetRootfs, shared.HostPath(filepath.Join(target, resp.RootfsName)))
+			err := os.Rename(targetRootfs, shared.HostPathFollow(filepath.Join(target, resp.RootfsName)))
 			if err != nil {
 				os.Remove(targetMeta)
 				os.Remove(targetRootfs)
@@ -658,7 +658,7 @@ func (c *cmdImageImport) Run(cmd *cobra.Command, args []string) error {
 
 	for _, arg := range args {
 		split := strings.Split(arg, "=")
-		if len(split) == 1 || shared.PathExists(shared.HostPath(arg)) {
+		if len(split) == 1 || shared.PathExists(shared.HostPathFollow(arg)) {
 			if strings.HasSuffix(arg, ":") {
 				var err error
 				remote, _, err = conf.ParseRemote(arg)
@@ -685,12 +685,12 @@ func (c *cmdImageImport) Run(cmd *cobra.Command, args []string) error {
 		imageFile = args[0]
 	}
 
-	if shared.PathExists(shared.HostPath(filepath.Clean(imageFile))) {
-		imageFile = shared.HostPath(filepath.Clean(imageFile))
+	if shared.PathExists(shared.HostPathFollow(filepath.Clean(imageFile))) {
+		imageFile = shared.HostPathFollow(filepath.Clean(imageFile))
 	}
 
-	if rootfsFile != "" && shared.PathExists(shared.HostPath(filepath.Clean(rootfsFile))) {
-		rootfsFile = shared.HostPath(filepath.Clean(rootfsFile))
+	if rootfsFile != "" && shared.PathExists(shared.HostPathFollow(filepath.Clean(rootfsFile))) {
+		rootfsFile = shared.HostPathFollow(filepath.Clean(rootfsFile))
 	}
 
 	d, err := conf.GetInstanceServer(remote)
diff --git a/lxc/import.go b/lxc/import.go
index 06d3974747..edbb137428 100644
--- a/lxc/import.go
+++ b/lxc/import.go
@@ -57,7 +57,7 @@ func (c *cmdImport) Run(cmd *cobra.Command, args []string) error {
 
 	resource := resources[0]
 
-	file, err := os.Open(shared.HostPath(args[len(args)-1]))
+	file, err := os.Open(shared.HostPathFollow(args[len(args)-1]))
 	if err != nil {
 		return err
 	}
diff --git a/lxc/manpage.go b/lxc/manpage.go
index f3893a15e5..f7f065832b 100644
--- a/lxc/manpage.go
+++ b/lxc/manpage.go
@@ -41,7 +41,7 @@ func (c *cmdManpage) Run(cmd *cobra.Command, args []string) error {
 
 	opts := doc.GenManTreeOptions{
 		Header:           header,
-		Path:             shared.HostPath(args[0]),
+		Path:             shared.HostPathFollow(args[0]),
 		CommandSeparator: ".",
 	}
 
diff --git a/lxc/storage_volume.go b/lxc/storage_volume.go
index 826c3a4875..7bb6229d06 100644
--- a/lxc/storage_volume.go
+++ b/lxc/storage_volume.go
@@ -1755,7 +1755,7 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error {
 		targetName = "backup.tar.gz"
 	}
 
-	target, err := os.Create(shared.HostPath(targetName))
+	target, err := os.Create(shared.HostPathFollow(targetName))
 	if err != nil {
 		return err
 	}
@@ -1824,7 +1824,7 @@ func (c *cmdStorageVolumeImport) Run(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
-	file, err := os.Open(shared.HostPath(args[len(args)-1]))
+	file, err := os.Open(shared.HostPathFollow(args[len(args)-1]))
 	if err != nil {
 		return err
 	}


More information about the lxc-devel mailing list