diff --git a/internal/cli/params.go b/internal/cli/params.go index 5a23b0b..64b7b32 100644 --- a/internal/cli/params.go +++ b/internal/cli/params.go @@ -2,6 +2,8 @@ package cli import ( "context" + "errors" + "io/fs" "os" "os/signal" "path/filepath" @@ -19,9 +21,9 @@ type Params struct { // Uses [ReadBaseDirectory] or falls back to [BaseDirectoryDefault]. func ParamsFromEnv() (params Params, err error) { // try to read the base directory! - value, err := ReadBaseDirectory() // TODO: Are we sure about the native environment here? + value, err := ReadBaseDirectory() switch { - case os.IsNotExist(err): + case errors.Is(err, fs.ErrNotExist): params.ConfigPath = bootstrap.BaseDirectoryDefault case err == nil: params.ConfigPath = value diff --git a/internal/dis/component/exporter/exporter.go b/internal/dis/component/exporter/exporter.go index 8b58ce2..260ae0b 100644 --- a/internal/dis/component/exporter/exporter.go +++ b/internal/dis/component/exporter/exporter.go @@ -2,8 +2,9 @@ package exporter import ( "crypto/rand" + "errors" "fmt" - "os" + "io/fs" "path/filepath" "time" @@ -72,7 +73,7 @@ func (*Exporter) newSnapshotName(prefix string) string { // NewStagingDir returns the path to a new snapshot directory. // The directory is guaranteed to have been freshly created. func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) { - for path == "" || os.IsExist(err) { + for path == "" || errors.Is(err, fs.ErrExist) { path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix)) err = fsx.Mkdir(path, fsx.DefaultFilePerm) } diff --git a/internal/dis/component/exporter/iface.go b/internal/dis/component/exporter/iface.go index 73388cf..d8fb1cf 100644 --- a/internal/dis/component/exporter/iface.go +++ b/internal/dis/component/exporter/iface.go @@ -2,7 +2,9 @@ package exporter import ( "context" + "errors" "io" + "io/fs" "os" "path/filepath" @@ -75,7 +77,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta // create the staging directory logging.LogMessage(progress, ctx, "Creating staging directory") err = fsx.Mkdir(stagingDir, fsx.DefaultDirPerm) - if !os.IsExist(err) && err != nil { + if !errors.Is(err, fs.ErrExist) && err != nil { return err } diff --git a/internal/dis/component/exporter/logger/logger.go b/internal/dis/component/exporter/logger/logger.go index 01c71f5..f2b0020 100644 --- a/internal/dis/component/exporter/logger/logger.go +++ b/internal/dis/component/exporter/logger/logger.go @@ -2,6 +2,8 @@ package logger import ( "context" + "errors" + "io/fs" "os" "github.com/FAU-CDI/wisski-distillery/internal/dis/component" @@ -63,7 +65,7 @@ func (log *Logger) Log(ctx context.Context) ([]models.Export, error) { // partition out the exports that have been deleted! parts := collection.Partition(exports, func(s models.Export) bool { _, err := os.Stat(s.Path) - return !os.IsNotExist(err) + return !errors.Is(err, fs.ErrNotExist) }) // go and delete them! diff --git a/internal/dis/component/ssh2/server_hostkeys.go b/internal/dis/component/ssh2/server_hostkeys.go index 5eefddc..7774072 100644 --- a/internal/dis/component/ssh2/server_hostkeys.go +++ b/internal/dis/component/ssh2/server_hostkeys.go @@ -8,6 +8,7 @@ import ( "crypto/x509" "encoding/pem" "io" + "io/fs" "os" "github.com/FAU-CDI/wisski-distillery/pkg/fsx" @@ -65,7 +66,7 @@ func (ssh2 *SSH2) UseOrMakeHostKey(progress io.Writer, ctx context.Context, serv func (ssh2 *SSH2) ReadOrMakeHostKey(progress io.Writer, ctx context.Context, privateKeyPath string, algorithm HostKeyAlgorithm) (key gossh.Signer, err error) { hostKey := NewHostKey(algorithm) - if _, e := os.Lstat(privateKeyPath); os.IsNotExist(e) { // path doesn't exist => generate a new key there! + if _, e := os.Lstat(privateKeyPath); errors.Is(e, fs.ErrNotExist) { // path doesn't exist => generate a new key there! err = ssh2.makeHostKey(progress, ctx, hostKey, privateKeyPath) if err != nil { err = errors.Wrap(err, "Unable to generate new host key") diff --git a/pkg/fsx/copy.go b/pkg/fsx/copy.go index 8869f55..ee9c7c4 100644 --- a/pkg/fsx/copy.go +++ b/pkg/fsx/copy.go @@ -141,7 +141,7 @@ func CopyDirectory(ctx context.Context, dst, src string, onCopy func(dst, src st // create the directory, but ignore an error if the directory already exists. // this is so that we can copy one tree into another tree. err = Mkdir(dst, info.Mode()) - if os.IsExist(err) && IsDirectory(dst) { + if errors.Is(err, fs.ErrExist) && IsDirectory(dst) { err = nil } diff --git a/pkg/fsx/create.go b/pkg/fsx/create.go index df95847..c8d2a14 100644 --- a/pkg/fsx/create.go +++ b/pkg/fsx/create.go @@ -1,6 +1,7 @@ package fsx import ( + "errors" "io/fs" "os" "time" @@ -40,7 +41,7 @@ func Touch(path string, perm fs.FileMode) error { } _, err := os.Stat(path) switch { - case os.IsNotExist(err): + case errors.Is(err, fs.ErrNotExist): f, err := Create(path, perm) if err != nil { return err diff --git a/pkg/fsx/same.go b/pkg/fsx/same.go index 197eea4..c0df9d6 100644 --- a/pkg/fsx/same.go +++ b/pkg/fsx/same.go @@ -1,6 +1,8 @@ package fsx import ( + "errors" + "io/fs" "os" "path/filepath" ) @@ -60,7 +62,7 @@ func couldBeSameFile(path1, path2 string) (same, authorative bool) { } // only 1 file does not exist => they could be different - if os.IsNotExist(err1) != os.IsNotExist(err2) { + if errors.Is(err1, fs.ErrNotExist) != errors.Is(err2, fs.ErrNotExist) { return } } diff --git a/pkg/unpack/resource.go b/pkg/unpack/resource.go index 717abff..304b654 100644 --- a/pkg/unpack/resource.go +++ b/pkg/unpack/resource.go @@ -83,7 +83,7 @@ func installDir(dst string, srcInfo fs.FileInfo, srcFile fs.ReadDirFile, src str // create the destination dstStat, dstErr := os.Stat(dst) switch { - case os.IsNotExist(dstErr): + case errors.Is(dstErr, fs.ErrNotExist): if err := fsx.MkdirAll(dst, srcInfo.Mode()); err != nil { return errors.Wrapf(err, "Error creating destination directory %s", dst) }