fix(vfs): V-05 — log flush failure as error in sanctum file drop and ensure flush on close
This commit is contained in:
+34
-3
@@ -318,9 +318,9 @@ impl SanctumFile {
|
||||
impl Drop for SanctumFile {
|
||||
fn drop(&mut self) {
|
||||
if let Err(e) = self.flush_cached_chunk_and_size() {
|
||||
warn!(
|
||||
"Fehler beim automatischen Flush im SanctumFile::drop: {:?}",
|
||||
e
|
||||
error!(
|
||||
"SanctumFile::drop: Fehler beim automatischen Flush von Knoten {}: {:?}",
|
||||
self.node_id, e
|
||||
);
|
||||
}
|
||||
if let Some((_, ref mut data, _)) = self.cached_chunk {
|
||||
@@ -1457,4 +1457,35 @@ mod tests {
|
||||
let bytes = read_empty.read_bytes(100).await.unwrap();
|
||||
assert!(bytes.is_empty(), "Leere Datei liefert 0 Bytes ohne Fehler");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_v05_sanctum_file_drop_flushes_dirty_chunk_automatically() {
|
||||
let (fs, _dir) = create_test_fs(true);
|
||||
let path = DavPath::new("/drop_flush_test.bin").unwrap();
|
||||
|
||||
let mut opts = OpenOptions::default();
|
||||
opts.write = true;
|
||||
opts.create_new = true;
|
||||
let mut file = fs.open(&path, opts).await.unwrap();
|
||||
|
||||
let test_data = b"Autoflush on drop without explicit flush() call (V-05)";
|
||||
file.write_bytes(Bytes::copy_from_slice(test_data))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Absichtlich KEIN file.flush().await aufrufen!
|
||||
// Drop des Handles muss Daten & Größe zwingend automatisch persistieren.
|
||||
drop(file);
|
||||
|
||||
// Prüfe, ob Datei in DB existiert und korrekte Größe hat
|
||||
let node = fs.resolve_path("/drop_flush_test.bin").unwrap().unwrap();
|
||||
assert_eq!(node.size, test_data.len() as u64);
|
||||
|
||||
// Lese Datei neu ein und verifiziere Inhalt
|
||||
let mut read_opts = OpenOptions::default();
|
||||
read_opts.read = true;
|
||||
let mut read_file = fs.open(&path, read_opts).await.unwrap();
|
||||
let read_bytes = read_file.read_bytes(test_data.len()).await.unwrap();
|
||||
assert_eq!(&read_bytes[..], test_data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user