forked from TrueCloudLab/rclone
swift: Use ContentType from Object to avoid lookups in listings - fixes #208
This commit is contained in:
parent
dcd6bedc27
commit
e8ba43c479
1 changed files with 4 additions and 14 deletions
|
@ -20,7 +20,6 @@ import (
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
directoryMarkerContentType = "application/directory" // content type of directory marker objects
|
directoryMarkerContentType = "application/directory" // content type of directory marker objects
|
||||||
directoryMarkerMaxSize = 1 // max size that directory marker objects can be
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
|
@ -179,9 +178,9 @@ func NewFs(name, root string) (fs.Fs, error) {
|
||||||
}
|
}
|
||||||
if f.root != "" {
|
if f.root != "" {
|
||||||
f.root += "/"
|
f.root += "/"
|
||||||
// Check to see if the object exists - ignore directory markers
|
// Check to see if the object exists - ignoring directory markers
|
||||||
_, headers, err := f.c.Object(container, directory)
|
info, _, err := f.c.Object(container, directory)
|
||||||
if err == nil && headers["Content-Type"] != directoryMarkerContentType {
|
if err == nil && info.ContentType != directoryMarkerContentType {
|
||||||
remote := path.Base(directory)
|
remote := path.Base(directory)
|
||||||
f.root = path.Dir(directory)
|
f.root = path.Dir(directory)
|
||||||
if f.root == "." {
|
if f.root == "." {
|
||||||
|
@ -536,16 +535,7 @@ func (o *Object) SetModTime(modTime time.Time) {
|
||||||
// Content-Type to directoryMarkerContentType - that makes it a
|
// Content-Type to directoryMarkerContentType - that makes it a
|
||||||
// directory marker which is not storable.
|
// directory marker which is not storable.
|
||||||
func (o *Object) Storable() bool {
|
func (o *Object) Storable() bool {
|
||||||
if o.info.Bytes > directoryMarkerMaxSize {
|
return o.info.ContentType != directoryMarkerContentType
|
||||||
return true
|
|
||||||
}
|
|
||||||
err := o.readMetaData()
|
|
||||||
if err != nil {
|
|
||||||
fs.Debug(o, "Failed to read metadata: %s", err)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
contentType := (*o.headers)["Content-Type"]
|
|
||||||
return contentType != directoryMarkerContentType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open an object for read
|
// Open an object for read
|
||||||
|
|
Loading…
Reference in a new issue