mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 13:26:11 +08:00
drive: Fix multiple files of same name being created
ModifiedDate seems to be set on Insert if set, so do that
This commit is contained in:
parent
bd62eb17e3
commit
86b77f3ca8
|
@ -663,45 +663,47 @@ func (f *FsDrive) Put(in io.Reader, remote string, modTime time.Time, size int64
|
|||
return nil, fmt.Errorf("Couldn't find or make directory: %s", err)
|
||||
}
|
||||
|
||||
// See if the file already exists
|
||||
var info *drive.File
|
||||
found, err := f.listAll(directoryId, leaf, false, true, func(item *drive.File) bool {
|
||||
info = item
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error finding file: %s", leaf, err)
|
||||
}
|
||||
|
||||
// Guess the mime type
|
||||
mimeType := mime.TypeByExtension(path.Ext(remote))
|
||||
if mimeType == "" {
|
||||
mimeType = "application/octet-stream"
|
||||
}
|
||||
modifiedDate := modTime.Format(time.RFC3339Nano)
|
||||
|
||||
if found {
|
||||
// Modify metadata
|
||||
info.ModifiedDate = modifiedDate
|
||||
info.MimeType = mimeType
|
||||
|
||||
// Make the API request to upload metadata and file data.
|
||||
info, err = f.svc.Files.Update(info.Id, info).SetModifiedDate(true).Media(in).Do()
|
||||
} else {
|
||||
// Define the metadata for the file we are going to create.
|
||||
info := &drive.File{
|
||||
info = &drive.File{
|
||||
Title: leaf,
|
||||
Description: leaf,
|
||||
Parents: []*drive.ParentReference{{Id: directoryId}},
|
||||
MimeType: mimeType,
|
||||
ModifiedDate: modifiedDate,
|
||||
}
|
||||
|
||||
// FIXME can't set modified date on initial upload as no
|
||||
// .SetModifiedDate(). This agrees with the API docs, but not
|
||||
// with the comment on
|
||||
// https://developers.google.com/drive/v2/reference/files/insert
|
||||
//
|
||||
// modifiedDate datetime Last time this file was modified by
|
||||
// anyone (formatted RFC 3339 timestamp). This is only mutable
|
||||
// on update when the setModifiedDate parameter is set.
|
||||
// writable
|
||||
//
|
||||
// There is no setModifiedDate parameter though
|
||||
|
||||
// Make the API request to upload infodata and file data.
|
||||
// Make the API request to upload metadata and file data.
|
||||
info, err = f.svc.Files.Insert(info).Media(in).Do()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Upload failed: %s", err)
|
||||
}
|
||||
fs.setMetaData(info)
|
||||
|
||||
// Set modified date
|
||||
info.ModifiedDate = modTime.Format(time.RFC3339Nano)
|
||||
_, err = f.svc.Files.Update(info.Id, info).SetModifiedDate(true).Do()
|
||||
if err != nil {
|
||||
return fs, fmt.Errorf("Failed to set mtime: %s", err)
|
||||
}
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ Ideas
|
|||
* Google cloud storage: https://developers.google.com/storage/
|
||||
* rsync over ssh
|
||||
* dropbox: https://github.com/nickoneill/go-dropbox (no MD5s)
|
||||
* control times sync (which is slow) with -a --archive flag?
|
||||
|
||||
Need to make directory objects otherwise can't upload an empty directory
|
||||
* Or could upload empty directories only?
|
||||
|
@ -42,6 +43,10 @@ s3
|
|||
* Otherwise can set metadata
|
||||
* Returns etag and last modified in bucket list
|
||||
|
||||
Bugs
|
||||
Drive
|
||||
* Should keep a note of files we list then call a new method
|
||||
Object.Update() which would be more efficient than haveing to look
|
||||
the id up for each file
|
||||
|
||||
Non verbose - not sure number transferred got counted up? CHECK
|
||||
Bugs
|
||||
* Non verbose - not sure number transferred got counted up? CHECK
|
||||
|
|
Loading…
Reference in New Issue
Block a user