onedrive: fix NewObject so it doesn't return an object when given a directory

This commit is contained in:
Nick Craig-Wood 2017-03-06 20:11:54 +00:00
parent b2a4ea9304
commit c45c604997

View File

@ -252,14 +252,15 @@ func (f *Fs) newObjectWithInfo(remote string, info *api.Item) (fs.Object, error)
fs: f, fs: f,
remote: remote, remote: remote,
} }
var err error
if info != nil { if info != nil {
// Set info // Set info
o.setMetaData(info) err = o.setMetaData(info)
} else { } else {
err := o.readMetaData() // reads info and meta, returning an error err = o.readMetaData() // reads info and meta, returning an error
if err != nil { }
return nil, err if err != nil {
} return nil, err
} }
return o, nil return o, nil
} }
@ -572,8 +573,7 @@ func (f *Fs) waitForJob(location string, o *Object) error {
if err != nil { if err != nil {
return err return err
} }
o.setMetaData(&info) return o.setMetaData(&info)
return nil
} }
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
@ -711,7 +711,10 @@ func (o *Object) Size() int64 {
} }
// setMetaData sets the metadata from info // setMetaData sets the metadata from info
func (o *Object) setMetaData(info *api.Item) { func (o *Object) setMetaData(info *api.Item) (err error) {
if info.Folder != nil {
return errors.Wrapf(fs.ErrorNotAFile, "%q", o.remote)
}
o.hasMetaData = true o.hasMetaData = true
o.size = info.Size o.size = info.Size
@ -734,6 +737,7 @@ func (o *Object) setMetaData(info *api.Item) {
o.modTime = time.Time(info.LastModifiedDateTime) o.modTime = time.Time(info.LastModifiedDateTime)
} }
o.id = info.ID o.id = info.ID
return nil
} }
// readMetaData gets the metadata if it hasn't already been fetched // readMetaData gets the metadata if it hasn't already been fetched
@ -756,8 +760,7 @@ func (o *Object) readMetaData() (err error) {
} }
return err return err
} }
o.setMetaData(info) return o.setMetaData(info)
return nil
} }
// ModTime returns the modification time of the object // ModTime returns the modification time of the object
@ -800,8 +803,7 @@ func (o *Object) SetModTime(modTime time.Time) error {
if err != nil { if err != nil {
return err return err
} }
o.setMetaData(info) return o.setMetaData(info)
return nil
} }
// Storable returns a boolean showing whether this object storable // Storable returns a boolean showing whether this object storable
@ -957,20 +959,19 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) (err error) {
if err != nil { if err != nil {
return err return err
} }
o.setMetaData(info) err = o.setMetaData(info)
} else { } else {
err = o.uploadMultipart(in, size) err = o.uploadMultipart(in, size)
if err != nil { }
return err if err != nil {
} return err
} }
// Set the mod time now and read metadata // Set the mod time now and read metadata
info, err = o.setModTime(modTime) info, err = o.setModTime(modTime)
if err != nil { if err != nil {
return err return err
} }
o.setMetaData(info) return o.setMetaData(info)
return nil
} }
// Remove an object // Remove an object