memoryd: serve, three sockets and one lock over the files and the index
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -352,6 +352,25 @@ impl Index {
|
||||
}
|
||||
}
|
||||
|
||||
/// The logs of one session: `(epoch, path)`, sorted. A session with no directory has none.
|
||||
pub fn session_logs(sessions: &Path, session: &str) -> Result<Vec<(i64, PathBuf)>, String> {
|
||||
let dir = sessions.join(session);
|
||||
let files = match std::fs::read_dir(&dir) {
|
||||
Ok(files) => files,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()),
|
||||
Err(e) => return Err(format!("{}: {e}", dir.display())),
|
||||
};
|
||||
let mut found = Vec::new();
|
||||
for file in files.filter_map(|f| f.ok()) {
|
||||
let name = file.file_name().to_string_lossy().into_owned();
|
||||
if let Some(Ok(epoch)) = name.strip_suffix(".jsonl").map(str::parse::<i64>) {
|
||||
found.push((epoch, file.path()));
|
||||
}
|
||||
}
|
||||
found.sort();
|
||||
Ok(found)
|
||||
}
|
||||
|
||||
/// Every session log under `sessions`: `(session, epoch, path)`, sorted.
|
||||
pub fn logs(sessions: &Path) -> Result<Vec<(String, i64, PathBuf)>, String> {
|
||||
// Read the directory `sessions` (NotFound -> Ok(empty); another error -> Err naming it). For
|
||||
|
||||
Reference in New Issue
Block a user