From ec2e72a6dd49b4dd3b72b33f73cb6bddde355e44 Mon Sep 17 00:00:00 2001 From: N-o-Z Date: Mon, 21 Oct 2024 20:20:58 -0400 Subject: [PATCH] Fix: Copy object mtime (#8291) * Fix: Copy object mtime * CR Fixes --- pkg/api/controller.go | 2 +- pkg/catalog/catalog.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/api/controller.go b/pkg/api/controller.go index ad8267d50ac..c39b304e07a 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -352,7 +352,6 @@ func (c *Controller) CompletePresignMultipartUpload(w http.ResponseWriter, r *ht return } - writeTime := time.Now() physicalAddress, addressType := normalizePhysicalAddress(repo.StorageNamespace, body.PhysicalAddress) if addressType != catalog.AddressTypeRelative { writeError(w, r, http.StatusBadRequest, "physical address must be relative to the storage namespace") @@ -383,6 +382,7 @@ func (c *Controller) CompletePresignMultipartUpload(w http.ResponseWriter, r *ht return } + writeTime := time.Now() checksum := httputil.StripQuotesAndSpaces(mpuResp.ETag) entryBuilder := catalog.NewDBEntryBuilder(). CommonLevel(false). diff --git a/pkg/catalog/catalog.go b/pkg/catalog/catalog.go index 69fa1a1c452..0146397eea1 100644 --- a/pkg/catalog/catalog.go +++ b/pkg/catalog/catalog.go @@ -2715,7 +2715,6 @@ func (c *Catalog) CopyEntry(ctx context.Context, srcRepository, srcRef, srcPath, // copy data to a new physical address dstEntry := *srcEntry - dstEntry.CreationDate = time.Now() dstEntry.Path = destPath dstEntry.AddressType = AddressTypeRelative dstEntry.PhysicalAddress = c.PathProvider.NewPath() @@ -2741,6 +2740,11 @@ func (c *Catalog) CopyEntry(ctx context.Context, srcRepository, srcRef, srcPath, return nil, err } + // Update creation date only after actual copy!!! + // The actual file upload can take a while and depend on many factors so we would like + // The mtime (creationDate) in lakeFS to be as close as possible to the mtime in the underlying storage + dstEntry.CreationDate = time.Now() + // create entry for the final copy err = c.CreateEntry(ctx, destRepository, destBranch, dstEntry, opts...) if err != nil {