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,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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue