Use tid for Date Modified #7

merged
opened by danabra.mov targeting main from danabra.mov/pdsfs: add-tid

So it appears nicer in Finder.

Changed files
+30 -5
src
+30 -5
src/fs.rs
···
-
use std::time;
+
use std::time::{self, SystemTime, UNIX_EPOCH, Duration};
use atrium_repo::{Repository, blockstore::AsyncBlockStoreRead};
use futures::StreamExt;
···
type Inode = usize;
+
/// Decode a TID (timestamp identifier) to get the timestamp in microseconds since Unix epoch
+
fn tid_to_timestamp(tid: &str) -> Option<SystemTime> {
+
const S32_CHAR: &[u8] = b"234567abcdefghijklmnopqrstuvwxyz";
+
+
if tid.len() != 13 {
+
return None;
+
}
+
+
let mut value: u64 = 0;
+
for ch in tid.chars() {
+
let pos = S32_CHAR.iter().position(|&c| c as char == ch)?;
+
// Big-endian: first character is most significant
+
value = (value << 5) | (pos as u64);
+
}
+
+
// Extract timestamp from upper bits (shifted by 10)
+
let micros = value >> 10;
+
+
UNIX_EPOCH.checked_add(Duration::from_micros(micros))
+
}
+
pub struct PdsFs<R> {
repos: IndexMap<String, Repository<R>>,
inodes: IndexSet<PdsFsEntry>,
···
.map_or(0, |v| serde_json::to_string(&v).unwrap().len())
as u64;
let blocks = ((size as u32 + BLKSIZE - 1) / BLKSIZE) as u64;
+
+
// Decode TID to get creation timestamp
+
let timestamp = tid_to_timestamp(&r.rkey).unwrap_or(time::UNIX_EPOCH);
+
fuser::FileAttr {
ino,
size,
blocks,
-
atime: time::UNIX_EPOCH,
-
mtime: time::UNIX_EPOCH,
-
ctime: time::UNIX_EPOCH,
-
crtime: time::UNIX_EPOCH,
+
atime: timestamp,
+
mtime: timestamp,
+
ctime: timestamp,
+
crtime: timestamp,
kind: fuser::FileType::RegularFile,
perm: 0o644,
nlink: 1,