-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DOC] Enhanced RDoc for ::cp_r #75
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -677,6 +677,8 @@ def link_entry(src, dest, dereference_root = false, remove_destination = false) | |
# | ||
# Raises an exception if +src+ is a directory. | ||
# | ||
# Related: FileUtils.cp_r (recursive). | ||
# | ||
# FileUtils.copy is an alias for FileUtils.cp. | ||
# | ||
def cp(src, dest, preserve: nil, noop: nil, verbose: nil) | ||
|
@@ -691,30 +693,79 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil) | |
alias copy cp | ||
module_function :copy | ||
|
||
# Copies files from +src+ to +dest+. | ||
# | ||
# Copies +src+ to +dest+. If +src+ is a directory, this method copies | ||
# all its contents recursively. If +dest+ is a directory, copies | ||
# +src+ to +dest/src+. | ||
# | ||
# +src+ can be a list of files. | ||
# If +src+ is the path to a file and +dest+ is not the path to a directory, | ||
# copies +src+ to +dest+: | ||
# | ||
# If +dereference_root+ is true, this method dereference tree root. | ||
# FileUtils.touch('src0.txt') | ||
# File.exist?('dest0.txt') # => false | ||
# FileUtils.cp_r('src0.txt', 'dest0.txt') | ||
# File.exist?('dest0.txt') # => true | ||
# | ||
# If +remove_destination+ is true, this method removes each destination file before copy. | ||
# If +src+ is the path to a file and +dest+ is the path to a directory, | ||
# copies +src+ to +dest+: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want |
||
# | ||
# FileUtils.touch('src1.txt') | ||
# FileUtils.mkdir('dest1') | ||
# FileUtils.cp_r('src1.txt', 'dest1') | ||
# File.exist?('dest1/src1.txt') # => true | ||
# | ||
# If +src+ is the path to a directory and +dest+ does not exist, | ||
# recursively copies +src+ to +dest+: | ||
# | ||
# FileUtils.mkdir_p(['src2/dir0', 'src2/dir1']) | ||
# FileUtils.touch('src2/dir0/src0.txt') | ||
# FileUtils.touch('src2/dir0/src1.txt') | ||
# FileUtils.touch('src2/dir1/src2.txt') | ||
# FileUtils.touch('src2/dir1/src3.txt') | ||
# FileUtils.cp_r('src2', 'dest2') | ||
# File.exist?('dest2/dir0/src0.txt') # => true | ||
# File.exist?('dest2/dir0/src1.txt') # => true | ||
# File.exist?('dest2/dir1/src2.txt') # => true | ||
# File.exist?('dest2/dir1/src3.txt') # => true | ||
# | ||
# If +src+ and +dest+ are paths to directories, | ||
# recursively copies +src+ to <tt>dest/src</tt>: | ||
# | ||
# FileUtils.mkdir_p(['src3/dir0', 'src3/dir1']) | ||
# FileUtils.touch('src3/dir0/src0.txt') | ||
# FileUtils.touch('src3/dir0/src1.txt') | ||
# FileUtils.touch('src3/dir1/src2.txt') | ||
# FileUtils.touch('src3/dir1/src3.txt') | ||
# FileUtils.mkdir('dest3') | ||
# FileUtils.cp_r('src3', 'dest3') | ||
# File.exist?('dest3/src3/dir0/src0.txt') # => true | ||
# File.exist?('dest3/src3/dir0/src1.txt') # => true | ||
# File.exist?('dest3/src3/dir1/src2.txt') # => true | ||
# File.exist?('dest3/src3/dir1/src3.txt') # => true | ||
# | ||
# Keyword arguments: | ||
# | ||
# - <tt>dereference_root: false</tt> - if +src+ is a symbolic link, | ||
# does not dereference it. | ||
# - <tt>noop: true</tt> - does not copy files. | ||
# - <tt>preserve</tt> - preserves file times. | ||
# - <tt>remove_destination: true</tt> - removes +dest+ before copying files. | ||
# - <tt>verbose: true</tt> - prints an equivalent command: | ||
# | ||
# FileUtils.cp_r('src0.txt', 'dest0.txt', noop: true, verbose: true) | ||
# FileUtils.cp_r('src1.txt', 'dest1', noop: true, verbose: true) | ||
# FileUtils.cp_r('src2', 'dest2', noop: true, verbose: true) | ||
# FileUtils.cp_r('src3', 'dest3', noop: true, verbose: true) | ||
# | ||
# Output: | ||
# | ||
# # Installing Ruby library "mylib" under the site_ruby | ||
# FileUtils.rm_r site_ruby + '/mylib', force: true | ||
# FileUtils.cp_r 'lib/', site_ruby + '/mylib' | ||
# cp -r src0.txt dest0.txt | ||
# cp -r src1.txt dest1 | ||
# cp -r src2 dest2 | ||
# cp -r src3 dest3 | ||
# | ||
# # Examples of copying several files to target directory. | ||
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail' | ||
# FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', noop: true, verbose: true | ||
# Raises an exception of +src+ is the path to a directory | ||
# and +dest+ is the path to a file. | ||
# | ||
# # If you want to copy all contents of a directory instead of the | ||
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y, | ||
# # use following code. | ||
# FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes dest/src, | ||
# # but this doesn't. | ||
# Related: FileUtils.cp (not recursive). | ||
# | ||
def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, | ||
dereference_root: true, remove_destination: nil) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should add recursively here, since that is how it differs from
cp
. If src is a file, I'd argue it still does a recursive copy, even if it is a trivial case.