Propagate unexpected metadata errors when preserving mtime in fs_store
What changed, and why it matters
This change fixes a bug in the file storage component where errors from checking a file's metadata (such as permission denied or disk I/O problems) were silently ignored. Now, most unexpected errors are reported up the chain instead of being swallowed, so the software can react appropriately rather than silently losing information about file modification times.
Review callers of write_file to ensure they handle propagated I/O errors gracefully, and consider backporting to stable branches since silent metadata failures could previously mask persistence problems.
Security signals we found
Silent error suppression removed
Permission and I/O errors now propagated
File metadata handling hardened
Evidence from the diff
In lightning-persister’s fs_store, the write_file method optionally preserves the source file’s modification time. Previously, fs::metadata(&dest_file_path).ok().and_then(|m| m.modified().ok()) silently discarded all metadata errors via .ok(). The patch changes this to explicitly match on the Result: NotFound errors are treated as expected (returning None, since there is no existing mtime to preserve), while any other error is propagated as a lightning::io::Error. This prevents masking permission, I/O, or other filesystem failures during persistence operations.
Changed components
lightning-persister/src/fs_store/common.rsFilesystemStoreInner::write_fileInspect captured patch +6 / −2
diff --git a/lightning-persister/src/fs_store/common.rs b/lightning-persister/src/fs_store/common.rs
index f2f5eeb..7aef941 100644
--- a/lightning-persister/src/fs_store/common.rs
+++ b/lightning-persister/src/fs_store/common.rs
@@ -9,7 +9,7 @@ use lightning::types::string::PrintableString;
use std::collections::HashMap;
use std::fs;
-use std::io::{Read, Write};
+use std::io::{ErrorKind, Read, Write};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, RwLock};
@@ -253,7 +253,11 @@ impl FilesystemStoreInner {
version: u64, preserve_mtime: bool,
) -> lightning::io::Result<()> {
let mtime = if preserve_mtime {
- fs::metadata(&dest_file_path).ok().and_then(|m| m.modified().ok())
+ match fs::metadata(&dest_file_path) {
+ Err(e) if e.kind() == ErrorKind::NotFound => None,
+ Err(e) => return Err(e.into()),
+ Ok(m) => Some(m.modified()?),
+ }
} else {
None
};
Why this scored 35/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.