@@ -231,36 +231,38 @@ assert.equal(shell.error(), null); // crash test only
231231assert . ok ( ! result . stderr ) ;
232232assert . equal ( result . code , 0 ) ;
233233
234- // Recursive, everything exists, overwrite a real file with a link (if same name)
235- // Because -R implies to not follow links!
236- shell . rm ( '-rf' , 'tmp/*' ) ;
237- shell . cp ( '-R' , 'resources/cp/*' , 'tmp' ) ;
238- assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
239- assert . ok ( ! ( fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ) ; // this one isn't
240- assert . notEqual ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
241- result = shell . cp ( '-R' , 'tmp/links/*' , 'tmp/fakeLinks' ) ;
242- assert . equal ( shell . error ( ) , null ) ;
243- assert . ok ( ! result . stderr ) ;
244- assert . equal ( result . code , 0 ) ;
245- assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
246- assert . ok ( fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is now a link
247- assert . equal ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
248-
249- // Recursive, everything exists, overwrite a real file *by following a link*
250- // Because missing the -R implies -L.
251- shell . rm ( '-rf' , 'tmp/*' ) ;
252- shell . cp ( '-R' , 'resources/cp/*' , 'tmp' ) ;
253- assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
254- assert . ok ( ! ( fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ) ; // this one isn't
255- assert . notEqual ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
256- result = shell . cp ( 'tmp/links/*' , 'tmp/fakeLinks' ) ; // don't use -R
257- assert . equal ( shell . error ( ) , null ) ;
258- assert . ok ( ! result . stderr ) ;
259- assert . equal ( result . code , 0 ) ;
260- assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
261- assert . ok ( ! fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is still not a link
262- // But it still follows the link
263- assert . equal ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
234+ if ( process . platform !== 'win32' ) {
235+ // Recursive, everything exists, overwrite a real file with a link (if same name)
236+ // Because -R implies to not follow links!
237+ shell . rm ( '-rf' , 'tmp/*' ) ;
238+ shell . cp ( '-R' , 'resources/cp/*' , 'tmp' ) ;
239+ assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
240+ assert . ok ( ! ( fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ) ; // this one isn't
241+ assert . notEqual ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
242+ result = shell . cp ( '-R' , 'tmp/links/*' , 'tmp/fakeLinks' ) ;
243+ assert . equal ( shell . error ( ) , null ) ;
244+ assert . ok ( ! result . stderr ) ;
245+ assert . equal ( result . code , 0 ) ;
246+ assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
247+ assert . ok ( fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is now a link
248+ assert . equal ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
249+
250+ // Recursive, everything exists, overwrite a real file *by following a link*
251+ // Because missing the -R implies -L.
252+ shell . rm ( '-rf' , 'tmp/*' ) ;
253+ shell . cp ( '-R' , 'resources/cp/*' , 'tmp' ) ;
254+ assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
255+ assert . ok ( ! ( fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ) ; // this one isn't
256+ assert . notEqual ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
257+ result = shell . cp ( 'tmp/links/*' , 'tmp/fakeLinks' ) ; // don't use -R
258+ assert . equal ( shell . error ( ) , null ) ;
259+ assert . ok ( ! result . stderr ) ;
260+ assert . equal ( result . code , 0 ) ;
261+ assert . ok ( fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is a link
262+ assert . ok ( ! fs . lstatSync ( 'tmp/fakeLinks/sym.lnk' ) . isSymbolicLink ( ) ) ; // this one is still not a link
263+ // But it still follows the link
264+ assert . equal ( shell . cat ( 'tmp/links/sym.lnk' ) . toString ( ) , shell . cat ( 'tmp/fakeLinks/sym.lnk' ) . toString ( ) ) ;
265+ }
264266
265267//recursive, everything exists, with force flag
266268shell . rm ( '-rf' , 'tmp/*' ) ;
@@ -306,12 +308,12 @@ assert.equal(fs.existsSync('tmp/dest/z'), true);
306308
307309// On Windows, permission bits are quite different so skip those tests for now
308310if ( common . platform !== 'win' ) {
309- //preserve mode bits
310- shell . rm ( '-rf' , 'tmp/*' ) ;
311- var execBit = parseInt ( '001' , 8 ) ;
312- assert . equal ( fs . statSync ( 'resources/cp-mode-bits/executable' ) . mode & execBit , execBit ) ;
313- shell . cp ( 'resources/cp-mode-bits/executable' , 'tmp/executable' ) ;
314- assert . equal ( fs . statSync ( 'resources/cp-mode-bits/executable' ) . mode , fs . statSync ( 'tmp/executable' ) . mode ) ;
311+ //preserve mode bits
312+ shell . rm ( '-rf' , 'tmp/*' ) ;
313+ var execBit = parseInt ( '001' , 8 ) ;
314+ assert . equal ( fs . statSync ( 'resources/cp-mode-bits/executable' ) . mode & execBit , execBit ) ;
315+ shell . cp ( 'resources/cp-mode-bits/executable' , 'tmp/executable' ) ;
316+ assert . equal ( fs . statSync ( 'resources/cp-mode-bits/executable' ) . mode , fs . statSync ( 'tmp/executable' ) . mode ) ;
315317}
316318
317319// Make sure hidden files are copied recursively
@@ -335,7 +337,7 @@ assert.ok(fs.existsSync('tmp/file1.txt'));
335337shell . rm ( '-rf' , 'tmp/' ) ;
336338shell . mkdir ( 'tmp/' ) ;
337339result = shell . cp ( 'resources/file1.txt' , 'resources/file2.txt' , 'resources/cp' ,
338- 'resources/ls/' , 'tmp/' ) ;
340+ 'resources/ls/' , 'tmp/' ) ;
339341assert . ok ( shell . error ( ) ) ;
340342assert . ok ( ! fs . existsSync ( 'tmp/.hidden_file' ) ) ; // doesn't copy dir contents
341343assert . ok ( ! fs . existsSync ( 'tmp/ls' ) ) ; // doesn't copy dir itself
@@ -344,6 +346,36 @@ assert.ok(!fs.existsSync('tmp/cp')); // doesn't copy dir itself
344346assert . ok ( fs . existsSync ( 'tmp/file1.txt' ) ) ;
345347assert . ok ( fs . existsSync ( 'tmp/file2.txt' ) ) ;
346348
349+ if ( process . platform !== 'win32' ) {
350+ // -R implies -P
351+ shell . rm ( '-rf' , 'tmp/*' ) ;
352+ shell . cp ( '-R' , 'resources/cp/links/sym.lnk' , 'tmp' ) ;
353+ assert . ok ( fs . lstatSync ( 'tmp/sym.lnk' ) . isSymbolicLink ( ) ) ;
354+
355+ // using -P explicitly works
356+ shell . rm ( '-rf' , 'tmp/*' ) ;
357+ shell . cp ( '-P' , 'resources/cp/links/sym.lnk' , 'tmp' ) ;
358+ assert . ok ( fs . lstatSync ( 'tmp/sym.lnk' ) . isSymbolicLink ( ) ) ;
359+
360+ // using -PR on a link to a folder does not follow the link
361+ shell . rm ( '-rf' , 'tmp/*' ) ;
362+ shell . cp ( '-PR' , 'resources/cp/symFolder' , 'tmp' ) ;
363+ assert . ok ( fs . lstatSync ( 'tmp/symFolder' ) . isSymbolicLink ( ) ) ;
364+
365+ // Recursive, copies entire directory with no symlinks and -L option does not cause change in behavior.
366+ shell . rm ( '-rf' , 'tmp/*' ) ;
367+ result = shell . cp ( '-rL' , 'resources/cp/dir_a' , 'tmp/dest' ) ;
368+ assert . equal ( shell . error ( ) , null ) ;
369+ assert . ok ( ! result . stderr ) ;
370+ assert . equal ( result . code , 0 ) ;
371+ assert . equal ( fs . existsSync ( 'tmp/dest/z' ) , true ) ;
372+ }
373+
374+ // using -R on a link to a folder *does* follow the link
375+ shell . rm ( '-rf' , 'tmp/*' ) ;
376+ shell . cp ( '-R' , 'resources/cp/symFolder' , 'tmp' ) ;
377+ assert . ok ( ! fs . lstatSync ( 'tmp/symFolder' ) . isSymbolicLink ( ) ) ;
378+
347379// Without -R, -L is implied
348380shell . rm ( '-rf' , 'tmp/*' ) ;
349381shell . cp ( 'resources/cp/links/sym.lnk' , 'tmp' ) ;
@@ -359,39 +391,11 @@ shell.rm('-rf', 'tmp/*');
359391shell . cp ( '-LR' , 'resources/cp/links/sym.lnk' , 'tmp' ) ;
360392assert . ok ( ! fs . lstatSync ( 'tmp/sym.lnk' ) . isSymbolicLink ( ) ) ;
361393
362- // -R implies -P
363- shell . rm ( '-rf' , 'tmp/*' ) ;
364- shell . cp ( '-R' , 'resources/cp/links/sym.lnk' , 'tmp' ) ;
365- assert . ok ( fs . lstatSync ( 'tmp/sym.lnk' ) . isSymbolicLink ( ) ) ;
366-
367- // using -P explicitly works
368- shell . rm ( '-rf' , 'tmp/*' ) ;
369- shell . cp ( '-P' , 'resources/cp/links/sym.lnk' , 'tmp' ) ;
370- assert . ok ( fs . lstatSync ( 'tmp/sym.lnk' ) . isSymbolicLink ( ) ) ;
371-
372394// using -LR also works recursively on directories containing links
373395shell . rm ( '-rf' , 'tmp/*' ) ;
374396shell . cp ( '-LR' , 'resources/cp/links' , 'tmp' ) ;
375397assert . ok ( ! fs . lstatSync ( 'tmp/links/sym.lnk' ) . isSymbolicLink ( ) ) ;
376398
377- // using -PR on a link to a folder does not follow the link
378- shell . rm ( '-rf' , 'tmp/*' ) ;
379- shell . cp ( '-PR' , 'resources/cp/symFolder' , 'tmp' ) ;
380- assert . ok ( fs . lstatSync ( 'tmp/symFolder' ) . isSymbolicLink ( ) ) ;
381-
382- // using -R on a link to a folder *does* follow the link
383- shell . rm ( '-rf' , 'tmp/*' ) ;
384- shell . cp ( '-R' , 'resources/cp/symFolder' , 'tmp' ) ;
385- assert . ok ( ! fs . lstatSync ( 'tmp/symFolder' ) . isSymbolicLink ( ) ) ;
386-
387- // Recursive, copies entire directory with no symlinks and -L option does not cause change in behavior.
388- shell . rm ( '-rf' , 'tmp/*' ) ;
389- result = shell . cp ( '-rL' , 'resources/cp/dir_a' , 'tmp/dest' ) ;
390- assert . equal ( shell . error ( ) , null ) ;
391- assert . ok ( ! result . stderr ) ;
392- assert . equal ( result . code , 0 ) ;
393- assert . equal ( fs . existsSync ( 'tmp/dest/z' ) , true ) ;
394-
395399// Test max depth.
396400shell . rm ( '-rf' , 'tmp/' ) ;
397401shell . mkdir ( 'tmp/' ) ;
0 commit comments