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] Adding 'Related' #92

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Changes from all commits
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
48 changes: 43 additions & 5 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def self.private_module_function(name) #:nodoc:
#
# FileUtils.getwd is an alias for FileUtils.pwd.
#
# Related: FileUtils.cd.
#
def pwd
Dir.pwd
end
Expand Down Expand Up @@ -239,6 +241,8 @@ def pwd
#
# FileUtils.chdir is an alias for FileUtils.cd.
#
# Related: FileUtils.pwd.
#
def cd(dir, verbose: nil, &block) # :yield: dir
fu_output_message "cd #{dir}" if verbose
result = Dir.chdir(dir, &block)
Expand All @@ -263,6 +267,8 @@ def cd(dir, verbose: nil, &block) # :yield: dir
#
# A non-existent file is considered to be infinitely old.
#
# Related: FileUtils.touch.
#
def uptodate?(new, old_list)
return false unless File.exist?(new)
new_time = File.mtime(new)
Expand Down Expand Up @@ -313,6 +319,8 @@ def remove_trailing_slash(dir) #:nodoc:
# Raises an exception if any path points to an existing
# file or directory, or if for any reason a directory cannot be created.
#
# Related: FileUtils.mkdir_p.
#
def mkdir(list, mode: nil, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message "mkdir #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
Expand Down Expand Up @@ -360,6 +368,8 @@ def mkdir(list, mode: nil, noop: nil, verbose: nil)
#
# FileUtils.mkpath and FileUtils.makedirs are aliases for FileUtils.mkdir_p.
#
# Related: FileUtils.mkdir.
#
def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
Expand Down Expand Up @@ -511,6 +521,8 @@ def rmdir(list, parents: nil, noop: nil, verbose: nil)
#
# FileUtils#link is an alias for FileUtils#ln.
#
# Related: FileUtils.link_entry (has different options).
#
def ln(src, dest, force: nil, noop: nil, verbose: nil)
fu_output_message "ln#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose
return if noop
Expand Down Expand Up @@ -599,6 +611,8 @@ def ln(src, dest, force: nil, noop: nil, verbose: nil)
# Raises an exception if +dest+ is the path to an existing file or directory
# and keyword argument <tt>remove_destination: true</tt> is not given.
#
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def cp_lr(src, dest, noop: nil, verbose: nil,
dereference_root: true, remove_destination: false)
fu_output_message "cp -lr#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
Expand Down Expand Up @@ -677,6 +691,8 @@ def cp_lr(src, dest, noop: nil, verbose: nil,
#
# FileUtils.symlink is an alias for FileUtils.ln_s.
#
# Related: FileUtils.ln_sf.
#
def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose
return if noop
Expand Down Expand Up @@ -736,6 +752,8 @@ def ln_sf(src, dest, noop: nil, verbose: nil)
# Raises an exception if +dest+ is the path to an existing file or directory
# and keyword argument <tt>remove_destination: true</tt> is not given.
#
# Related: FileUtils.ln (has different options).
#
def link_entry(src, dest, dereference_root = false, remove_destination = false)
Entry_.new(src, nil, dereference_root).traverse do |ent|
destent = Entry_.new(dest, ent.rel, false)
Expand Down Expand Up @@ -795,10 +813,10 @@ 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.
#
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
fu_output_message "cp#{preserve ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if verbose
return if noop
Expand Down Expand Up @@ -908,7 +926,7 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
# Raises an exception of +src+ is the path to a directory
# and +dest+ is the path to a file.
#
# Related: FileUtils.cp (not recursive).
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
dereference_root: true, remove_destination: nil)
Expand Down Expand Up @@ -963,6 +981,8 @@ def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
# - <tt>preserve: true</tt> - preserves file times.
# - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
#
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
if dereference_root
src = File.realpath(src)
Expand Down Expand Up @@ -997,6 +1017,8 @@ def copy_entry(src, dest, preserve = false, dereference_root = false, remove_des
# - <tt>preserve: true</tt> - preserves file times.
# - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
#
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def copy_file(src, dest, preserve = false, dereference = true)
ent = Entry_.new(src, nil, dereference)
ent.copy_file dest
Expand All @@ -1007,6 +1029,8 @@ def copy_file(src, dest, preserve = false, dereference = true)
# Copies \IO stream +src+ to \IO stream +dest+ via
# {IO.copy_stream}[https://docs.ruby-lang.org/en/master/IO.html#method-c-copy_stream].
#
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def copy_stream(src, dest)
IO.copy_stream(src, dest)
end
Expand Down Expand Up @@ -1135,10 +1159,10 @@ def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
#
# rm src0.dat src0.txt
#
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
#
# FileUtils.remove is an alias for FileUtils.rm.
#
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
#
def rm(list, force: nil, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message "rm#{force ? ' -f' : ''} #{list.join ' '}" if verbose
Expand All @@ -1164,6 +1188,8 @@ def rm(list, force: nil, noop: nil, verbose: nil)
#
# FileUtils.safe_unlink is an alias for FileUtils.rm_f.
#
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
#
def rm_f(list, noop: nil, verbose: nil)
rm list, force: true, noop: noop, verbose: verbose
end
Expand Down Expand Up @@ -1430,6 +1456,8 @@ def remove_dir(path, force = false)
#
# FileUtils.identical? and FileUtils.cmp are aliases for FileUtils.compare_file.
#
# Related: FileUtils.compare_stream.
#
def compare_file(a, b)
return false unless File.size(a) == File.size(b)
File.open(a, 'rb') {|fa|
Expand All @@ -1451,6 +1479,8 @@ def compare_file(a, b)
# Arguments +a+ and +b+
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
#
# Related: FileUtils.compare_file.
#
def compare_stream(a, b)
bsize = fu_stream_blksize(a, b)

Expand Down Expand Up @@ -1528,6 +1558,8 @@ def compare_stream(a, b)
# install -c src1.txt dest1.txt
# install -c src2.txt dest2
#
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
#
def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil,
noop: nil, verbose: nil)
if verbose
Expand Down Expand Up @@ -1714,6 +1746,8 @@ def mode_to_s(mode) #:nodoc:
# chmod u=wrx,go=rx src1.txt
# chmod u=wrx,go=rx /usr/bin/ruby
#
# Related: FileUtils.chmod_R.
#
def chmod(mode, list, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message sprintf('chmod %s %s', mode_to_s(mode), list.join(' ')) if verbose
Expand Down Expand Up @@ -1805,6 +1839,8 @@ def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
# chown user2:group1 src0.txt
# chown user2:group1 .
#
# Related: FileUtils.chown_R.
#
def chown(user, group, list, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message sprintf('chown %s %s',
Expand Down Expand Up @@ -1913,6 +1949,8 @@ def fu_get_gid(group) #:nodoc:
# touch src0.txt src0.dat
# touch src0.txt
#
# Related: FileUtils.uptodate?.
#
def touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)
list = fu_list(list)
t = mtime
Expand Down