forked from TrueCloudLab/restic
Modernize internal/cache error handling
This commit is contained in:
parent
ea04f40eb3
commit
6586e90acf
2 changed files with 8 additions and 9 deletions
15
internal/cache/cache.go
vendored
15
internal/cache/cache.go
vendored
|
@ -28,7 +28,7 @@ const fileMode = 0644
|
|||
|
||||
func readVersion(dir string) (v uint, err error) {
|
||||
buf, err := ioutil.ReadFile(filepath.Join(dir, "version"))
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
@ -61,13 +61,13 @@ func writeCachedirTag(dir string) error {
|
|||
|
||||
tagfile := filepath.Join(dir, "CACHEDIR.TAG")
|
||||
_, err := fs.Lstat(tagfile)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
f, err := fs.OpenFile(tagfile, os.O_CREATE|os.O_EXCL|os.O_WRONLY, fileMode)
|
||||
if err != nil {
|
||||
if os.IsExist(errors.Cause(err)) {
|
||||
if errors.Is(err, os.ErrExist) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ func New(id string, basedir string) (c *Cache, err error) {
|
|||
// create the repo cache dir if it does not exist yet
|
||||
var created bool
|
||||
_, err = fs.Lstat(cachedir)
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = fs.MkdirAll(cachedir, dirMode)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
|
@ -179,11 +179,10 @@ func validCacheDirName(s string) bool {
|
|||
// listCacheDirs returns the list of cache directories.
|
||||
func listCacheDirs(basedir string) ([]os.FileInfo, error) {
|
||||
f, err := fs.Open(basedir)
|
||||
if err != nil && os.IsNotExist(errors.Cause(err)) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
2
internal/cache/file.go
vendored
2
internal/cache/file.go
vendored
|
@ -99,7 +99,7 @@ func (c *Cache) Save(h restic.Handle, rd io.Reader) error {
|
|||
finalname := c.filename(h)
|
||||
dir := filepath.Dir(finalname)
|
||||
err := fs.Mkdir(dir, 0700)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
if err != nil && !errors.Is(err, os.ErrExist) {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue