Replace deprecated os.Is{Not,}Exist calls
This commit replaces deprecated calls to `os.Is{Not,}Exist` with the
newer `errors.Is(err, fs.Err{Not,}Exist)`.
This commit is contained in:
parent
473040a69f
commit
9807213e60
9 changed files with 22 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue