diff options
author | TomSweeneyRedHat <tsweeney@redhat.com> | 2020-11-16 15:47:32 -0500 |
---|---|---|
committer | TomSweeneyRedHat <tsweeney@redhat.com> | 2020-11-16 15:50:14 -0500 |
commit | b78a90cbdea05ea92e080f50f9f8fc8fa3cd4d68 (patch) | |
tree | 2502a8a847e080d5b739eca29afbabe2ce0d98a2 /vendor/github.com/Microsoft/go-winio/backuptar/strconv.go | |
parent | e59394973a7559feb42b89ea882f2ce52d0432b8 (diff) | |
download | podman-b78a90cbdea05ea92e080f50f9f8fc8fa3cd4d68.tar.gz podman-b78a90cbdea05ea92e080f50f9f8fc8fa3cd4d68.tar.bz2 podman-b78a90cbdea05ea92e080f50f9f8fc8fa3cd4d68.zip |
Bump Buildah to v1.18.0, c/storage to v1.24.0
Update to Buildah v1.18.0 and c/storage to v1.24
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Diffstat (limited to 'vendor/github.com/Microsoft/go-winio/backuptar/strconv.go')
-rw-r--r-- | vendor/github.com/Microsoft/go-winio/backuptar/strconv.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/Microsoft/go-winio/backuptar/strconv.go b/vendor/github.com/Microsoft/go-winio/backuptar/strconv.go new file mode 100644 index 000000000..341609663 --- /dev/null +++ b/vendor/github.com/Microsoft/go-winio/backuptar/strconv.go @@ -0,0 +1,68 @@ +package backuptar + +import ( + "archive/tar" + "fmt" + "strconv" + "strings" + "time" +) + +// Functions copied from https://github.com/golang/go/blob/master/src/archive/tar/strconv.go +// as we need to manage the LIBARCHIVE.creationtime PAXRecord manually. +// Idea taken from containerd which did the same thing. + +// parsePAXTime takes a string of the form %d.%d as described in the PAX +// specification. Note that this implementation allows for negative timestamps, +// which is allowed for by the PAX specification, but not always portable. +func parsePAXTime(s string) (time.Time, error) { + const maxNanoSecondDigits = 9 + + // Split string into seconds and sub-seconds parts. + ss, sn := s, "" + if pos := strings.IndexByte(s, '.'); pos >= 0 { + ss, sn = s[:pos], s[pos+1:] + } + + // Parse the seconds. + secs, err := strconv.ParseInt(ss, 10, 64) + if err != nil { + return time.Time{}, tar.ErrHeader + } + if len(sn) == 0 { + return time.Unix(secs, 0), nil // No sub-second values + } + + // Parse the nanoseconds. + if strings.Trim(sn, "0123456789") != "" { + return time.Time{}, tar.ErrHeader + } + if len(sn) < maxNanoSecondDigits { + sn += strings.Repeat("0", maxNanoSecondDigits-len(sn)) // Right pad + } else { + sn = sn[:maxNanoSecondDigits] // Right truncate + } + nsecs, _ := strconv.ParseInt(sn, 10, 64) // Must succeed + if len(ss) > 0 && ss[0] == '-' { + return time.Unix(secs, -1*nsecs), nil // Negative correction + } + return time.Unix(secs, nsecs), nil +} + +// formatPAXTime converts ts into a time of the form %d.%d as described in the +// PAX specification. This function is capable of negative timestamps. +func formatPAXTime(ts time.Time) (s string) { + secs, nsecs := ts.Unix(), ts.Nanosecond() + if nsecs == 0 { + return strconv.FormatInt(secs, 10) + } + + // If seconds is negative, then perform correction. + sign := "" + if secs < 0 { + sign = "-" // Remember sign + secs = -(secs + 1) // Add a second to secs + nsecs = -(nsecs - 1e9) // Take that second away from nsecs + } + return strings.TrimRight(fmt.Sprintf("%s%d.%09d", sign, secs, nsecs), "0") +} |