Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Export/unexport #309

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}