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

Allow lastModified to be set for object (default to current time if not explicitly set) #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sdwards
Copy link

@sdwards sdwards commented Aug 7, 2020

No description provided.

@jorkzijlstra
Copy link

@romangrebennikov Are there any plans to merge this?

@kevin-denver
Copy link

kevin-denver commented Mar 13, 2021

I would love to see this merged too because I'm currently stuck without this functionality

@florind
Copy link

florind commented May 31, 2021

+1

1 similar comment
@yonatang
Copy link

yonatang commented Apr 5, 2023

+1

@yonatang
Copy link

yonatang commented Apr 5, 2023

This repo has no activity since 2020. So assuming no one is going to merge this in, here's a reflection based walk-around I'm using, hope it helps:

import io.findify.s3mock.S3Mock;
import io.findify.s3mock.provider.InMemoryProvider;
import scala.collection.concurrent.TrieMap;

import java.lang.reflect.Field;
import java.util.Date;

public class YourTestClass {
    
    // ...

    private static Field bucketStoreField;
    static {
        try {
            bucketStoreField = InMemoryProvider.class.getDeclaredField("bucketDataStore");
            bucketStoreField.setAccessible(true);
        } catch (Exception e){
            throw new RuntimeException(e);
        }
    }
    
    public void setLastModified(String bucket, String key, Date lastModified) {
        InMemoryProvider p = (InMemoryProvider)s3mock.p();
        p.getObject(bucket, key).metadata().get().setLastModified(lastModified);
        // Hack to make listObject work
        TrieMap<String, InMemoryProvider.BucketContents> bucketStore =  (TrieMap<String, InMemoryProvider.BucketContents>)bucketStoreField.get(p);
        InMemoryProvider.BucketContents bucketContents = bucketStore.get(bucket).get();
        InMemoryProvider.KeyContents rawObject = bucketContents.keysInBucket().get(key).get();
        akka.http.scaladsl.model.DateTime newDateTime = (akka.http.scaladsl.model.DateTime)akka.http.scaladsl.model.DateTime.create(lastModified.getTime());
        bucketContents.keysInBucket().put(key, rawObject.copy(newDateTime, rawObject.data()));
        
    }
}

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

Successfully merging this pull request may close these issues.

5 participants