Skip to content
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] More on cp_r #87

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 additions & 19 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
alias copy cp
module_function :copy

# Recursively copies files from +src+ to +dest+.
# Recursively copies files from +src+ (a single path or an array of paths)
# to +dest+ (a single path).
#
# Arguments +src+ and +dest+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, I think we should specify here that src is a single or an array of paths and dest is a single path.

Copy link
Member Author

@BurdetteLamar BurdetteLamar Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what it says?

Recursively copies files from +src+ (a single path or an array of paths)
to +dest+ (a single path).

Maybe 820-824 should be rolled together?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for this method says:

Recursively copies files from +src+ (a single path or an array of paths)
to +dest+ (a single path).

Arguments +src+ and +dest+
should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].

Whereas, for example, the docs for ln_s says:

Creates {symbolic links}[https://en.wikipedia.org/wiki/Symbolic_link].

Arguments +src+ (a single path or an array of paths)
and +dest+ (a single path)
should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].

So yeah, perhaps we can remove duplication in the docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

# should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
Expand All @@ -841,31 +842,53 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
# 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')
# tree('src2')
# src2
# |-- dir0
# | |-- src0.txt
# | `-- src1.txt
# `-- dir1
# |-- src2.txt
# `-- src3.txt
# FileUtils.exist?('dest2') # => false
#
# 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
# tree('dest2')
# dest2
# |-- dir0
# | |-- src0.txt
# | `-- src1.txt
# `-- dir1
# |-- src2.txt
# `-- src3.txt
#
# 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')
# tree('src3')
# src3
# |-- dir0
# | |-- src0.txt
# | `-- src1.txt
# `-- dir1
# |-- src2.txt
# `-- 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
# tree('dest3')
# dest3
# `-- src3
# |-- dir0
# | |-- src0.txt
# | `-- src1.txt
# `-- dir1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line's indentation is off by one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

# |-- src2.txt
# `-- src3.txt
#
# If +src+ is an array of paths and +dest+ is a directory,
# recursively copies from each path in +src+ to +dest+;
# the paths in +src+ may point to files and/or directories.
#
# Keyword arguments:
#
Expand Down