Fix Windows log folder opening
This commit is contained in:
parent
ad8d03fd86
commit
f25d92c4e6
27
main.go
27
main.go
|
|
@ -474,18 +474,31 @@ func openFolder(path string) error {
|
||||||
if strings.TrimSpace(path) == "" {
|
if strings.TrimSpace(path) == "" {
|
||||||
return fmt.Errorf("path is empty")
|
return fmt.Errorf("path is empty")
|
||||||
}
|
}
|
||||||
|
p := filepath.Clean(filepath.FromSlash(path))
|
||||||
|
if abs, err := filepath.Abs(p); err == nil {
|
||||||
|
p = abs
|
||||||
|
}
|
||||||
|
info, err := os.Stat(p)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
if mkErr := os.MkdirAll(p, 0o755); mkErr != nil {
|
||||||
|
return fmt.Errorf("failed to create folder: %w", mkErr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if !info.IsDir() {
|
||||||
|
p = filepath.Dir(p)
|
||||||
|
}
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
p := filepath.Clean(filepath.FromSlash(path))
|
cmd = utils.CreateCommandRaw("explorer", p)
|
||||||
if abs, err := filepath.Abs(p); err == nil {
|
|
||||||
p = abs
|
|
||||||
}
|
|
||||||
cmd = utils.CreateCommandRaw("cmd", "/c", "start", "", p)
|
|
||||||
case "darwin":
|
case "darwin":
|
||||||
cmd = utils.CreateCommandRaw("open", path)
|
cmd = utils.CreateCommandRaw("open", p)
|
||||||
default:
|
default:
|
||||||
cmd = utils.CreateCommandRaw("xdg-open", path)
|
cmd = utils.CreateCommandRaw("xdg-open", p)
|
||||||
}
|
}
|
||||||
return cmd.Start()
|
return cmd.Start()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user