Skip to content

Commit

Permalink
fix:[#420] abort export if bin in $PATH
Browse files Browse the repository at this point in the history
- abort if bin or output in $PATH
- en translation for abort message
  • Loading branch information
jardon committed Oct 25, 2024
1 parent 1ae5a88 commit e227cf7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cmd/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package cmd
import (
"fmt"
"slices"
"os/exec"

"github.com/spf13/cobra"
"github.com/vanilla-os/apx/v2/core"
Expand Down Expand Up @@ -357,9 +358,15 @@ func handleExport(subSystem *core.SubSystem, command, appName, bin, binOutput st

cmdr.Info.Printfln(apx.Trans("runtimeCommand.info.exportedApp"), appName)
} else {
err := subSystem.ExportBin(bin, binOutput)
if err != nil {
return fmt.Errorf(apx.Trans("runtimeCommand.error.exportingBin"), err)
_, binErr := exec.LookPath(bin)
_, outErr := exec.LookPath(binOutput)
if binErr != nil && outErr != nil {
err := subSystem.ExportBin(bin, binOutput)
if err != nil {
return fmt.Errorf(apx.Trans("runtimeCommand.error.exportingBin"), err)
}
} else {
return fmt.Errorf(apx.Trans("runtimeCommand.error.protectedBin"))
}

cmdr.Info.Printfln(apx.Trans("runtimeCommand.info.exportedBin"), bin)
Expand Down
1 change: 1 addition & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ runtimeCommand:
unexportingBin: "An error occurred while unexporting the binary: %s"
startingContainer: "An error occurred while starting the container: %s"
stoppingContainer: "An error occurred while stopping the container: %s"
protectedBin: "Binary already exists on the host."
info:
unexportedApps: "Unexported %d applications"
exportedApps: "Exported %d applications"
Expand Down

0 comments on commit e227cf7

Please sign in to comment.