From f217c243739ada7164aaa9c9a0a47784b99ad4de Mon Sep 17 00:00:00 2001 From: Mateus Melchiades Date: Sat, 16 Dec 2023 13:45:02 -0300 Subject: [PATCH] fix: Export/unexport --- core/dbox.go | 11 ++++++++--- core/subSystem.go | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/core/dbox.go b/core/dbox.go index b5803dbf..30b7e1e4 100644 --- a/core/dbox.go +++ b/core/dbox.go @@ -135,6 +135,11 @@ func (d *dbox) RunCommand(command string, args []string, engineFlags []string, u if captureOutput { output, err := cmd.Output() + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + return output, errors.New(string(exitErr.Stderr)) + } + } return output, err } @@ -297,7 +302,7 @@ func (d *dbox) ContainerExport(name string, delete bool, rootFull bool, args ... finalArgs = append(finalArgs, args...) - _, err := d.ContainerExec(name, false, true, rootFull, finalArgs...) + _, err := d.ContainerExec(name, true, true, rootFull, finalArgs...) return err } @@ -316,7 +321,7 @@ func (d *dbox) ContainerExportBin(containerName string, binary string, exportPat return d.ContainerExport(containerName, false, rootFull, args...) } -func (d *dbox) ContainerUnexportBin(containerName string, binary string, exportPath string, rootFull bool) error { - args := []string{"--bin", binary, "--export-path", exportPath} +func (d *dbox) ContainerUnexportBin(containerName string, binary string, rootFull bool) error { + args := []string{"--bin", binary} return d.ContainerExport(containerName, true, rootFull, args...) } diff --git a/core/subSystem.go b/core/subSystem.go index e04dd1ee..67e4c752 100644 --- a/core/subSystem.go +++ b/core/subSystem.go @@ -2,7 +2,7 @@ package core import ( "fmt" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -68,7 +68,7 @@ func findExportedPrograms(internalName string, name string) map[string]map[strin } defer f.Close() - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { continue } @@ -311,8 +311,7 @@ func (s *SubSystem) ExportBin(binary string, exportPath string) error { return err } - binary = binaryPath - binary = strings.TrimSuffix(binary, "\r\n") + binary = strings.TrimSpace(binaryPath) } binaryName := filepath.Base(binary) @@ -328,7 +327,7 @@ func (s *SubSystem) ExportBin(binary string, exportPath string) error { } if exportPath == "" { - exportPath = fmt.Sprintf("%s/%s", homeDir, ".local/bin") + exportPath = filepath.Join(homeDir, ".local", "bin") } joinedPath := filepath.Join(exportPath, binaryName) @@ -385,10 +384,19 @@ func (s *SubSystem) UnexportDesktopEntry(appName string) error { } func (s *SubSystem) UnexportBin(binary string, exportPath string) error { + if !strings.HasPrefix(binary, "/") { + binaryPath, err := s.Exec(true, "which", binary) + if err != nil { + return err + } + + binary = strings.TrimSpace(binaryPath) + } + dbox, err := NewDbox() if err != nil { return err } - return dbox.ContainerUnexportBin(s.InternalName, binary, exportPath, s.IsRootfull) + return dbox.ContainerUnexportBin(s.InternalName, binary, s.IsRootfull) }