fix file created_at not working on some targets

This commit is contained in:
2025-07-17 21:54:40 +02:00
parent d8963e1f2d
commit 1cfedd1608
3 changed files with 18 additions and 10 deletions

5
backend/Cargo.lock generated
View File

@@ -1662,9 +1662,9 @@ checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f"
[[package]]
name = "rustix"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [
"bitflags",
"errno",
@@ -2524,6 +2524,7 @@ dependencies = [
"hex",
"mime_guess",
"regex",
"rustix",
"serde",
"serde_json",
"sqlx",

View File

@@ -22,6 +22,7 @@ dotenv = "0.15.0"
hex = "0.4.3"
mime_guess = "2.0.5"
regex = "1.11.1"
rustix = { version = "1.0.8", features = ["fs"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
sqlx = { version = "0.8.6", features = ["chrono", "postgres", "runtime-tokio", "time", "uuid"] }

View File

@@ -1,6 +1,5 @@
use std::time::UNIX_EPOCH;
use anyhow::{Context, anyhow, bail};
use rustix::fs::statx;
use tokio::{
fs,
io::{self, AsyncWriteExt as _},
@@ -72,12 +71,19 @@ impl FileSystem {
continue;
}
};
let metadata = entry.metadata().await?;
let created_at = metadata
.created()
.ok()
.map(|c| c.duration_since(UNIX_EPOCH).ok().map(|c| c.as_secs()))
.flatten();
// TODO: Use `DirEntry::metadata` once `target=x86_64-unknown-linux-musl` updates from musl 1.2.3 to 1.2.5
// https://github.com/rust-lang/rust/pull/142682
let created_at = unsafe {
statx(
std::os::fd::BorrowedFd::borrow_raw(-100),
entry.path(),
rustix::fs::AtFlags::empty(),
rustix::fs::StatxFlags::BTIME,
)
}
.ok()
.map(|statx| statx.stx_btime.tv_sec as u64);
let mime_type = match file_type {
FileType::File => FileMimeType::from_name(&name),