Skip to content

Commit

Permalink
lxc/file: Fix edit in snap environment
Browse files Browse the repository at this point in the history
Closes canonical#10323

Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Apr 27, 2022
1 parent 4551d74 commit f2200dd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lxc/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func (c *cmdFileEdit) Run(cmd *cobra.Command, args []string) error {
os.Remove(fname)
defer os.Remove(fname)

// Tell pull/push that they're called from edit.
c.filePull.edit = true
c.filePush.edit = true

// Extract current value
err = c.filePull.Run(cmd, append([]string{args[0]}, fname))
if err != nil {
Expand All @@ -223,6 +227,8 @@ func (c *cmdFileEdit) Run(cmd *cobra.Command, args []string) error {
type cmdFilePull struct {
global *cmdGlobal
file *cmdFile

edit bool
}

func (c *cmdFilePull) Command() *cobra.Command {
Expand Down Expand Up @@ -250,7 +256,11 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error {
}

// Determine the target
target := shared.HostPathFollow(filepath.Clean(args[len(args)-1]))
target := filepath.Clean(args[len(args)-1])
if !c.edit {
target = shared.HostPathFollow(target)
}

targetIsDir := false
sb, err := os.Stat(target)
if err != nil && !os.IsNotExist(err) {
Expand Down Expand Up @@ -417,6 +427,7 @@ type cmdFilePush struct {
global *cmdGlobal
file *cmdFile

edit bool
noModeChange bool
}

Expand Down Expand Up @@ -477,7 +488,11 @@ func (c *cmdFilePush) Run(cmd *cobra.Command, args []string) error {
// Make a list of paths to transfer
sourcefilenames := []string{}
for _, fname := range args[:len(args)-1] {
sourcefilenames = append(sourcefilenames, shared.HostPathFollow(filepath.Clean(fname)))
if !c.edit {
sourcefilenames = append(sourcefilenames, shared.HostPathFollow(filepath.Clean(fname)))
} else {
sourcefilenames = append(sourcefilenames, filepath.Clean(fname))
}
}

// Determine the target mode
Expand Down

0 comments on commit f2200dd

Please sign in to comment.