From 02ef83fe28f123c57bdb3893740d64a63a01be22 Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Sat, 5 Oct 2024 10:43:51 -0700 Subject: [PATCH] fix: Use chart archive modifed time for OCI push Signed-off-by: George Jenkins --- pkg/pusher/ocipusher.go | 5 +++-- pkg/time/ctime/ctime.go | 6 +++++- pkg/time/ctime/ctime_linux.go | 4 ++-- pkg/time/ctime/ctime_other.go | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/pusher/ocipusher.go b/pkg/pusher/ocipusher.go index b37a0c605..fc08411ec 100644 --- a/pkg/pusher/ocipusher.go +++ b/pkg/pusher/ocipusher.go @@ -90,8 +90,9 @@ func (pusher *OCIPusher) push(chartRef, href string) error { path.Join(strings.TrimPrefix(href, fmt.Sprintf("%s://", registry.OCIScheme)), meta.Metadata.Name), meta.Metadata.Version) - chartCreationTime := ctime.Created(stat) - pushOpts = append(pushOpts, registry.PushOptCreationTime(chartCreationTime.Format(time.RFC3339))) + // The time the chart was "created" is semantically the time the chart archive file was last written + chartArchiveFileCreatedTime := ctime.Modified(stat) + pushOpts = append(pushOpts, registry.PushOptCreationTime(chartArchiveFileCreatedTime.Format(time.RFC3339))) _, err = client.Push(chartBytes, ref, pushOpts...) return err diff --git a/pkg/time/ctime/ctime.go b/pkg/time/ctime/ctime.go index f2998d76d..63a41c0bf 100644 --- a/pkg/time/ctime/ctime.go +++ b/pkg/time/ctime/ctime.go @@ -21,5 +21,9 @@ import ( ) func Created(fi os.FileInfo) time.Time { - return created(fi) + return modified(fi) +} + +func Modified(fi os.FileInfo) time.Time { + return modified(fi) } diff --git a/pkg/time/ctime/ctime_linux.go b/pkg/time/ctime/ctime_linux.go index c3cea1d78..d8a6ea1a1 100644 --- a/pkg/time/ctime/ctime_linux.go +++ b/pkg/time/ctime/ctime_linux.go @@ -23,8 +23,8 @@ import ( "time" ) -func created(fi os.FileInfo) time.Time { +func modified(fi os.FileInfo) time.Time { st := fi.Sys().(*syscall.Stat_t) //nolint - return time.Unix(int64(st.Ctim.Sec), int64(st.Ctim.Nsec)) + return time.Unix(int64(st.Mtim.Sec), int64(st.Mtim.Nsec)) } diff --git a/pkg/time/ctime/ctime_other.go b/pkg/time/ctime/ctime_other.go index f21ed7347..12afc6df2 100644 --- a/pkg/time/ctime/ctime_other.go +++ b/pkg/time/ctime/ctime_other.go @@ -22,6 +22,6 @@ import ( "time" ) -func created(fi os.FileInfo) time.Time { +func modified(fi os.FileInfo) time.Time { return fi.ModTime() }