import java.io.File
import java.nio.ByteBuffer
import java.nio.file.FileAlreadyExistsException
+import java.nio.file.Files
+import java.nio.file.LinkOption
+import java.nio.file.attribute.BasicFileAttributeView
+import java.nio.file.attribute.BasicFileAttributes
import java.time.Instant
import kotlin.String
import kotlin.time.Duration.Companion.hours
}
data class StoredFileStats(
+ val created: Instant,
val updated: Instant,
val size: Long,
)
override suspend fun statFile(path: StoragePath): StoredFileStats? {
val file = resolveFile(path)
if (!file.isFile) return null
-
- return StoredFileStats(Instant.ofEpochMilli(file.lastModified()), file.length())
+ return withContext(Dispatchers.IO) {
+ val basicAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java)
+ StoredFileStats(
+ basicAttributes.creationTime().toInstant(),
+ basicAttributes.lastModifiedTime().toInstant(),
+ basicAttributes.size()
+ )
+ }
}
override suspend fun writeFile(path: StoragePath, content: ByteArray): Boolean {
if (path.isRoot) return null
val file = getExact(path) ?: return null
val gridFsFile = bucket.find(Filters.eq(MONGODB_ID_KEY, file.file)).awaitFirst()
- return StoredFileStats(file.updated, gridFsFile.length)
+ return StoredFileStats(file.created, file.updated, gridFsFile.length)
}
override suspend fun writeFile(path: StoragePath, content: ByteArray): Boolean {