mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-22 07:30:25 +00:00
GCS: don't paginate to find compat "dirs"
This commit is contained in:
parent
a8a17a223a
commit
5d4f758c47
1 changed files with 5 additions and 65 deletions
70
vfs/gcsfs.go
70
vfs/gcsfs.go
|
@ -5,7 +5,6 @@ package vfs
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -138,46 +137,13 @@ func (fs *GCSFs) Stat(name string) (os.FileInfo, error) {
|
||||||
|
|
||||||
func (fs *GCSFs) getStatCompat(name string) (os.FileInfo, error) {
|
func (fs *GCSFs) getStatCompat(name string) (os.FileInfo, error) {
|
||||||
var result FileInfo
|
var result FileInfo
|
||||||
prefix := fs.getPrefixForStat(name)
|
attrs, err := fs.headObject(name + "/")
|
||||||
query := &storage.Query{Prefix: prefix, Delimiter: "/"}
|
|
||||||
err := query.SetAttrSelection(gcsDefaultFieldsSelection)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return result, err
|
||||||
}
|
}
|
||||||
ctx, cancelFn := context.WithDeadline(context.Background(), time.Now().Add(fs.ctxTimeout))
|
objSize := attrs.Size
|
||||||
defer cancelFn()
|
objectModTime := attrs.Updated
|
||||||
bkt := fs.svc.Bucket(fs.config.Bucket)
|
return NewFileInfo(name, true, objSize, objectModTime, false), nil
|
||||||
it := bkt.Objects(ctx, query)
|
|
||||||
for {
|
|
||||||
attrs, err := it.Next()
|
|
||||||
if err == iterator.Done {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
metrics.GCSListObjectsCompleted(err)
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
if attrs.Prefix != "" {
|
|
||||||
if fs.isEqual(attrs.Prefix, name) {
|
|
||||||
result = NewFileInfo(name, true, 0, time.Now(), false)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !attrs.Deleted.IsZero() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if fs.isEqual(attrs.Name, name) {
|
|
||||||
isDir := strings.HasSuffix(attrs.Name, "/")
|
|
||||||
result = NewFileInfo(name, isDir, attrs.Size, attrs.Updated, false)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
metrics.GCSListObjectsCompleted(nil)
|
|
||||||
if result.Name() == "" {
|
|
||||||
err = errors.New("404 no such file or directory")
|
|
||||||
}
|
|
||||||
return result, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lstat returns a FileInfo describing the named file
|
// Lstat returns a FileInfo describing the named file
|
||||||
|
@ -642,19 +608,6 @@ func (fs *GCSFs) resolve(name string, prefix string) (string, bool) {
|
||||||
return result, isDir
|
return result, isDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *GCSFs) isEqual(key string, virtualName string) bool {
|
|
||||||
if key == virtualName {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if key == virtualName+"/" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if key+"/" == virtualName {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fs *GCSFs) checkIfBucketExists() error {
|
func (fs *GCSFs) checkIfBucketExists() error {
|
||||||
ctx, cancelFn := context.WithDeadline(context.Background(), time.Now().Add(fs.ctxTimeout))
|
ctx, cancelFn := context.WithDeadline(context.Background(), time.Now().Add(fs.ctxTimeout))
|
||||||
defer cancelFn()
|
defer cancelFn()
|
||||||
|
@ -717,19 +670,6 @@ func (fs *GCSFs) getPrefix(name string) string {
|
||||||
return prefix
|
return prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *GCSFs) getPrefixForStat(name string) string {
|
|
||||||
prefix := path.Dir(name)
|
|
||||||
if prefix == "/" || prefix == "." || prefix == "" {
|
|
||||||
prefix = ""
|
|
||||||
} else {
|
|
||||||
prefix = strings.TrimPrefix(prefix, "/")
|
|
||||||
if !strings.HasSuffix(prefix, "/") {
|
|
||||||
prefix += "/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fs *GCSFs) headObject(name string) (*storage.ObjectAttrs, error) {
|
func (fs *GCSFs) headObject(name string) (*storage.ObjectAttrs, error) {
|
||||||
ctx, cancelFn := context.WithDeadline(context.Background(), time.Now().Add(fs.ctxTimeout))
|
ctx, cancelFn := context.WithDeadline(context.Background(), time.Now().Add(fs.ctxTimeout))
|
||||||
defer cancelFn()
|
defer cancelFn()
|
||||||
|
|
Loading…
Reference in a new issue