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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -19,9 +21,9 @@ type Params struct {
|
||||||
// Uses [ReadBaseDirectory] or falls back to [BaseDirectoryDefault].
|
// Uses [ReadBaseDirectory] or falls back to [BaseDirectoryDefault].
|
||||||
func ParamsFromEnv() (params Params, err error) {
|
func ParamsFromEnv() (params Params, err error) {
|
||||||
// try to read the base directory!
|
// try to read the base directory!
|
||||||
value, err := ReadBaseDirectory() // TODO: Are we sure about the native environment here?
|
value, err := ReadBaseDirectory()
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(err):
|
case errors.Is(err, fs.ErrNotExist):
|
||||||
params.ConfigPath = bootstrap.BaseDirectoryDefault
|
params.ConfigPath = bootstrap.BaseDirectoryDefault
|
||||||
case err == nil:
|
case err == nil:
|
||||||
params.ConfigPath = value
|
params.ConfigPath = value
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ package exporter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"io/fs"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -72,7 +73,7 @@ func (*Exporter) newSnapshotName(prefix string) string {
|
||||||
// NewStagingDir returns the path to a new snapshot directory.
|
// NewStagingDir returns the path to a new snapshot directory.
|
||||||
// The directory is guaranteed to have been freshly created.
|
// The directory is guaranteed to have been freshly created.
|
||||||
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
|
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))
|
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
|
||||||
err = fsx.Mkdir(path, fsx.DefaultFilePerm)
|
err = fsx.Mkdir(path, fsx.DefaultFilePerm)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package exporter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
|
@ -75,7 +77,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
||||||
// create the staging directory
|
// create the staging directory
|
||||||
logging.LogMessage(progress, ctx, "Creating staging directory")
|
logging.LogMessage(progress, ctx, "Creating staging directory")
|
||||||
err = fsx.Mkdir(stagingDir, fsx.DefaultDirPerm)
|
err = fsx.Mkdir(stagingDir, fsx.DefaultDirPerm)
|
||||||
if !os.IsExist(err) && err != nil {
|
if !errors.Is(err, fs.ErrExist) && err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
"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!
|
// partition out the exports that have been deleted!
|
||||||
parts := collection.Partition(exports, func(s models.Export) bool {
|
parts := collection.Partition(exports, func(s models.Export) bool {
|
||||||
_, err := os.Stat(s.Path)
|
_, err := os.Stat(s.Path)
|
||||||
return !os.IsNotExist(err)
|
return !errors.Is(err, fs.ErrNotExist)
|
||||||
})
|
})
|
||||||
|
|
||||||
// go and delete them!
|
// go and delete them!
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
"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) {
|
func (ssh2 *SSH2) ReadOrMakeHostKey(progress io.Writer, ctx context.Context, privateKeyPath string, algorithm HostKeyAlgorithm) (key gossh.Signer, err error) {
|
||||||
hostKey := NewHostKey(algorithm)
|
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)
|
err = ssh2.makeHostKey(progress, ctx, hostKey, privateKeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "Unable to generate new host key")
|
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.
|
// create the directory, but ignore an error if the directory already exists.
|
||||||
// this is so that we can copy one tree into another tree.
|
// this is so that we can copy one tree into another tree.
|
||||||
err = Mkdir(dst, info.Mode())
|
err = Mkdir(dst, info.Mode())
|
||||||
if os.IsExist(err) && IsDirectory(dst) {
|
if errors.Is(err, fs.ErrExist) && IsDirectory(dst) {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package fsx
|
package fsx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -40,7 +41,7 @@ func Touch(path string, perm fs.FileMode) error {
|
||||||
}
|
}
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(err):
|
case errors.Is(err, fs.ErrNotExist):
|
||||||
f, err := Create(path, perm)
|
f, err := Create(path, perm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package fsx
|
package fsx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
@ -60,7 +62,7 @@ func couldBeSameFile(path1, path2 string) (same, authorative bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only 1 file does not exist => they could be different
|
// 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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ func installDir(dst string, srcInfo fs.FileInfo, srcFile fs.ReadDirFile, src str
|
||||||
// create the destination
|
// create the destination
|
||||||
dstStat, dstErr := os.Stat(dst)
|
dstStat, dstErr := os.Stat(dst)
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(dstErr):
|
case errors.Is(dstErr, fs.ErrNotExist):
|
||||||
if err := fsx.MkdirAll(dst, srcInfo.Mode()); err != nil {
|
if err := fsx.MkdirAll(dst, srcInfo.Mode()); err != nil {
|
||||||
return errors.Wrapf(err, "Error creating destination directory %s", dst)
|
return errors.Wrapf(err, "Error creating destination directory %s", dst)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue