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

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),