Skip to content

Commit

Permalink
Matching the last modified time of an object between the List and Get…
Browse files Browse the repository at this point in the history
…Object function (#22)

* Custom round time so that time match

* Added zero microseconds case

* Fixed comments
  • Loading branch information
gmauleon authored and jdolitsky committed Dec 4, 2019
1 parent 12e78b2 commit a49401b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"os"
pathutil "path"
"time"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
Expand Down Expand Up @@ -163,10 +164,20 @@ func (b OpenstackOSBackend) ListObjects(prefix string) ([]Object, error) {
if objectPathIsInvalid(path) {
continue
}

// This is a patch so that LastModified match between the List and GetObject function
// Openstack seems to send a rounded up time when getting the LastModified date from an object show versus an object list
var lastModified time.Time
if openStackObject.LastModified.Nanosecond()/int(time.Microsecond) == 0 {
lastModified = openStackObject.LastModified
} else {
lastModified = openStackObject.LastModified.Truncate(time.Second).Add(time.Second)
}

object := Object{
Path: path,
Content: []byte{},
LastModified: openStackObject.LastModified,
LastModified: lastModified,
}
objects = append(objects, object)
}
Expand Down

0 comments on commit a49401b

Please sign in to comment.