fix(io): handle file shrink in update_for_append to prevent SIGBUS
File truncation/rotation during mmap lifetime caused SIGBUS crash because update_for_append() ignored new_size < old_size, leaving a stale mapping that would fault on access. Introduce AppendStatus enum (Unchanged/Appended/Reloaded) so the caller can distinguish shrink events from normal appends. On shrink, reload() rebuilds the mmap and line index. The TUI layer clamps cursor and invalidates viewport cache on Reloaded, matching the existing handle_file_truncated() behavior. Fixes #1
This commit is contained in:
@@ -3,7 +3,7 @@ use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::error::{CoreError, Result};
|
||||
use crate::io::file_reader::FileReader;
|
||||
use crate::io::file_reader::{AppendStatus, FileReader};
|
||||
use crate::io::index_cache::IndexCache;
|
||||
use crate::io::line_index::LineIndex;
|
||||
use crate::io::line_sampler::sample_line_count;
|
||||
@@ -656,10 +656,10 @@ impl ProgressiveFileReader {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_for_append(&mut self) -> Result<u64> {
|
||||
pub fn update_for_append(&mut self) -> Result<AppendStatus> {
|
||||
match &mut self.state {
|
||||
ReaderState::Ready { reader, .. } => reader.update_for_append(),
|
||||
_ => Ok(0),
|
||||
_ => Ok(AppendStatus::Unchanged),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user