Use fsx package and friends from pkglib

This commit is contained in:
Tom Wiesing 2023-04-08 17:51:17 +02:00
parent 1f8c55da7c
commit 0f6803f890
No known key found for this signature in database
35 changed files with 91 additions and 493 deletions

View file

@ -5,7 +5,7 @@ import (
"path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/pkglib/fsx"
)
type PathsConfig struct {
@ -38,14 +38,14 @@ func (pcfg PathsConfig) UsingDistilleryExecutable() bool {
if err != nil {
return false
}
return fsx.SameFile(exe, pcfg.ExecutablePath())
return fsx.Same(exe, pcfg.ExecutablePath())
}
// CurrentExecutable returns the path to the current executable being used.
// When it does not exist, falls back to the default executable.
func (pcfg PathsConfig) CurrentExecutable() string {
exe, err := os.Executable()
if err != nil || !fsx.IsFile(exe) {
if err != nil || !fsx.IsRegular(exe) {
return pcfg.ExecutablePath()
}
return exe

View file

@ -1,15 +1,15 @@
package validators
import (
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/pkg/errors"
"github.com/tkw1536/pkglib/fsx"
)
func ValidateFile(path *string, dflt string) error {
if *path == "" {
*path = dflt
}
if !fsx.IsFile(*path) {
if !fsx.IsRegular(*path) {
return errors.Errorf("%q does not exist or is not a file", *path)
}
return nil