mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
S3: fix empty directory detection
when listing empty directory MinIO returns no contents while S3 returns 1 object with the key equal to the prefix. Make detection work in both cases Fixes #227
This commit is contained in:
13
vfs/s3fs.go
13
vfs/s3fs.go
@@ -652,7 +652,7 @@ func (fs *S3Fs) hasContents(name string) (bool, error) {
|
|||||||
prefix += "/"
|
prefix += "/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maxResults := int64(1)
|
maxResults := int64(2)
|
||||||
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()
|
||||||
results, err := fs.svc.ListObjectsV2WithContext(ctx, &s3.ListObjectsV2Input{
|
results, err := fs.svc.ListObjectsV2WithContext(ctx, &s3.ListObjectsV2Input{
|
||||||
@@ -664,7 +664,16 @@ func (fs *S3Fs) hasContents(name string) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return len(results.Contents) > 0, nil
|
// MinIO returns no contents while S3 returns 1 object
|
||||||
|
// with the key equal to the prefix for empty directories
|
||||||
|
for _, obj := range results.Contents {
|
||||||
|
name, _ := fs.resolve(obj.Key, prefix)
|
||||||
|
if name == "" || name == "/" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *S3Fs) headObject(name string) (*s3.HeadObjectOutput, error) {
|
func (fs *S3Fs) headObject(name string) (*s3.HeadObjectOutput, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user