2022-09-21 23:09:50 +08:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
2024-04-14 00:50:11 +08:00
|
|
|
"github.com/rclone/gofakes3"
|
2022-09-21 23:09:50 +08:00
|
|
|
)
|
|
|
|
|
2023-12-05 19:11:29 +08:00
|
|
|
func (b *s3Backend) entryListR(bucket, fdPath, name string, addPrefix bool, response *gofakes3.ObjectList) error {
|
2022-09-21 23:09:50 +08:00
|
|
|
fp := path.Join(bucket, fdPath)
|
|
|
|
|
2023-11-14 00:40:34 +08:00
|
|
|
dirEntries, err := getDirEntries(fp, b.vfs)
|
2022-09-21 23:09:50 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, entry := range dirEntries {
|
|
|
|
object := entry.Name()
|
|
|
|
|
|
|
|
// workround for control-chars detect
|
|
|
|
objectPath := path.Join(fdPath, object)
|
|
|
|
|
|
|
|
if !strings.HasPrefix(object, name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry.IsDir() {
|
2023-12-05 19:11:29 +08:00
|
|
|
if addPrefix {
|
2022-09-21 23:09:50 +08:00
|
|
|
response.AddPrefix(gofakes3.URLEncode(objectPath))
|
|
|
|
continue
|
|
|
|
}
|
2023-11-14 00:40:34 +08:00
|
|
|
err := b.entryListR(bucket, path.Join(fdPath, object), "", false, response)
|
2022-09-21 23:09:50 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
item := &gofakes3.Content{
|
|
|
|
Key: gofakes3.URLEncode(objectPath),
|
|
|
|
LastModified: gofakes3.NewContentTime(entry.ModTime()),
|
|
|
|
ETag: getFileHash(entry),
|
|
|
|
Size: entry.Size(),
|
|
|
|
StorageClass: gofakes3.StorageStandard,
|
|
|
|
}
|
|
|
|
response.Add(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|