@@ -357,6 +357,7 @@ def rmdir(list, parents: nil, noop: nil, verbose: nil)
357
357
end
358
358
module_function :rmdir
359
359
360
+ # Creates {hard links}[https://en.wikipedia.org/wiki/Hard_link].
360
361
#
361
362
# When +src+ is the path to an existing file
362
363
# and +dest+ is the path to a non-existent file,
@@ -369,7 +370,7 @@ def rmdir(list, parents: nil, noop: nil, verbose: nil)
369
370
#
370
371
# When +src+ is the path to an existing file
371
372
# and +dest+ is the path to an existing directory,
372
- # creates a hard link in + dest+ pointing to +src+; returns zero:
373
+ # creates a hard link at <tt> dest/src</tt> pointing to +src+; returns zero:
373
374
#
374
375
# Dir.children('tmp2') # => ["t.dat"]
375
376
# Dir.children('tmp3') # => []
@@ -379,7 +380,7 @@ def rmdir(list, parents: nil, noop: nil, verbose: nil)
379
380
# When +src+ is an array of paths to existing files
380
381
# and +dest+ is the path to an existing directory,
381
382
# then for each path +target+ in +src+,
382
- # creates a hard link in + dest+ pointing to +target+;
383
+ # creates a hard link at <tt> dest/target</tt> pointing to +target+;
383
384
# returns +src+:
384
385
#
385
386
# Dir.children('tmp4/') # => []
@@ -420,28 +421,75 @@ def ln(src, dest, force: nil, noop: nil, verbose: nil)
420
421
alias link ln
421
422
module_function :link
422
423
424
+ # Creates {hard links}[https://en.wikipedia.org/wiki/Hard_link].
425
+ #
426
+ # If +src+ is the path to a directory and +dest+ does not exist,
427
+ # creates links +dest+ and descendents pointing to +src+ and its descendents:
428
+ #
429
+ # Dir.glob('**/*.txt')
430
+ # # => ["tmp0/tmp2/t0.txt",
431
+ # "tmp0/tmp2/t1.txt",
432
+ # "tmp0/tmp3/t2.txt",
433
+ # "tmp0/tmp3/t3.txt"]
434
+ # FileUtils.cp_lr('tmp0', 'tmp1')
435
+ # Dir.glob('**/*.txt')
436
+ # # => ["tmp0/tmp2/t0.txt",
437
+ # "tmp0/tmp2/t1.txt",
438
+ # "tmp0/tmp3/t2.txt",
439
+ # "tmp0/tmp3/t3.txt",
440
+ # "tmp1/tmp2/t0.txt",
441
+ # "tmp1/tmp2/t1.txt",
442
+ # "tmp1/tmp3/t2.txt",
443
+ # "tmp1/tmp3/t3.txt"]
444
+ #
445
+ # If +src+ is an array of paths to files and +dest+ is the path to a directory,
446
+ # for each path +filepath+ in +src+, creates a link at <tt>dest/filepath</tt>
447
+ # pointing to that path:
448
+ #
449
+ # FileUtils.rm_r('tmp1')
450
+ # Dir.mkdir('tmp1')
451
+ # FileUtils.cp_lr(['tmp0/tmp3/t2.txt', 'tmp0/tmp3/t3.txt'], 'tmp1')
452
+ # Dir.glob('**/*.txt')
453
+ # # => ["tmp0/tmp2/t0.txt",
454
+ # "tmp0/tmp2/t1.txt",
455
+ # "tmp0/tmp3/t2.txt",
456
+ # "tmp0/tmp3/t3.txt",
457
+ # "tmp1/t2.txt",
458
+ # "tmp1/t3.txt"]
459
+ #
460
+ # If +src+ and +dest+ are both paths to directories,
461
+ # creates links <tt>dest/src</tt> and descendents
462
+ # pointing to +src+ and its descendents:
463
+ #
464
+ # FileUtils.rm_r('tmp1')
465
+ # Dir.mkdir('tmp1')
466
+ # FileUtils.cp_lr('tmp0', 'tmp1')
467
+ # # => ["tmp0/tmp2/t0.txt",
468
+ # "tmp0/tmp2/t1.txt",
469
+ # "tmp0/tmp3/t2.txt",
470
+ # "tmp0/tmp3/t3.txt",
471
+ # "tmp1/tmp0/tmp2/t0.txt",
472
+ # "tmp1/tmp0/tmp2/t1.txt",
473
+ # "tmp1/tmp0/tmp3/t2.txt",
474
+ # "tmp1/tmp0/tmp3/t3.txt"]
423
475
#
424
- # Hard link +src+ to +dest+. If +src+ is a directory, this method links
425
- # all its contents recursively. If +dest+ is a directory, links
426
- # +src+ to +dest/src+.
427
- #
428
- # +src+ can be a list of files.
476
+ # Keyword arguments:
429
477
#
430
- # If +dereference_root+ is true, this method dereference tree root.
478
+ # - <tt>dereference_root: false</tt> - does not follow soft links.
479
+ # - <tt>noop: true</tt> - does not create links.
480
+ # - <tt>remove_destination: true</tt> - removes +dest+ before creating links.
481
+ # - <tt>verbose: true</tt> - prints an equivalent command:
431
482
#
432
- # If +remove_destination+ is true, this method removes each destination file before copy.
483
+ # FileUtils.cp_lr('tmp0', 'tmp1', verbose: true, noop: true)
484
+ # FileUtils.cp_lr(['tmp0/tmp3/t2.txt', 'tmp0/tmp3/t3.txt'], 'tmp1', verbose: true, noop: true)
433
485
#
434
- # FileUtils.rm_r site_ruby + '/mylib', force: true
435
- # FileUtils.cp_lr 'lib/', site_ruby + '/mylib'
486
+ # Output:
436
487
#
437
- # # Examples of linking several files to target directory.
438
- # FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail'
439
- # FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', noop: true, verbose: true
488
+ # cp -lr tmp0 tmp1
489
+ # cp -lr tmp0/tmp3/t2.txt tmp0/tmp3/t3.txt tmp1
440
490
#
441
- # # If you want to link all contents of a directory instead of the
442
- # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
443
- # # use the following code.
444
- # FileUtils.cp_lr 'src/.', 'dest' # cp_lr('src', 'dest') makes dest/src, but this doesn't.
491
+ # Raises an exception if +dest+ is the path to an existing file
492
+ # and keyword argument +remove_destination+ is not +true+.
445
493
#
446
494
def cp_lr ( src , dest , noop : nil , verbose : nil ,
447
495
dereference_root : true , remove_destination : false )
0 commit comments