Skip to content

Commit

Permalink
fix: Export/unexport
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Dec 16, 2023
1 parent 962b6ee commit f217c24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
11 changes: 8 additions & 3 deletions core/dbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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...)
}
20 changes: 14 additions & 6 deletions core/subSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package core

import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit f217c24

Please sign in to comment.