File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -489,13 +489,7 @@ async function readSessionLogSnapshot(params: {
489489 snapshot . byteSize = Math . floor ( scannedSize ) ;
490490 return snapshot ;
491491 }
492- try {
493- const stat = await fs . promises . stat ( logPath ) ;
494- const size = Math . floor ( stat . size ) ;
495- snapshot . byteSize = Number . isFinite ( size ) && size >= 0 ? size : undefined ;
496- } catch {
497- snapshot . byteSize = undefined ;
498- }
492+ snapshot . byteSize = await readSessionLogByteSize ( logPath ) ;
499493 }
500494
501495 return snapshot ;
@@ -507,6 +501,20 @@ type SessionLogUsageScan = {
507501 byteSize : number ;
508502} ;
509503
504+ async function readSessionLogByteSize ( logPath : string ) : Promise < number | undefined > {
505+ let handle : fs . promises . FileHandle | undefined ;
506+ try {
507+ handle = await fs . promises . open ( logPath , "r" ) ;
508+ const stat = await handle . stat ( ) ;
509+ const size = Math . floor ( stat . size ) ;
510+ return Number . isFinite ( size ) && size >= 0 ? size : undefined ;
511+ } catch {
512+ return undefined ;
513+ } finally {
514+ await handle ?. close ( ) ;
515+ }
516+ }
517+
510518async function readLastNonzeroUsageFromSessionLog ( logPath : string ) : Promise < SessionLogUsageScan > {
511519 const handle = await fs . promises . open ( logPath , "r" ) ;
512520 try {
You can’t perform that action at this time.
0 commit comments