@@ -145,21 +145,27 @@ export class Context {
145145 await fsPromises . unlink ( tempPath ) . catch ( noop )
146146 throw new errors . INVALID_MAP_FILE ( )
147147 } finally {
148- await tempReader . close ( ) . catch ( noop )
148+ await tempReader . close ( ) . catch ( ( e ) => {
149+ console . error ( 'Error closing temp reader:' , e )
150+ } )
149151 }
150152
151153 // Graceful replacement of SMP Reader when map file is updated
152154 const readerPromise = ( async ( ) => {
153155 const existingReaderPromise = this . #mapReaders. get ( mapId )
154156 if ( existingReaderPromise ) {
157+ console . log ( `Closing existing reader for map ID "${ mapId } "` )
155158 const existingReader = await existingReaderPromise
156- await existingReader . close ( ) . catch ( noop )
159+ await existingReader . opened ( ) . catch ( noop ) // Ensure reader is fully opened before closing
160+ await existingReader . close ( ) . catch ( ( e ) => {
161+ console . error ( 'Error closing existing reader:' , e )
162+ } )
157163 }
158- await fsPromises . cp ( tempPath , mapFileUrl , { force : true } )
164+ await fsPromises . rename ( tempPath , mapFileUrl )
159165 return new Reader ( fileURLToPath ( mapFileUrl ) )
160166 } ) ( )
161167 this . #mapReaders. set ( mapId , readerPromise )
162- // Wait for the file copy to complete before closing the stream
168+ // Wait for the file rename to complete before closing the stream
163169 await readerPromise
164170 } ,
165171 async abort ( err ) {
0 commit comments