@@ -6,6 +6,7 @@ import * as promise from './promise.js';
66import { promisify } from './promise.js' ;
77import map from './map.js' ;
88
9+ const fcopy = require ( 'fcopy' ) ;
910const path = require ( 'path' ) ;
1011const fs = require ( 'fs' ) ;
1112const os = require ( 'os' ) ;
@@ -26,8 +27,9 @@ export const exists: (path: string) => Promise<boolean> = promisify(fs.exists, t
2627export const lstat : ( path : string ) => Promise < fs . Stats > = promisify ( fs . lstat ) ;
2728export const chmod : ( path : string , mode : number | string ) => Promise < void > = promisify ( fs . chmod ) ;
2829export const link : ( path : string ) => Promise < fs . Stats > = promisify ( fs . link ) ;
30+ export const utimes : ( path : string , atime : number , mtime : number ) => Promise < void > = promisify ( fs . utimes ) ;
2931
30- const CONCURRENT_QUEUE_ITEMS = 4 ;
32+ const CONCURRENT_QUEUE_ITEMS = 16 ;
3133
3234const fsSymlink : (
3335 target : string ,
@@ -510,37 +512,16 @@ export async function copyBulk(
510512 }
511513
512514 const cleanup = ( ) => delete currentlyWriting [ data . dest ] ;
513- return currentlyWriting [ data . dest ] = new Promise ( ( resolve , reject ) => {
514- const readStream = fs . createReadStream ( data . src ) ;
515- const writeStream = fs . createWriteStream ( data . dest , { mode : data . mode } ) ;
516-
515+ return currentlyWriting [ data . dest ] = ( async function ( ) : Promise < void > {
517516 reporter . verbose ( reporter . lang ( 'verboseFileCopy' , data . src , data . dest ) ) ;
518-
519- readStream . on ( 'error' , reject ) ;
520- writeStream . on ( 'error' , reject ) ;
521-
522- writeStream . on ( 'open' , function ( ) {
523- readStream . pipe ( writeStream ) ;
524- } ) ;
525-
526- writeStream . once ( 'close' , function ( ) {
527- fs . utimes ( data . dest , data . atime , data . mtime , function ( err ) {
528- if ( err ) {
529- reject ( err ) ;
530- } else {
531- events . onProgress ( data . dest ) ;
532- cleanup ( ) ;
533- resolve ( ) ;
534- }
535- } ) ;
536- } ) ;
537- } ) . then ( ( arg ) => {
538- cleanup ( ) ;
539- return arg ;
540- } ) . catch ( ( arg ) => {
541- cleanup ( ) ;
542- throw arg ;
543- } ) ;
517+ try {
518+ await fcopy ( data . src , data . dest , { mode : data . mode } ) ;
519+ await utimes ( data . dest , data . atime , data . mtime ) ;
520+ events . onProgress ( data . dest ) ;
521+ } finally {
522+ cleanup ( ) ;
523+ }
524+ } ) ( ) ;
544525 } , CONCURRENT_QUEUE_ITEMS ) ;
545526
546527 // we need to copy symlinks last as they could reference files we were copying
0 commit comments