Skip to content

Commit 0172654

Browse files
committed
Simplify stat import and avoid variable shadowing in download-lock
1 parent 974c2dd commit 0172654

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

registry/src/lib/download-lock.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @fileoverview Download locking utilities to prevent concurrent downloads of the same resource. Uses file-based locking for cross-process synchronization. */
22

33
import { existsSync } from 'node:fs'
4-
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
4+
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises'
55
import { dirname, join } from 'node:path'
66

77
import { httpDownload } from './http-request'
@@ -199,13 +199,11 @@ export async function downloadWithLock(
199199

200200
// If file already exists and has content, return immediately
201201
if (existsSync(destPath)) {
202-
const stat = await import('node:fs/promises').then(m =>
203-
m.stat(destPath).catch(() => null),
204-
)
205-
if (stat && stat.size > 0) {
202+
const statResult = await stat(destPath).catch(() => null)
203+
if (statResult && statResult.size > 0) {
206204
return {
207205
path: destPath,
208-
size: stat.size,
206+
size: statResult.size,
209207
}
210208
}
211209
}
@@ -221,13 +219,11 @@ export async function downloadWithLock(
221219
try {
222220
// Check again if file was created while we were waiting for lock
223221
if (existsSync(destPath)) {
224-
const stat = await import('node:fs/promises').then(m =>
225-
m.stat(destPath).catch(() => null),
226-
)
227-
if (stat && stat.size > 0) {
222+
const statResult = await stat(destPath).catch(() => null)
223+
if (statResult && statResult.size > 0) {
228224
return {
229225
path: destPath,
230-
size: stat.size,
226+
size: statResult.size,
231227
}
232228
}
233229
}

0 commit comments

Comments
 (0)