tangled
alpha
login
or
join now
danabra.mov
/
pdsfs
forked from
oppi.li/pdsfs
1
fork
atom
mount an atproto PDS repository as a FUSE filesystem
1
fork
atom
overview
issues
pulls
pipelines
add tid
danabra.mov
4 months ago
0f3f8eb0
c0811193
+30
-5
1 changed file
expand all
collapse all
unified
split
src
fs.rs
+30
-5
src/fs.rs
···
1
1
-
use std::time;
1
1
+
use std::time::{self, SystemTime, UNIX_EPOCH, Duration};
2
2
3
3
use atrium_repo::{Repository, blockstore::AsyncBlockStoreRead};
4
4
use futures::StreamExt;
5
5
use indexmap::{IndexMap, IndexSet};
6
6
7
7
type Inode = usize;
8
8
+
9
9
+
/// Decode a TID (timestamp identifier) to get the timestamp in microseconds since Unix epoch
10
10
+
fn tid_to_timestamp(tid: &str) -> Option<SystemTime> {
11
11
+
const S32_CHAR: &[u8] = b"234567abcdefghijklmnopqrstuvwxyz";
12
12
+
13
13
+
if tid.len() != 13 {
14
14
+
return None;
15
15
+
}
16
16
+
17
17
+
let mut value: u64 = 0;
18
18
+
for ch in tid.chars() {
19
19
+
let pos = S32_CHAR.iter().position(|&c| c as char == ch)?;
20
20
+
// Big-endian: first character is most significant
21
21
+
value = (value << 5) | (pos as u64);
22
22
+
}
23
23
+
24
24
+
// Extract timestamp from upper bits (shifted by 10)
25
25
+
let micros = value >> 10;
26
26
+
27
27
+
UNIX_EPOCH.checked_add(Duration::from_micros(micros))
28
28
+
}
8
29
9
30
pub struct PdsFs<R> {
10
31
repos: IndexMap<String, Repository<R>>,
···
172
193
.map_or(0, |v| serde_json::to_string(&v).unwrap().len())
173
194
as u64;
174
195
let blocks = ((size as u32 + BLKSIZE - 1) / BLKSIZE) as u64;
196
196
+
197
197
+
// Decode TID to get creation timestamp
198
198
+
let timestamp = tid_to_timestamp(&r.rkey).unwrap_or(time::UNIX_EPOCH);
199
199
+
175
200
fuser::FileAttr {
176
201
ino,
177
202
size,
178
203
blocks,
179
179
-
atime: time::UNIX_EPOCH,
180
180
-
mtime: time::UNIX_EPOCH,
181
181
-
ctime: time::UNIX_EPOCH,
182
182
-
crtime: time::UNIX_EPOCH,
204
204
+
atime: timestamp,
205
205
+
mtime: timestamp,
206
206
+
ctime: timestamp,
207
207
+
crtime: timestamp,
183
208
kind: fuser::FileType::RegularFile,
184
209
perm: 0o644,
185
210
nlink: 1,