Skip to content

Commit eea14d0

Browse files
committed
if errF and errD are pointers to os.PathError, then they won't compare equal, even when they are
1 parent 584399d commit eea14d0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

client.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,15 @@ func (c *Client) Remove(path string) error {
772772

773773
// Both failed: figure out which error to return.
774774

775-
if errF == errD {
776-
// If they are the same error, then just return that.
777-
return errF
775+
if errF, ok := errF.(*os.PathError); ok {
776+
// The only time it makes sense to compare errors, is when both are `*os.PathError`.
777+
// We cannot test these directly with errF == errD, as that would be a pointer comparison.
778+
779+
if errD, ok := errD.(*os.PathError); ok && errors.Is(errF.Err, errD.Err) {
780+
// If they are both pointers to PathError,
781+
// and the same underlying error, then return that.
782+
return errF
783+
}
778784
}
779785

780786
fi, err := c.Stat(path)

0 commit comments

Comments
 (0)