Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

putObject() overrides lastModified in ObjectMetaData #163

Open
jlippmann opened this issue May 4, 2020 · 1 comment
Open

putObject() overrides lastModified in ObjectMetaData #163

jlippmann opened this issue May 4, 2020 · 1 comment

Comments

@jlippmann
Copy link

I have an usecase where I want to cleanup objects created a certain time ago.
For that I create a new object (putObject()) with an ObjectMetaDatas lastModified far in the past.
Unfortunately this date always gets overriden in both, FileProvider as well as InMemoryProvider.

My proposal: Set the current DateTime for an empty lastModified only, keep the set value otherwise.

@xhanshawn
Copy link

xhanshawn commented Aug 4, 2020

I have a similar use case for checking the last modified time of an object. I solved it by modified the object meta in the metastore:

val api = S3Mock(port = port, dir = dir)

def overwriteLastModified(bucket: String, key: String, date: Date): Unit = {
  val metastore = api.p.metadataStore
  val meta = metastore.get(bucket, objectKey) // ObjectMetadata
  meta.setLastModified(date)
  metastore.put(bucket, objectKey, meta)
}

At least this works for me. In my case, the object is created as part of the preparation for the test. So I usually do:

mockS3.putObject(bucket, key, data)
overwriteLastModified(bucket, key)

// run the test

But I agree, ideally, the S3Mock should behave as what you raised. Hopefully, what I did can help your case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants