@@ -26,22 +26,18 @@ export class CopyLockStalledError extends Error {
2626 }
2727}
2828
29- /** The newest change among the lock and the owner's temp and piece files: how recently the owner did anything. */
3029function lastActivityMs ( cachePath : string , lockPath : string ) : number {
3130 const name = basename ( cachePath ) ;
3231 const stem = basename ( cachePath , extname ( cachePath ) ) ;
3332 const mine = ( file : string ) =>
3433 file === basename ( lockPath ) ||
35- ( file . startsWith ( ".tmp-" ) && file . endsWith ( `-${ name } ` ) ) ||
34+ ( file . startsWith ( ".tmp-" ) && ( file . endsWith ( `-${ name } ` ) || file . includes ( `-.part- ${ stem } -` ) ) ) ||
3635 file . startsWith ( `.part-${ stem } -` ) ;
3736 let newest = 0 ;
3837 for ( const file of readdirSync ( dirname ( cachePath ) ) ) {
3938 if ( ! mine ( file ) ) continue ;
40- try {
41- newest = Math . max ( newest , statSync ( join ( dirname ( cachePath ) , file ) ) . mtimeMs ) ;
42- } catch {
43- // gone between the listing and the stat
44- }
39+ const changed = statSync ( join ( dirname ( cachePath ) , file ) , { throwIfNoEntry : false } ) ?. mtimeMs ;
40+ newest = Math . max ( newest , changed ?? 0 ) ;
4541 }
4642 return newest ;
4743}
@@ -77,8 +73,7 @@ function pause(ms: number, signal: AbortSignal): Promise<void> {
7773 } ) ;
7874}
7975
80- /** The right to make the copy at `cachePath`; null once another process finished it. Takes over a dead owner's lock,
81- * and gives up on a live one that has changed nothing for `stallMs` (a hung or recycled-pid owner). */
76+ /** The right to make the copy at `cachePath`; null once another process finished it; throws on a stalled live owner. */
8277export async function acquireCopyLock (
8378 cachePath : string ,
8479 signal : AbortSignal ,
0 commit comments