@@ -451,6 +451,50 @@ test('-R implies -P', t => {
451
451
} ) ;
452
452
} ) ;
453
453
454
+ test ( '-Ru respects the -u flag recursively (don\'t update newer file)' , t => {
455
+ // Setup code
456
+ const TWO_DAYS_IN_MS = 2 * 24 * 60 * 60 * 1000 ;
457
+ const dir = `${ t . context . tmp } /cp-Ru` ;
458
+ const sourceDir = `${ dir } /old` ;
459
+ const sourceFile = `${ sourceDir } /file` ;
460
+ const destDir = `${ dir } /new` ;
461
+ const destFile = `${ destDir } /file` ;
462
+ [ sourceDir , destDir ] . forEach ( d => shell . mkdir ( '-p' , d ) ) ;
463
+ shell . ShellString ( 'Source File Contents\n' ) . to ( sourceFile ) ;
464
+ shell . ShellString ( 'Destination File Contents\n' ) . to ( destFile ) ;
465
+ // End setup
466
+ // Get the old mtime for dest
467
+ const oldTime = fs . statSync ( destFile ) . mtimeMs ;
468
+ // Set the source file to be older than the destination file
469
+ shell . touch ( '-m' , oldTime - TWO_DAYS_IN_MS , sourceFile ) ;
470
+ // Now, copy the old dir to the new one
471
+ shell . cp ( '-Ru' , sourceDir , destDir ) ;
472
+ // Check that dest has not been updated
473
+ t . is ( shell . cat ( destFile ) . stdout , 'Destination File Contents\n' ) ;
474
+ } ) ;
475
+
476
+ test ( '-Ru respects the -u flag recursively (update older file)' , t => {
477
+ // Setup code
478
+ const TWO_DAYS_IN_MS = 2 * 24 * 60 * 60 * 1000 ;
479
+ const dir = `${ t . context . tmp } /cp-Ru` ;
480
+ const sourceDir = `${ dir } /old` ;
481
+ const sourceFile = `${ sourceDir } /file` ;
482
+ const destDir = `${ dir } /new` ;
483
+ const destFile = `${ destDir } /file` ;
484
+ [ sourceDir , destDir ] . forEach ( d => shell . mkdir ( '-p' , d ) ) ;
485
+ shell . ShellString ( 'Source File Contents\n' ) . to ( sourceFile ) ;
486
+ shell . ShellString ( 'Destination File Contents\n' ) . to ( destFile ) ;
487
+ // End setup
488
+ // Get the old mtime for dest
489
+ const oldTime = fs . statSync ( destFile ) . mtimeMs ;
490
+ // Set the destination file to be older than the source file
491
+ shell . touch ( '-m' , oldTime + TWO_DAYS_IN_MS , sourceFile ) ;
492
+ // Now, copy the old dir to the new one
493
+ shell . cp ( '-Ru' , sourceDir , destDir ) ;
494
+ // Check that dest has been updated
495
+ t . is ( shell . cat ( sourceFile ) . stdout , 'Source File Contents\n' ) ;
496
+ } ) ;
497
+
454
498
test ( 'using -P explicitly works' , t => {
455
499
utils . skipOnWin ( t , ( ) => {
456
500
shell . cp ( '-P' , 'test/resources/cp/links/sym.lnk' , t . context . tmp ) ;
0 commit comments