pub async fn migrate_legacy_session_layout(
data_dir: &Path,
) -> Result<MigrationReport, SessionError>Expand description
Moves any session directories still sitting at the pre-#5981 on-disk layout
(<data_dir>/sessions/<session_id>/) up one level to the fixed layout
(<data_dir>/<session_id>/), which is what session_dir now resolves to.
Before #5981, session_dir appended a redundant sessions segment, so any session created
before the fix physically has its events.jsonl/blobs/ one directory level deeper than
where the crate now looks. Left unmigrated, log::SessionEventLog::open silently
create_dir_alls and creates a blank log at the new (empty) path — the user’s real history
becomes unreachable with zero error or warning. This function is meant to be called once at
process startup, before any session is opened, to make that transition transparent.
A destination that already exists is left untouched (skipped, with a tracing::warn!)
rather than clobbered. Idempotent: once every legacy subdirectory has been moved (or
skipped), a subsequent run finds an empty (or absent) <data_dir>/sessions/ and returns
cheaply; a missing <data_dir>/sessions/ (a brand-new install, or one already migrated) is
not an error.
§Errors
Returns SessionError::Io if <data_dir>/sessions/ exists but cannot be listed, or if a
rename or an existence check fails for a reason other than the destination not existing.
§Examples
use std::path::Path;
let dir = tempfile::tempdir().unwrap();
// Brand-new install: no `sessions/` subdirectory yet — a cheap no-op, not an error.
let report = zeph_session::migrate_legacy_session_layout(dir.path()).await.unwrap();
assert_eq!(report, zeph_session::MigrationReport::default());