fix(journal): canonicalize file paths in JournalStorage constructors

Resolve symlinks and `../` traversals best-effort in `new()` and
`open()`, falling back to the original path if canonicalization fails
(e.g. file doesn't exist yet).
This commit is contained in:
Manuel Raimann
2026-02-12 16:34:27 +01:00
parent cfa8426312
commit 8c025b4525
+9 -2
View File
@@ -149,9 +149,13 @@ impl<V: Serialize + DeserializeOwned + Send + Sync> JournalStorage<V> {
/// [`JournalStorage::open`] instead.
#[must_use]
pub fn new(path: impl AsRef<Path>) -> Self {
let path = path
.as_ref()
.canonicalize()
.unwrap_or_else(|_| path.as_ref().to_path_buf());
Self {
memory: MemoryStorage::new(),
path: path.as_ref().to_path_buf(),
path,
write_lock: Mutex::new(()),
file_offset: AtomicU64::new(0),
_marker: PhantomData,
@@ -168,7 +172,10 @@ impl<V: Serialize + DeserializeOwned + Send + Sync> JournalStorage<V> {
/// Return a [`Storage`](crate::Error::Storage) error if the file
/// exists but cannot be read or parsed.
pub fn open(path: impl AsRef<Path>) -> crate::Result<Self> {
let path = path.as_ref().to_path_buf();
let path = path
.as_ref()
.canonicalize()
.unwrap_or_else(|_| path.as_ref().to_path_buf());
let (trials, offset) = load_trials_from_file(&path)?;
Ok(Self {
memory: MemoryStorage::with_trials(trials),