-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Adam Pickering <[email protected]>
- Loading branch information
1 parent
3aad632
commit 4092dc1
Showing
5 changed files
with
55 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//go:build linux || darwin | ||
|
||
package utils | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"golang.org/x/sys/unix" | ||
"io/fs" | ||
"os" | ||
) | ||
|
||
// Verify that the candidatePath is usable as a Rancher Desktop "executable". This means: | ||
// - check that candidatePath exists | ||
// - if checkExecutability is true, check that candidatePath is a regular file, | ||
// and that it is executable | ||
// | ||
// Note that candidatePath may not always be a file; in macOS, it may be a | ||
// .app directory. | ||
func checkUsableApplication(candidatePath string, checkExecutability bool) (bool, error) { | ||
statResult, err := os.Stat(candidatePath) | ||
if errors.Is(err, fs.ErrNotExist) { | ||
return false, nil | ||
} | ||
if err != nil { | ||
return false, fmt.Errorf("failed to get info on %q: %w", candidatePath, err) | ||
} | ||
|
||
if !checkExecutability { | ||
return true, nil | ||
} | ||
|
||
if !statResult.Mode().IsRegular() { | ||
return false, nil | ||
} | ||
|
||
err = unix.Access(candidatePath, unix.X_OK) | ||
return err == nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters