@@ -176,20 +176,18 @@ async function syncSymlink(src, dst, sandbox, exists) {
176
176
return 1
177
177
}
178
178
179
- async function syncDirectory ( src , dst , sandbox , writePerm ) {
179
+ async function syncDirectory ( file , src , sandbox , writePerm ) {
180
180
if ( process . env . JS_BINARY__LOG_DEBUG ) {
181
- console . error (
182
- `Syncing directory ${ src . slice ( RUNFILES_ROOT . length + 1 ) } ...`
183
- )
181
+ console . error ( `Syncing directory ${ file } ...` )
184
182
}
185
183
const contents = await fs . promises . readdir ( src )
186
184
return (
187
185
await Promise . all (
188
186
contents . map (
189
187
async ( entry ) =>
190
188
await syncRecursive (
191
- path . join ( src , entry ) ,
192
- path . join ( dst , entry ) ,
189
+ path . join ( file , entry ) ,
190
+ undefined ,
193
191
sandbox ,
194
192
writePerm
195
193
)
@@ -201,9 +199,9 @@ async function syncDirectory(src, dst, sandbox, writePerm) {
201
199
async function syncFile ( src , dst , exists , lstat , writePerm ) {
202
200
if ( process . env . JS_BINARY__LOG_DEBUG ) {
203
201
console . error (
204
- `Syncing file ${ src . slice (
205
- RUNFILES_ROOT . length + 1
206
- ) } ( ${ friendlyFileSize ( lstat . size ) } )`
202
+ `Syncing file ${ src . slice ( RUNFILES_ROOT . length + 1 ) } ${
203
+ lstat ? ' (' + friendlyFileSize ( lstat . size ) + ')' : ''
204
+ } )`
207
205
)
208
206
}
209
207
if ( exists ) {
@@ -237,7 +235,10 @@ async function syncFile(src, dst, exists, lstat, writePerm) {
237
235
// synced it is only re-copied if the file's last modified time has changed since the last time that
238
236
// file was copied. Symlinks are not copied but instead a symlink is created under the destination
239
237
// pointing to the source symlink.
240
- async function syncRecursive ( src , dst , sandbox , writePerm ) {
238
+ async function syncRecursive ( file , _ , sandbox , writePerm ) {
239
+ const src = path . join ( RUNFILES_ROOT , file )
240
+ const dst = path . join ( sandbox , file )
241
+
241
242
try {
242
243
const lstat = await withRetry (
243
244
( ) => fs . promises . lstat ( src ) ,
@@ -260,7 +261,7 @@ async function syncRecursive(src, dst, sandbox, writePerm) {
260
261
if ( lstat . isSymbolicLink ( ) ) {
261
262
return syncSymlink ( src , dst , sandbox , exists )
262
263
} else if ( lstat . isDirectory ( ) ) {
263
- return syncDirectory ( src , dst , sandbox , writePerm )
264
+ return syncDirectory ( file , src , sandbox , writePerm )
264
265
} else {
265
266
const lastChecksum = syncedChecksum . get ( src )
266
267
const checksum = await generateChecksum ( src )
@@ -293,8 +294,11 @@ async function deleteFiles(previousFiles, updatedFiles, sandbox) {
293
294
const deletions = [ ]
294
295
295
296
// Remove files that were previously synced but are no longer in the updated list of files to sync
296
- const updatedFilesSet = new Set ( updatedFiles )
297
- for ( const f of previousFiles ) {
297
+ const updatedFilesSet = new Set ( )
298
+ for ( const [ f ] of updatedFiles ) {
299
+ updatedFilesSet . add ( f )
300
+ }
301
+ for ( const [ f ] of previousFiles ) {
298
302
if ( updatedFilesSet . has ( f ) ) {
299
303
continue
300
304
}
@@ -353,18 +357,19 @@ async function syncFiles(files, sandbox, writePerm, doSync) {
353
357
const packageStore1pDeps = [ ]
354
358
const otherNodeModulesFiles = [ ]
355
359
const otherFiles = [ ]
356
- for ( const file of files ) {
360
+ for ( const fileInfo of files ) {
361
+ const file = fileInfo [ 0 ]
357
362
if ( isNodeModulePath ( file ) ) {
358
363
// Node module file
359
364
if ( is1pPackageStoreDep ( file ) ) {
360
365
// 1p package store dep
361
- packageStore1pDeps . push ( file )
366
+ packageStore1pDeps . push ( fileInfo )
362
367
} else {
363
368
// Other node_modules file
364
- otherNodeModulesFiles . push ( file )
369
+ otherNodeModulesFiles . push ( fileInfo )
365
370
}
366
371
} else {
367
- otherFiles . push ( file )
372
+ otherFiles . push ( fileInfo )
368
373
}
369
374
}
370
375
@@ -378,10 +383,8 @@ async function syncFiles(files, sandbox, writePerm, doSync) {
378
383
379
384
let totalSynced = (
380
385
await Promise . all (
381
- otherFiles . map ( async ( file ) => {
382
- const src = path . join ( RUNFILES_ROOT , file )
383
- const dst = path . join ( sandbox , file )
384
- return await doSync ( src , dst , sandbox , writePerm )
386
+ otherFiles . map ( async ( [ file , isDirectory ] ) => {
387
+ return await doSync ( file , isDirectory , sandbox , writePerm )
385
388
} )
386
389
)
387
390
) . reduce ( ( s , t ) => s + t , 0 )
@@ -396,10 +399,8 @@ async function syncFiles(files, sandbox, writePerm, doSync) {
396
399
397
400
totalSynced += (
398
401
await Promise . all (
399
- packageStore1pDeps . map ( async ( file ) => {
400
- const src = path . join ( RUNFILES_ROOT , file )
401
- const dst = path . join ( sandbox , file )
402
- return await doSync ( src , dst , sandbox , writePerm )
402
+ packageStore1pDeps . map ( async ( [ file , isDirectory ] ) => {
403
+ return await doSync ( file , isDirectory , sandbox , writePerm )
403
404
} )
404
405
)
405
406
) . reduce ( ( s , t ) => s + t , 0 )
@@ -413,10 +414,8 @@ async function syncFiles(files, sandbox, writePerm, doSync) {
413
414
414
415
totalSynced += (
415
416
await Promise . all (
416
- otherNodeModulesFiles . map ( async ( file ) => {
417
- const src = path . join ( RUNFILES_ROOT , file )
418
- const dst = path . join ( sandbox , file )
419
- return await doSync ( src , dst , sandbox , writePerm )
417
+ otherNodeModulesFiles . map ( async ( [ file , isDirectory ] ) => {
418
+ return await doSync ( file , isDirectory , sandbox , writePerm )
420
419
} )
421
420
)
422
421
) . reduce ( ( s , t ) => s + t , 0 )
@@ -658,7 +657,7 @@ async function watchProtocolCycle(config, entriesPath, sandbox, cycle) {
658
657
const newFiles = await fs . promises . readFile ( entriesPath ) . then ( JSON . parse )
659
658
660
659
// Only sync files changed in the current cycle.
661
- const filesToSync = newFiles . filter ( ( f ) =>
660
+ const filesToSync = newFiles . filter ( ( [ f ] ) =>
662
661
cycle . sources . hasOwnProperty ( `${ process . env . JS_BINARY__WORKSPACE } /${ f } ` )
663
662
)
664
663
@@ -679,7 +678,10 @@ async function watchProtocolCycle(config, entriesPath, sandbox, cycle) {
679
678
config . previous_entries = newFiles
680
679
}
681
680
682
- async function cycleSyncRecurse ( cycle , src , dst , sandbox , writePerm ) {
681
+ async function cycleSyncRecurse ( cycle , file , isDirectory , sandbox , writePerm ) {
682
+ const src = path . join ( RUNFILES_ROOT , file )
683
+ const dst = path . join ( sandbox , file )
684
+
683
685
// Assume it exists if it has been synced before.
684
686
const exists = syncedTime . has ( src )
685
687
@@ -700,23 +702,10 @@ async function cycleSyncRecurse(cycle, src, dst, sandbox, writePerm) {
700
702
return syncSymlink ( src , dst , sandbox , exists )
701
703
}
702
704
703
- let isDirectory = false
704
- let lstat = null
705
- if ( isNodeModulePath ( src ) ) {
706
- // A node_modules path which is not a symlink is always a directory
707
- isDirectory = true
708
- } else {
709
- // Otherwise a fs.lstat is needed to determine if it is a directory
710
- // TODO: move to protocol capability that expands directories
711
- lstat = await fs . promises . lstat ( src )
712
-
713
- isDirectory = lstat . isDirectory ( )
714
- }
715
-
716
705
if ( isDirectory ) {
717
- return syncDirectory ( src , dst , sandbox , writePerm )
706
+ return syncDirectory ( file , src , sandbox , writePerm )
718
707
} else {
719
- return syncFile ( src , dst , exists , lstat , writePerm )
708
+ return syncFile ( src , dst , exists , null , writePerm )
720
709
}
721
710
}
722
711
0 commit comments