swift: Don't return an MD5SUM for static large objects - #392

* rename isManifest to isDynamicLargeObject for clarity
This commit is contained in:
Nick Craig-Wood 2016-03-17 17:36:20 +00:00
parent 9dccf91da7
commit bd27473762

View file

@ -223,7 +223,7 @@ func (f *Fs) newFsObjectWithInfo(remote string, info *swift.Object) fs.Object {
fs: f, fs: f,
remote: remote, remote: remote,
} }
// Note that due to a quirk of swift, manifest files are // Note that due to a quirk of swift, dynamic large objects are
// returned as 0 bytes in the listing. Correct this here by // returned as 0 bytes in the listing. Correct this here by
// making sure we read the full metadata for all 0 byte files. // making sure we read the full metadata for all 0 byte files.
if info != nil && info.Bytes == 0 { if info != nil && info.Bytes == 0 {
@ -320,7 +320,7 @@ func (f *Fs) listFiles(ignoreStorable bool) fs.ObjectsChan {
defer close(out) defer close(out)
f.list(false, func(remote string, object *swift.Object) error { f.list(false, func(remote string, object *swift.Object) error {
if o := f.newFsObjectWithInfo(remote, object); o != nil { if o := f.newFsObjectWithInfo(remote, object); o != nil {
// Storable does a full metadata read on 0 size objects which might be manifest files // Storable does a full metadata read on 0 size objects which might be dynamic large objects
storable := o.Storable() storable := o.Storable()
if storable || ignoreStorable { if storable || ignoreStorable {
out <- o out <- o
@ -480,19 +480,24 @@ func (o *Object) Hash(t fs.HashType) (string, error) {
if t != fs.HashMD5 { if t != fs.HashMD5 {
return "", fs.ErrHashUnsupported return "", fs.ErrHashUnsupported
} }
isManifest, err := o.isManifestFile() isDynamicLargeObject, err := o.isDynamicLargeObject()
if err != nil { if err != nil {
return "", err return "", err
} }
if isManifest { isStaticLargeObject, err := o.isStaticLargeObject()
fs.Debug(o, "Returning empty Md5sum for swift manifest file") if err != nil {
return "", err
}
if isDynamicLargeObject || isStaticLargeObject {
fs.Debug(o, "Returning empty Md5sum for swift large object")
return "", nil return "", nil
} }
return strings.ToLower(o.info.Hash), nil return strings.ToLower(o.info.Hash), nil
} }
// isManifestFile checks for manifest header // hasHeader checks for the header passed in returning false if the
func (o *Object) isManifestFile() (bool, error) { // object isn't found.
func (o *Object) hasHeader(header string) (bool, error) {
err := o.readMetaData() err := o.readMetaData()
if err != nil { if err != nil {
if err == swift.ObjectNotFound { if err == swift.ObjectNotFound {
@ -500,8 +505,18 @@ func (o *Object) isManifestFile() (bool, error) {
} }
return false, err return false, err
} }
_, isManifestFile := (*o.headers)["X-Object-Manifest"] _, isDynamicLargeObject := (*o.headers)[header]
return isManifestFile, nil return isDynamicLargeObject, nil
}
// isDynamicLargeObject checks for X-Object-Manifest header
func (o *Object) isDynamicLargeObject() (bool, error) {
return o.hasHeader("X-Object-Manifest")
}
// isStaticLargeObjectFile checks for the X-Static-Large-Object header
func (o *Object) isStaticLargeObject() (bool, error) {
return o.hasHeader("X-Static-Large-Object")
} }
// Size returns the size of an object in bytes // Size returns the size of an object in bytes
@ -677,8 +692,8 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) error {
size := src.Size() size := src.Size()
modTime := src.ModTime() modTime := src.ModTime()
// Note whether this has a manifest before starting // Note whether this is a dynamic large object before starting
isManifest, err := o.isManifestFile() isDynamicLargeObject, err := o.isDynamicLargeObject()
if err != nil { if err != nil {
return err return err
} }
@ -701,8 +716,8 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) error {
} }
} }
// If file was a manifest then remove old/all segments // If file was a dynamic large object then remove old/all segments
if isManifest { if isDynamicLargeObject {
err = o.removeSegments(uniquePrefix) err = o.removeSegments(uniquePrefix)
if err != nil { if err != nil {
fs.Log(o, "Failed to remove old segments - carrying on with upload: %v", err) fs.Log(o, "Failed to remove old segments - carrying on with upload: %v", err)
@ -716,7 +731,7 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) error {
// Remove an object // Remove an object
func (o *Object) Remove() error { func (o *Object) Remove() error {
isManifestFile, err := o.isManifestFile() isDynamicLargeObject, err := o.isDynamicLargeObject()
if err != nil { if err != nil {
return err return err
} }
@ -726,7 +741,7 @@ func (o *Object) Remove() error {
return err return err
} }
// ...then segments if required // ...then segments if required
if isManifestFile { if isDynamicLargeObject {
err = o.removeSegments("") err = o.removeSegments("")
if err != nil { if err != nil {
return err return err