Skip to content

Commit d674fb2

Browse files
committed
getlog: Correctly detect .log3 file suffix
The previous implementation used `Path::ends_with`, which checks for full path components rather than string suffixes. This caused `.log3` files to be misidentified as version 2 logs. Switched to string-based suffix checking using `to_string_lossy()` to ensure the correct reader is initialized.
1 parent 71ecdd9 commit d674fb2

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/getlog.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) async fn getlog_handler(
7171
async move {
7272
match tokio::fs::File::open(&file_path).await {
7373
Ok(file) => {
74-
if file_path.ends_with(".log3") {
74+
if file_path.to_string_lossy().ends_with(".log3") {
7575
JournalReaderLog3::new(BufReader::new(file.compat())).next().await.is_some()
7676
} else {
7777
JournalReaderLog2::new(BufReader::new(file.compat())).next().await.is_some()
@@ -120,7 +120,13 @@ pub(crate) async fn getlog_handler(
120120
tokio::fs::File::open(&file_path)
121121
.await
122122
.map_err(|err| format!("Cannot open file {file_path} in call to getLog: {err}", file_path = file_path.to_string_lossy()))
123-
.map(|file| JournalReaderLog2::new(BufReader::new(file.compat())))
123+
.map(|file|
124+
if file_path.to_string_lossy().ends_with(".log3") {
125+
Box::pin(JournalReaderLog3::new(BufReader::new(file.compat()))) as JournalEntryStream
126+
} else {
127+
Box::pin(JournalReaderLog2::new(BufReader::new(file.compat()))) as JournalEntryStream
128+
}
129+
)
124130
})
125131
.try_collect::<Vec<_>>()
126132
.await
@@ -138,7 +144,7 @@ pub(crate) async fn getlog_handler(
138144
.await
139145
.map_err(|err| RpcError::new(RpcErrorCode::InternalError, format!("Cannot get dirtylog: {err}")))?;
140146

141-
Ok(getlog_impl(site_path, file_readers.into_iter().map(|s| Box::pin(s) as _), dirtylog, params).await)
147+
Ok(getlog_impl(site_path, file_readers, dirtylog, params).await)
142148
}
143149

144150
pub(crate) type JournalEntryStream = Pin<Box<dyn Stream<Item = Result<JournalEntry, Box<dyn Error + Send + Sync>>> + Send + Sync>>;

0 commit comments

Comments
 (0)