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:
Tom Wiesing 2023-03-02 12:56:20 +01:00
parent 473040a69f
commit 9807213e60
No known key found for this signature in database
9 changed files with 22 additions and 11 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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
}
}

View file

@ -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)
}