summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorcdoern <cdoern@redhat.com>2021-08-09 10:07:46 -0400
committercdoern <cdoern@redhat.com>2021-08-23 12:51:56 -0400
commitd06d285e66251784126b4f19e047c2a93182d08e (patch)
tree1a1078cc0bca1f2c9fb864dd268c4644e381b8a7 /pkg
parent04ab2b16617fe2d3178eb0b461aacbcab609611e (diff)
downloadpodman-d06d285e66251784126b4f19e047c2a93182d08e.tar.gz
podman-d06d285e66251784126b4f19e047c2a93182d08e.tar.bz2
podman-d06d285e66251784126b4f19e047c2a93182d08e.zip
logFile until flag issue
we were adding a negative duration in podman events, causing inputs like -5s to be correct and 5s to be incorrect. fixes #11158 Signed-off-by: cdoern <cdoern@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/containers_logs.go4
-rw-r--r--pkg/util/utils.go7
-rw-r--r--pkg/util/utils_test.go2
3 files changed, 8 insertions, 5 deletions
diff --git a/pkg/api/handlers/compat/containers_logs.go b/pkg/api/handlers/compat/containers_logs.go
index 656e2c627..50cdb1e65 100644
--- a/pkg/api/handlers/compat/containers_logs.go
+++ b/pkg/api/handlers/compat/containers_logs.go
@@ -63,7 +63,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
var since time.Time
if _, found := r.URL.Query()["since"]; found {
- since, err = util.ParseInputTime(query.Since)
+ since, err = util.ParseInputTime(query.Since, true)
if err != nil {
utils.BadRequest(w, "since", query.Since, err)
return
@@ -73,7 +73,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
var until time.Time
if _, found := r.URL.Query()["until"]; found {
if query.Until != "0" {
- until, err = util.ParseInputTime(query.Until)
+ until, err = util.ParseInputTime(query.Until, false)
if err != nil {
utils.BadRequest(w, "until", query.Until, err)
return
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index 774590f44..37a00c25c 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -520,7 +520,7 @@ func WriteStorageConfigFile(storageOpts *stypes.StoreOptions, storageConf string
// ParseInputTime takes the users input and to determine if it is valid and
// returns a time format and error. The input is compared to known time formats
// or a duration which implies no-duration
-func ParseInputTime(inputTime string) (time.Time, error) {
+func ParseInputTime(inputTime string, since bool) (time.Time, error) {
timeFormats := []string{time.RFC3339Nano, time.RFC3339, "2006-01-02T15:04:05", "2006-01-02T15:04:05.999999999",
"2006-01-02Z07:00", "2006-01-02"}
// iterate the supported time formats
@@ -542,7 +542,10 @@ func ParseInputTime(inputTime string) (time.Time, error) {
if err != nil {
return time.Time{}, errors.Errorf("unable to interpret time value")
}
- return time.Now().Add(-duration), nil
+ if since {
+ return time.Now().Add(-duration), nil
+ }
+ return time.Now().Add(duration), nil
}
// OpenExclusiveFile opens a file for writing and ensure it doesn't already exist
diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go
index 027acbdab..35322c7ea 100644
--- a/pkg/util/utils_test.go
+++ b/pkg/util/utils_test.go
@@ -280,7 +280,7 @@ func TestPeriodAndQuotaToCores(t *testing.T) {
}
func TestParseInputTime(t *testing.T) {
- tm, err := ParseInputTime("1.5")
+ tm, err := ParseInputTime("1.5", true)
if err != nil {
t.Errorf("expected error to be nil but was: %v", err)
}