Module

FileUtils

Includes:

fileutils.rb

Copyright © 2000-2006 Minero Aoki

This program is free software. You can distribute/modify this program under the same terms of ruby.

module FileUtils

Namespace for several file utility methods for copying, moving, removing, etc.

Module Functions

cd(dir, options)
cd(dir, options) {|dir| .... }
pwd()
mkdir(dir, options)
mkdir(list, options)
mkdir_p(dir, options)
mkdir_p(list, options)
rmdir(dir, options)
rmdir(list, options)
ln(old, new, options)
ln(list, destdir, options)
ln_s(old, new, options)
ln_s(list, destdir, options)
ln_sf(src, dest, options)
cp(src, dest, options)
cp(list, dir, options)
cp_r(src, dest, options)
cp_r(list, dir, options)
mv(src, dest, options)
mv(list, dir, options)
rm(list, options)
rm_r(list, options)
rm_rf(list, options)
install(src, dest, mode = <src's>, options)
chmod(mode, list, options)
chmod_R(mode, list, options)
chown(user, group, list, options)
chown_R(user, group, list, options)
touch(list, options)

The options parameter is a hash of options, taken from the list :force, :noop, :preserve, and :verbose. :noop means that no changes are made. The other two are obvious. Each method documents the options that it honours.

All methods that have the concept of a "source" file or directory can take either one file or a list of files in that argument. See the method documentation for examples.

There are some `low level’ methods, which do not accept any option:

copy_entry(src, dest, preserve = false, dereference = false)
copy_file(src, dest, preserve = false, dereference = true)
copy_stream(srcstream, deststream)
remove_entry(path, force = false)
remove_entry_secure(path, force = false)
remove_file(path, force = false)
compare_file(path_a, path_b)
compare_stream(stream_a, stream_b)
uptodate?(file, cmp_list)

module FileUtils::Verbose

This module has all methods of FileUtils module, but it outputs messages before acting. This equates to passing the :verbose flag to methods in FileUtils.

module FileUtils::NoWrite

This module has all methods of FileUtils module, but never changes files/directories. This equates to passing the :noop flag to methods in FileUtils.

module FileUtils::DryRun

This module has all methods of FileUtils module, but never changes files/directories. This equates to passing the :noop and :verbose flags to methods in FileUtils.

Modules
DryRun This module has all methods of FileUtils module, but never changes files/directories, with printing message before acting. This equates to passing the :noop and :verbose flag to methods in FileUtils.
NoWrite This module has all methods of FileUtils module, but never changes files/directories. This equates to passing the :noop flag to methods in FileUtils.
StreamUtils_
Verbose This module has all methods of FileUtils module, but it outputs messages before acting. This equates to passing the :verbose flag to methods in FileUtils.
Classes
Entry_
Constants
METHODS
OPT_TABLE This hash table holds command options.
Public Methods
cd Options: verbose
chdir Alias for #cd
chmod Options: noop verbose
chmod_R Options: noop verbose force
chown Options: noop verbose
chown_R Options: noop verbose force
cmp Alias for #compare_file
compare_file Returns true if the contents of a file A and a file B are identical.
compare_stream Returns true if the contents of a stream a and b are identical.
copy Alias for #cp
copy_entry Copies a file system entry src to dest. If src is a directory, this method copies its contents recursively. This method preserves file types, c.f. symlink, directory… (FIFO, device files and etc. are not supported yet)
copy_file Copies file contents of src to dest. Both of src and dest must be a path name.
copy_stream Copies stream src to dest. src must respond to #read(n) and dest must respond to #write(str).
cp Options: preserve noop verbose
cp_r Options: preserve noop verbose dereference_root remove_destination
fu_get_gid
fu_get_gid
fu_get_uid need Win32 support???
fu_get_uid
fu_have_symlink?
fu_mkdir
fu_stat_identical_entry?
fu_world_writable?
getwd Alias for #pwd
identical? Alias for #compare_file
install Options: mode preserve noop verbose
link Alias for #ln
ln Options: force noop verbose
ln_s Options: force noop verbose
ln_sf Options: noop verbose
makedirs Alias for #mkdir_p
mkdir Options: mode noop verbose
mkdir_p Options: mode noop verbose
mkpath Alias for #mkdir_p
move Alias for #mv
mv Options: force noop verbose
private_module_function
pwd Options: (none)
remove Alias for #rm
remove_dir Removes a directory dir and its contents recursively. This method ignores StandardError if force is true.
remove_entry This method removes a file system entry path. path might be a regular file, a directory, or something. If path is a directory, remove it recursively.
remove_entry_secure This method removes a file system entry path. path shall be a regular file, a directory, or something. If path is a directory, remove it recursively. This method is required to avoid TOCTTOU (time-of-check-to-time-of-use) local security vulnerability of #rm_r. #rm_r causes security hole when:
remove_file Removes a file path. This method ignores StandardError if force is true.
rename_cannot_overwrite_file?
rm Options: force noop verbose
rm_f Options: noop verbose
rm_r Options: force noop verbose secure
rm_rf Options: noop verbose secure
rmdir Options: noop, verbose
rmtree Alias for #rm_rf
safe_unlink Alias for #rm_f
symlink Alias for #ln_s
touch Options: noop verbose
uptodate? Options: (none)
Private Methods
collect_method Returns an Array of method names which have the option opt.
commands Returns an Array of method names which have any options.
fu_check_options
fu_each_src_dest
fu_each_src_dest0
fu_have_st_ino?
fu_list
fu_output_message
fu_same?
fu_update_option
have_option? Returns true if the method mid have an option opt.
options Returns an Array of option names.
options_of Returns an Array of option names of the method mid.
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.