Skip to content

Commit 63f1b49

Browse files
committed
fix(gcsfs): update object not exist check logic
Signed-off-by: ahkui <ahkui@outlook.com>
1 parent debd095 commit 63f1b49

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

gcsfs/errors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package gcsfs
1919
import (
2020
"errors"
2121
"syscall"
22+
23+
"cloud.google.com/go/storage"
2224
)
2325

2426
var (
2527
ErrNoBucketInName = errors.New("no bucket name found in the name")
2628
ErrFileClosed = errors.New("file is closed")
2729
ErrOutOfRange = errors.New("out of range")
28-
ErrObjectDoesNotExist = errors.New("storage: object doesn't exist")
30+
ErrObjectDoesNotExist = storage.ErrObjectNotExist
2931
ErrEmptyObjectName = errors.New("storage: object name is empty")
3032
ErrFileNotFound = syscall.ENOENT
3133
)

gcsfs/file_info.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package gcsfs
1818

1919
import (
20+
"errors"
2021
"os"
2122
"path/filepath"
2223
"strings"
@@ -58,7 +59,7 @@ func newFileInfo(name string, fs *Fs, fileMode os.FileMode) (*FileInfo, error) {
5859
res.name = fs.ensureTrailingSeparator(res.name)
5960
res.isDir = true
6061
return res, nil
61-
} else if err.Error() == ErrObjectDoesNotExist.Error() {
62+
} else if errors.Is(err, ErrObjectDoesNotExist) {
6263
// Folders do not actually "exist" in GCloud, so we have to check, if something exists with
6364
// such a prefix
6465
bucketName, bucketPath := fs.splitName(name)

gcsfs/gcs_mocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (o *objectMock) Attrs(_ context.Context) (*storage.ObjectAttrs, error) {
130130

131131
if info.IsDir() {
132132
// we have to mock it here, because of FileInfo logic
133-
return nil, ErrObjectDoesNotExist
133+
return nil, storage.ErrObjectNotExist
134134
}
135135

136136
return res, nil

0 commit comments

Comments
 (0)