Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(s3): truncate LastModified timestamps to second precision (#24)

Hector Venturaad31e7a7b7ed
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/model/Part.java b/src/main/java/io/github/hectorvent/floci/services/s3/model/Part.java
index 3ce0b6270c..5f5fea82f7 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/model/Part.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/model/Part.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.s3.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
+import java.time.temporal.ChronoUnit;
@RegisterForReflection
public class Part {
@@ -18,7 +19,7 @@ public class Part {
this.partNumber = partNumber;
this.eTag = eTag;
this.size = size;
- this.lastModified = Instant.now();
+ this.lastModified = Instant.now().truncatedTo(ChronoUnit.SECONDS);
}
public int getPartNumber() { return partNumber; }
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/model/S3Object.java b/src/main/java/io/github/hectorvent/floci/services/s3/model/S3Object.java
index 527273afac..6c3f9346d4 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/model/S3Object.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/model/S3Object.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
@@ -42,7 +43,7 @@ public class S3Object {
this.data = data;
this.contentType = contentType != null ? contentType : "application/octet-stream";
this.size = data.length;
- this.lastModified = Instant.now();
+ this.lastModified = Instant.now().truncatedTo(ChronoUnit.SECONDS);
this.eTag = computeETag(data);
this.metadata = new HashMap<>();
this.tags = new HashMap<>();
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java
index 81d3f3739b..1e77b3e550 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java
@@ -81,6 +81,13 @@ class S3ServiceTest {
assertEquals(2, buckets.size());
}
+ @Test
+ void putObjectLastModifiedHasSecondPrecision() {
+ s3Service.createBucket("test-bucket");
+ S3Object obj = s3Service.putObject("test-bucket", "file.txt", "data".getBytes(), null, null);
+ assertEquals(0, obj.getLastModified().getNano());
+ }
+
@Test
void putAndGetObject() {
s3Service.createBucket("test-bucket", "us-east-1");