Skip to content

Commit

Permalink
setModifiedDate for remote instead of local on push
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Odeke committed Jan 5, 2015
1 parent a3f2ae2 commit 8671fef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion push.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (g *Commands) remoteMod(change *Change) (err error) {
}
}
_, err = g.rem.Upsert(parent.Id, change.Src, body)
return err
return err
}

func (g *Commands) remoteAdd(change *Change) (err error) {
Expand Down
12 changes: 12 additions & 0 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,20 @@ func (r *Remote) Upsert(parentId string, file *File, body io.Reader) (f *File, e
}
return NewRemoteFile(uploaded), nil
}

utc := file.ModTime.UTC().Round(time.Second)

// Ugly but straight forward formatting because time.Parse is such a prima donna
str := fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%0d.000Z",
utc.Year(), utc.Month(), utc.Day(), utc.Hour(), utc.Minute(), utc.Second())

uploaded.ModifiedDate = str

// update the existing
req := r.service.Files.Update(file.Id, uploaded)
// We always want it to match up with the local time
req.SetModifiedDate(true)

if !file.IsDir && body != nil {
req = req.Media(body)
}
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewLocalFile(absPath string, f os.FileInfo) *File {
return &File{
Id: "",
Name: f.Name(),
ModTime: f.ModTime(),
ModTime: f.ModTime().Round(time.Second),
IsDir: f.IsDir(),
Size: f.Size(),
BlobAt: absPath,
Expand Down

0 comments on commit 8671fef

Please sign in to comment.