2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-09-28 07:59:27 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package filestore
|
|
|
|
|
2021-05-14 16:05:42 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
)
|
2018-09-28 07:59:27 +01:00
|
|
|
|
|
|
|
// underlyingError returns the underlying error for known os error types.
|
|
|
|
func underlyingError(err error) error {
|
2021-05-14 16:05:42 +01:00
|
|
|
var perr *os.PathError
|
|
|
|
var lerr *os.LinkError
|
|
|
|
var serr *os.SyscallError
|
|
|
|
switch {
|
|
|
|
case errors.As(err, &perr):
|
|
|
|
return perr.Err
|
|
|
|
case errors.As(err, &lerr):
|
|
|
|
return lerr.Err
|
|
|
|
case errors.As(err, &serr):
|
|
|
|
return serr.Err
|
2018-09-28 07:59:27 +01:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|