@@ -197,7 +197,7 @@ pub fn open_session(path: &str) -> Result<ViewerOpenResult, ViewerError> {
197197 match LineIndexBackend :: open ( & path_clone, & cancel_for_indexer) {
198198 Ok ( new_backend) => {
199199 if !cancel_for_indexer. load ( Ordering :: Relaxed ) {
200- let mut sessions = SESSIONS . lock ( ) . unwrap ( ) ;
200+ let mut sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
201201 if let Some ( session) = sessions. get_mut ( & session_id_clone) {
202202 debug ! (
203203 "Indexing completed for session {}, upgrading to LineIndex" ,
@@ -259,14 +259,17 @@ pub fn open_session(path: &str) -> Result<ViewerOpenResult, ViewerError> {
259259 is_indexing,
260260 } ;
261261
262- SESSIONS . lock ( ) . unwrap ( ) . insert ( session_id, session) ;
262+ SESSIONS
263+ . lock ( )
264+ . unwrap_or_else ( |e| e. into_inner ( ) )
265+ . insert ( session_id, session) ;
263266
264267 Ok ( result)
265268}
266269
267270/// Gets the current status of a session (backend type, indexing state).
268271pub fn get_session_status ( session_id : & str ) -> Result < ViewerSessionStatus , ViewerError > {
269- let sessions = SESSIONS . lock ( ) . unwrap ( ) ;
272+ let sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
270273 let session = sessions
271274 . get ( session_id)
272275 . ok_or ( ViewerError :: SessionNotFound ( session_id. to_string ( ) ) ) ?;
@@ -280,7 +283,7 @@ pub fn get_session_status(session_id: &str) -> Result<ViewerSessionStatus, Viewe
280283
281284/// Gets a range of lines from a session.
282285pub fn get_lines ( session_id : & str , target : SeekTarget , count : usize ) -> Result < LineChunk , ViewerError > {
283- let sessions = SESSIONS . lock ( ) . unwrap ( ) ;
286+ let sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
284287 let session = sessions
285288 . get ( session_id)
286289 . ok_or ( ViewerError :: SessionNotFound ( session_id. to_string ( ) ) ) ?;
@@ -313,7 +316,7 @@ pub fn search_start(session_id: &str, query: String) -> Result<(), ViewerError>
313316
314317 // Get the file path from the session to open a fresh file handle in the search thread
315318 let path = {
316- let mut sessions = SESSIONS . lock ( ) . unwrap ( ) ;
319+ let mut sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
317320 let session = sessions
318321 . get_mut ( session_id)
319322 . ok_or ( ViewerError :: SessionNotFound ( session_id. to_string ( ) ) ) ?;
@@ -332,30 +335,30 @@ pub fn search_start(session_id: &str, query: String) -> Result<(), ViewerError>
332335 let backend = match ByteSeekBackend :: open ( & path) {
333336 Ok ( b) => b,
334337 Err ( _) => {
335- * status_clone. lock ( ) . unwrap ( ) = SearchStatus :: Done ;
338+ * status_clone. lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) = SearchStatus :: Done ;
336339 return ;
337340 }
338341 } ;
339342
340343 let result = backend. search ( & query, & cancel_clone, & matches_clone) ;
341344 let final_scanned: u64 = result. unwrap_or_default ( ) ;
342345
343- * bytes_scanned_clone. lock ( ) . unwrap ( ) = final_scanned;
346+ * bytes_scanned_clone. lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) = final_scanned;
344347
345348 let final_status = if cancel_clone. load ( Ordering :: Relaxed ) {
346349 SearchStatus :: Cancelled
347350 } else {
348351 SearchStatus :: Done
349352 } ;
350- * status_clone. lock ( ) . unwrap ( ) = final_status;
353+ * status_clone. lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) = final_status;
351354 } ) ;
352355
353356 Ok ( ( ) )
354357}
355358
356359/// Polls search progress for a session.
357360pub fn search_poll ( session_id : & str ) -> Result < SearchPollResult , ViewerError > {
358- let sessions = SESSIONS . lock ( ) . unwrap ( ) ;
361+ let sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
359362 let session = sessions
360363 . get ( session_id)
361364 . ok_or ( ViewerError :: SessionNotFound ( session_id. to_string ( ) ) ) ?;
@@ -370,9 +373,9 @@ pub fn search_poll(session_id: &str) -> Result<SearchPollResult, ViewerError> {
370373 bytes_scanned : 0 ,
371374 } ) ,
372375 Some ( search) => {
373- let status = search. status . lock ( ) . unwrap ( ) . clone ( ) ;
374- let matches = search. matches . lock ( ) . unwrap ( ) . clone ( ) ;
375- let bytes_scanned = * search. bytes_scanned . lock ( ) . unwrap ( ) ;
376+ let status = search. status . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) . clone ( ) ;
377+ let matches = search. matches . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) . clone ( ) ;
378+ let bytes_scanned = * search. bytes_scanned . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
376379
377380 Ok ( SearchPollResult {
378381 status,
@@ -386,7 +389,7 @@ pub fn search_poll(session_id: &str) -> Result<SearchPollResult, ViewerError> {
386389
387390/// Cancels an ongoing search.
388391pub fn search_cancel ( session_id : & str ) -> Result < ( ) , ViewerError > {
389- let mut sessions = SESSIONS . lock ( ) . unwrap ( ) ;
392+ let mut sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
390393 let session = sessions
391394 . get_mut ( session_id)
392395 . ok_or ( ViewerError :: SessionNotFound ( session_id. to_string ( ) ) ) ?;
@@ -401,7 +404,7 @@ pub fn search_cancel(session_id: &str) -> Result<(), ViewerError> {
401404
402405/// Closes a viewer session and frees resources.
403406pub fn close_session ( session_id : & str ) -> Result < ( ) , ViewerError > {
404- let mut sessions = SESSIONS . lock ( ) . unwrap ( ) ;
407+ let mut sessions = SESSIONS . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) ;
405408 if let Some ( session) = sessions. remove ( session_id) {
406409 // Cancel any ongoing search
407410 if let Some ( search) = & session. search {
0 commit comments