rbs 3.0.0.dev.2 → 3.0.0.dev.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- data/sig/shims/ripper.rbs +0 -8
@@ -1,100 +1,197 @@
|
|
1
1
|
# <!-- rdoc-file=lib/fileutils.rb -->
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
# ::
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
2
|
+
# Namespace for file utility methods for copying, moving, removing, etc.
|
3
|
+
#
|
4
|
+
# ## What's Here
|
5
|
+
#
|
6
|
+
# First, what’s elsewhere. Module FileUtils:
|
7
|
+
#
|
8
|
+
# * Inherits from [class Object](rdoc-ref:Object).
|
9
|
+
# * Supplements [class File](rdoc-ref:File) (but is not included or extended
|
10
|
+
# there).
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# Here, module FileUtils provides methods that are useful for:
|
14
|
+
#
|
15
|
+
# * [Creating](rdoc-ref:FileUtils@Creating).
|
16
|
+
# * [Deleting](rdoc-ref:FileUtils@Deleting).
|
17
|
+
# * [Querying](rdoc-ref:FileUtils@Querying).
|
18
|
+
# * [Setting](rdoc-ref:FileUtils@Setting).
|
19
|
+
# * [Comparing](rdoc-ref:FileUtils@Comparing).
|
20
|
+
# * [Copying](rdoc-ref:FileUtils@Copying).
|
21
|
+
# * [Moving](rdoc-ref:FileUtils@Moving).
|
22
|
+
# * [Options](rdoc-ref:FileUtils@Options).
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# ### Creating
|
26
|
+
#
|
27
|
+
# * ::mkdir: Creates directories.
|
28
|
+
# * ::mkdir_p, ::makedirs, ::mkpath: Creates directories, also creating
|
29
|
+
# ancestor directories as needed.
|
30
|
+
# * ::link_entry: Creates a hard link.
|
31
|
+
# * ::ln, ::link: Creates hard links.
|
32
|
+
# * ::ln_s, ::symlink: Creates symbolic links.
|
33
|
+
# * ::ln_sf: Creates symbolic links, overwriting if necessary.
|
34
|
+
# * ::ln_sr: Creates symbolic links relative to targets
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# ### Deleting
|
38
|
+
#
|
39
|
+
# * ::remove_dir: Removes a directory and its descendants.
|
40
|
+
# * ::remove_entry: Removes an entry, including its descendants if it is a
|
41
|
+
# directory.
|
42
|
+
# * ::remove_entry_secure: Like ::remove_entry, but removes securely.
|
43
|
+
# * ::remove_file: Removes a file entry.
|
44
|
+
# * ::rm, ::remove: Removes entries.
|
45
|
+
# * ::rm_f, ::safe_unlink: Like ::rm, but removes forcibly.
|
46
|
+
# * ::rm_r: Removes entries and their descendants.
|
47
|
+
# * ::rm_rf, ::rmtree: Like ::rm_r, but removes forcibly.
|
48
|
+
# * ::rmdir: Removes directories.
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# ### Querying
|
52
|
+
#
|
53
|
+
# * ::pwd, ::getwd: Returns the path to the working directory.
|
54
|
+
# * ::uptodate?: Returns whether a given entry is newer than given other
|
55
|
+
# entries.
|
56
|
+
#
|
57
|
+
#
|
58
|
+
# ### Setting
|
59
|
+
#
|
60
|
+
# * ::cd, ::chdir: Sets the working directory.
|
61
|
+
# * ::chmod: Sets permissions for an entry.
|
62
|
+
# * ::chmod_R: Sets permissions for an entry and its descendants.
|
63
|
+
# * ::chown: Sets the owner and group for entries.
|
64
|
+
# * ::chown_R: Sets the owner and group for entries and their descendants.
|
65
|
+
# * ::touch: Sets modification and access times for entries, creating if
|
66
|
+
# necessary.
|
67
|
+
#
|
68
|
+
#
|
69
|
+
# ### Comparing
|
70
|
+
#
|
71
|
+
# * ::compare_file, ::cmp, ::identical?: Returns whether two entries are
|
72
|
+
# identical.
|
73
|
+
# * ::compare_stream: Returns whether two streams are identical.
|
74
|
+
#
|
75
|
+
#
|
76
|
+
# ### Copying
|
77
|
+
#
|
78
|
+
# * ::copy_entry: Recursively copies an entry.
|
79
|
+
# * ::copy_file: Copies an entry.
|
80
|
+
# * ::copy_stream: Copies a stream.
|
81
|
+
# * ::cp, ::copy: Copies files.
|
82
|
+
# * ::cp_lr: Recursively creates hard links.
|
83
|
+
# * ::cp_r: Recursively copies files, retaining mode, owner, and group.
|
84
|
+
# * ::install: Recursively copies files, optionally setting mode, owner, and
|
85
|
+
# group.
|
86
|
+
#
|
87
|
+
#
|
88
|
+
# ### Moving
|
89
|
+
#
|
90
|
+
# * ::mv, ::move: Moves entries.
|
91
|
+
#
|
92
|
+
#
|
93
|
+
# ### Options
|
94
|
+
#
|
95
|
+
# * ::collect_method: Returns the names of methods that accept a given option.
|
96
|
+
# * ::commands: Returns the names of methods that accept options.
|
97
|
+
# * ::have_option?: Returns whether a given method accepts a given option.
|
98
|
+
# * ::options: Returns all option names.
|
99
|
+
# * ::options_of: Returns the names of the options for a given method.
|
100
|
+
#
|
101
|
+
#
|
102
|
+
# ## Path Arguments
|
103
|
+
#
|
104
|
+
# Some methods in FileUtils accept *path* arguments, which are interpreted as
|
105
|
+
# paths to filesystem entries:
|
106
|
+
#
|
107
|
+
# * If the argument is a string, that value is the path.
|
108
|
+
# * If the argument has method `:to_path`, it is converted via that method.
|
109
|
+
# * If the argument has method `:to_str`, it is converted via that method.
|
110
|
+
#
|
111
|
+
#
|
112
|
+
# ## About the Examples
|
113
|
+
#
|
114
|
+
# Some examples here involve trees of file entries. For these, we sometimes
|
115
|
+
# display trees using the [tree command-line
|
116
|
+
# utility](https://en.wikipedia.org/wiki/Tree_(command)), which is a recursive
|
117
|
+
# directory-listing utility that produces a depth-indented listing of files and
|
118
|
+
# directories.
|
119
|
+
#
|
120
|
+
# We use a helper method to launch the command and control the format:
|
121
|
+
#
|
122
|
+
# def tree(dirpath = '.')
|
123
|
+
# command = "tree --noreport --charset=ascii #{dirpath}"
|
124
|
+
# system(command)
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
# To illustrate:
|
128
|
+
#
|
129
|
+
# tree('src0')
|
130
|
+
# # => src0
|
131
|
+
# # |-- sub0
|
132
|
+
# # | |-- src0.txt
|
133
|
+
# # | `-- src1.txt
|
134
|
+
# # `-- sub1
|
135
|
+
# # |-- src2.txt
|
136
|
+
# # `-- src3.txt
|
137
|
+
#
|
138
|
+
# ## Avoiding the TOCTTOU Vulnerability
|
139
|
+
#
|
140
|
+
# For certain methods that recursively remove entries, there is a potential
|
141
|
+
# vulnerability called the [Time-of-check to
|
142
|
+
# time-of-use](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use), or
|
143
|
+
# TOCTTOU, vulnerability that can exist when:
|
144
|
+
#
|
145
|
+
# * An ancestor directory of the entry at the target path is world writable;
|
146
|
+
# such directories include `/tmp`.
|
147
|
+
# * The directory tree at the target path includes:
|
148
|
+
#
|
149
|
+
# * A world-writable descendant directory.
|
150
|
+
# * A symbolic link.
|
151
|
+
#
|
152
|
+
#
|
153
|
+
#
|
154
|
+
# To avoid that vulnerability, you can use this method to remove entries:
|
155
|
+
#
|
156
|
+
# * FileUtils.remove_entry_secure: removes recursively if the target path
|
157
|
+
# points to a directory.
|
158
|
+
#
|
159
|
+
#
|
160
|
+
# Also available are these methods, each of which calls
|
161
|
+
# FileUtils.remove_entry_secure:
|
162
|
+
#
|
163
|
+
# * FileUtils.rm_r with keyword argument `secure: true`.
|
164
|
+
# * FileUtils.rm_rf with keyword argument `secure: true`.
|
165
|
+
#
|
166
|
+
#
|
167
|
+
# Finally, this method for moving entries calls FileUtils.remove_entry_secure if
|
168
|
+
# the source and destination are on different file systems (which means that the
|
169
|
+
# "move" is really a copy and remove):
|
170
|
+
#
|
171
|
+
# * FileUtils.mv with keyword argument `secure: true`.
|
172
|
+
#
|
173
|
+
#
|
174
|
+
# Method FileUtils.remove_entry_secure removes securely by applying a special
|
175
|
+
# pre-process:
|
176
|
+
#
|
177
|
+
# * If the target path points to a directory, this method uses methods
|
178
|
+
# [File#chown](rdoc-ref:File#chown) and [File#chmod](rdoc-ref:File#chmod) in
|
179
|
+
# removing directories.
|
180
|
+
# * The owner of the target directory should be either the current process or
|
181
|
+
# the super user (root).
|
182
|
+
#
|
183
|
+
#
|
184
|
+
# WARNING: You must ensure that **ALL** parent directories cannot be moved by
|
185
|
+
# other untrusted users. For example, parent directories should not be owned by
|
186
|
+
# untrusted users, and should not be world writable except when the sticky bit
|
187
|
+
# is set.
|
188
|
+
#
|
189
|
+
# For details of this security vulnerability, see Perl cases:
|
190
|
+
#
|
191
|
+
# * [CVE-2005-0448](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-04
|
192
|
+
# 48).
|
193
|
+
# * [CVE-2004-0452](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-04
|
194
|
+
# 52).
|
98
195
|
#
|
99
196
|
module FileUtils
|
100
197
|
VERSION: String
|
@@ -109,18 +206,41 @@ module FileUtils
|
|
109
206
|
# rdoc-file=lib/fileutils.rb
|
110
207
|
# - cd(dir, verbose: nil) { |dir| ... }
|
111
208
|
# -->
|
112
|
-
# Changes the
|
209
|
+
# Changes the working directory to the given `dir`, which should be
|
210
|
+
# [interpretable as a path](rdoc-ref:FileUtils@Path+Arguments):
|
211
|
+
#
|
212
|
+
# With no block given, changes the current directory to the directory at `dir`;
|
213
|
+
# returns zero:
|
214
|
+
#
|
215
|
+
# FileUtils.pwd # => "/rdoc/fileutils"
|
216
|
+
# FileUtils.cd('..')
|
217
|
+
# FileUtils.pwd # => "/rdoc"
|
218
|
+
# FileUtils.cd('fileutils')
|
219
|
+
#
|
220
|
+
# With a block given, changes the current directory to the directory at `dir`,
|
221
|
+
# calls the block with argument `dir`, and restores the original current
|
222
|
+
# directory; returns the block's value:
|
223
|
+
#
|
224
|
+
# FileUtils.pwd # => "/rdoc/fileutils"
|
225
|
+
# FileUtils.cd('..') { |arg| [arg, FileUtils.pwd] } # => ["..", "/rdoc"]
|
226
|
+
# FileUtils.pwd # => "/rdoc/fileutils"
|
227
|
+
#
|
228
|
+
# Keyword arguments:
|
229
|
+
#
|
230
|
+
# * `verbose: true` - prints an equivalent command:
|
231
|
+
#
|
232
|
+
# FileUtils.cd('..')
|
233
|
+
# FileUtils.cd('fileutils')
|
234
|
+
#
|
235
|
+
# Output:
|
113
236
|
#
|
114
|
-
#
|
115
|
-
#
|
237
|
+
# cd ..
|
238
|
+
# cd fileutils
|
116
239
|
#
|
117
|
-
# FileUtils.cd('/') # change directory
|
118
240
|
#
|
119
|
-
#
|
241
|
+
# FileUtils.chdir is an alias for FileUtils.cd.
|
120
242
|
#
|
121
|
-
#
|
122
|
-
# # ... # do something
|
123
|
-
# end # return to original directory
|
243
|
+
# Related: FileUtils.pwd.
|
124
244
|
#
|
125
245
|
def self?.cd: (path dir, ?verbose: boolish) -> void
|
126
246
|
| [X] (path dir, ?verbose: boolish) { (String) -> X } -> X
|
@@ -143,48 +263,82 @@ module FileUtils
|
|
143
263
|
# rdoc-file=lib/fileutils.rb
|
144
264
|
# - chmod(mode, list, noop: nil, verbose: nil)
|
145
265
|
# -->
|
146
|
-
# Changes
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
266
|
+
# Changes permissions on the entries at the paths given in `list` (a single path
|
267
|
+
# or an array of paths) to the permissions given by `mode`; returns `list` if it
|
268
|
+
# is an array, `[list]` otherwise:
|
269
|
+
#
|
270
|
+
# * Modifies each entry that is a regular file using
|
271
|
+
# [File.chmod](rdoc-ref:File.chmod).
|
272
|
+
# * Modifies each entry that is a symbolic link using
|
273
|
+
# [File.lchmod](rdoc-ref:File.lchmod).
|
274
|
+
#
|
275
|
+
#
|
276
|
+
# Argument `list` or its elements should be [interpretable as
|
277
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
278
|
+
#
|
279
|
+
# Argument `mode` may be either an integer or a string:
|
280
|
+
#
|
281
|
+
# * Integer `mode`: represents the permission bits to be set:
|
282
|
+
#
|
283
|
+
# FileUtils.chmod(0755, 'src0.txt')
|
284
|
+
# FileUtils.chmod(0644, ['src0.txt', 'src0.dat'])
|
285
|
+
#
|
286
|
+
# * String `mode`: represents the permissions to be set:
|
287
|
+
#
|
288
|
+
# The string is of the form `[targets][[operator][perms[,perms]]`, where:
|
289
|
+
#
|
290
|
+
# * `targets` may be any combination of these letters:
|
291
|
+
#
|
292
|
+
# * `'u'`: permissions apply to the file's owner.
|
293
|
+
# * `'g'`: permissions apply to users in the file's group.
|
294
|
+
# * `'o'`: permissions apply to other users not in the file's group.
|
295
|
+
# * `'a'` (the default): permissions apply to all users.
|
296
|
+
#
|
297
|
+
#
|
298
|
+
# * `operator` may be one of these letters:
|
299
|
+
#
|
300
|
+
# * `'+'`: adds permissions.
|
301
|
+
# * `'-'`: removes permissions.
|
302
|
+
# * `'='`: sets (replaces) permissions.
|
303
|
+
#
|
304
|
+
#
|
305
|
+
# * `perms` (may be repeated, with separating commas) may be any
|
306
|
+
# combination of these letters:
|
307
|
+
#
|
308
|
+
# * `'r'`: Read.
|
309
|
+
# * `'w'`: Write.
|
310
|
+
# * `'x'`: Execute (search, for a directory).
|
311
|
+
# * `'X'`: Search (for a directories only; must be used with `'+'`)
|
312
|
+
# * `'s'`: Uid or gid.
|
313
|
+
# * `'t'`: Sticky bit.
|
314
|
+
#
|
315
|
+
#
|
316
|
+
#
|
317
|
+
# Examples:
|
318
|
+
#
|
319
|
+
# FileUtils.chmod('u=wrx,go=rx', 'src1.txt')
|
320
|
+
# FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby')
|
321
|
+
#
|
322
|
+
#
|
323
|
+
# Keyword arguments:
|
324
|
+
#
|
325
|
+
# * `noop: true` - does not change permissions; returns `nil`.
|
326
|
+
# * `verbose: true` - prints an equivalent command:
|
327
|
+
#
|
328
|
+
# FileUtils.chmod(0755, 'src0.txt', noop: true, verbose: true)
|
329
|
+
# FileUtils.chmod(0644, ['src0.txt', 'src0.dat'], noop: true, verbose: true)
|
330
|
+
# FileUtils.chmod('u=wrx,go=rx', 'src1.txt', noop: true, verbose: true)
|
331
|
+
# FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby', noop: true, verbose: true)
|
332
|
+
#
|
333
|
+
# Output:
|
334
|
+
#
|
335
|
+
# chmod 755 src0.txt
|
336
|
+
# chmod 644 src0.txt src0.dat
|
337
|
+
# chmod u=wrx,go=rx src1.txt
|
338
|
+
# chmod u=wrx,go=rx /usr/bin/ruby
|
339
|
+
#
|
340
|
+
#
|
341
|
+
# Related: FileUtils.chmod_R.
|
188
342
|
#
|
189
343
|
def self?.chmod: (mode mode, pathlist list, ?noop: boolish, ?verbose: boolish) -> void
|
190
344
|
|
@@ -192,11 +346,7 @@ module FileUtils
|
|
192
346
|
# rdoc-file=lib/fileutils.rb
|
193
347
|
# - chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
|
194
348
|
# -->
|
195
|
-
#
|
196
|
-
# represented by `mode`.
|
197
|
-
#
|
198
|
-
# FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
|
199
|
-
# FileUtils.chmod_R "u=wrx", "/tmp/app.#{$$}"
|
349
|
+
# Like FileUtils.chmod, but changes permissions recursively.
|
200
350
|
#
|
201
351
|
def self?.chmod_R: (mode mode, pathlist list, ?noop: boolish, ?verbose: boolish, ?force: boolish) -> void
|
202
352
|
|
@@ -204,13 +354,70 @@ module FileUtils
|
|
204
354
|
# rdoc-file=lib/fileutils.rb
|
205
355
|
# - chown(user, group, list, noop: nil, verbose: nil)
|
206
356
|
# -->
|
207
|
-
# Changes owner and group on the
|
208
|
-
# the
|
209
|
-
#
|
210
|
-
# attribute.
|
357
|
+
# Changes the owner and group on the entries at the paths given in `list` (a
|
358
|
+
# single path or an array of paths) to the given `user` and `group`; returns
|
359
|
+
# `list` if it is an array, `[list]` otherwise:
|
211
360
|
#
|
212
|
-
#
|
213
|
-
#
|
361
|
+
# * Modifies each entry that is a regular file using
|
362
|
+
# [File.chown](rdoc-ref:File.chown).
|
363
|
+
# * Modifies each entry that is a symbolic link using
|
364
|
+
# [File.lchown](rdoc-ref:File.lchown).
|
365
|
+
#
|
366
|
+
#
|
367
|
+
# Argument `list` or its elements should be [interpretable as
|
368
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
369
|
+
#
|
370
|
+
# User and group:
|
371
|
+
#
|
372
|
+
# * Argument `user` may be a user name or a user id; if `nil` or `-1`, the
|
373
|
+
# user is not changed.
|
374
|
+
# * Argument `group` may be a group name or a group id; if `nil` or `-1`, the
|
375
|
+
# group is not changed.
|
376
|
+
# * The user must be a member of the group.
|
377
|
+
#
|
378
|
+
#
|
379
|
+
# Examples:
|
380
|
+
#
|
381
|
+
# # One path.
|
382
|
+
# # User and group as string names.
|
383
|
+
# File.stat('src0.txt').uid # => 1004
|
384
|
+
# File.stat('src0.txt').gid # => 1004
|
385
|
+
# FileUtils.chown('user2', 'group1', 'src0.txt')
|
386
|
+
# File.stat('src0.txt').uid # => 1006
|
387
|
+
# File.stat('src0.txt').gid # => 1005
|
388
|
+
#
|
389
|
+
# # User and group as uid and gid.
|
390
|
+
# FileUtils.chown(1004, 1004, 'src0.txt')
|
391
|
+
# File.stat('src0.txt').uid # => 1004
|
392
|
+
# File.stat('src0.txt').gid # => 1004
|
393
|
+
#
|
394
|
+
# # Array of paths.
|
395
|
+
# FileUtils.chown(1006, 1005, ['src0.txt', 'src0.dat'])
|
396
|
+
#
|
397
|
+
# # Directory (not recursive).
|
398
|
+
# FileUtils.chown('user2', 'group1', '.')
|
399
|
+
#
|
400
|
+
# Keyword arguments:
|
401
|
+
#
|
402
|
+
# * `noop: true` - does not change permissions; returns `nil`.
|
403
|
+
# * `verbose: true` - prints an equivalent command:
|
404
|
+
#
|
405
|
+
# FileUtils.chown('user2', 'group1', 'src0.txt', noop: true, verbose: true)
|
406
|
+
# FileUtils.chown(1004, 1004, 'src0.txt', noop: true, verbose: true)
|
407
|
+
# FileUtils.chown(1006, 1005, ['src0.txt', 'src0.dat'], noop: true, verbose: true)
|
408
|
+
# FileUtils.chown('user2', 'group1', path, noop: true, verbose: true)
|
409
|
+
# FileUtils.chown('user2', 'group1', '.', noop: true, verbose: true)
|
410
|
+
#
|
411
|
+
# Output:
|
412
|
+
#
|
413
|
+
# chown user2:group1 src0.txt
|
414
|
+
# chown 1004:1004 src0.txt
|
415
|
+
# chown 1006:1005 src0.txt src0.dat
|
416
|
+
# chown user2:group1 src0.txt
|
417
|
+
# chown user2:group1 .
|
418
|
+
#
|
419
|
+
#
|
420
|
+
# Related: FileUtils.chown_R.
|
214
421
|
#
|
215
422
|
def self?.chown: (String? user, String? group, pathlist list, ?noop: boolish, ?verbose: boolish) -> void
|
216
423
|
|
@@ -218,13 +425,7 @@ module FileUtils
|
|
218
425
|
# rdoc-file=lib/fileutils.rb
|
219
426
|
# - chown_R(user, group, list, noop: nil, verbose: nil, force: nil)
|
220
427
|
# -->
|
221
|
-
#
|
222
|
-
# the group `group` recursively. `user` and `group` may be an ID
|
223
|
-
# (Integer/String) or a name (String). If `user` or `group` is nil, this method
|
224
|
-
# does not change the attribute.
|
225
|
-
#
|
226
|
-
# FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
|
227
|
-
# FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', verbose: true
|
428
|
+
# Like FileUtils.chown, but changes owner and group recursively.
|
228
429
|
#
|
229
430
|
def self?.chown_R: (String? user, String? group, pathlist list, ?noop: boolish, ?verbose: boolish, ?force: boolish) -> void
|
230
431
|
|
@@ -232,9 +433,10 @@ module FileUtils
|
|
232
433
|
# rdoc-file=lib/fileutils.rb
|
233
434
|
# - collect_method(opt)
|
234
435
|
# -->
|
235
|
-
# Returns an
|
436
|
+
# Returns an array of the string method names of the methods that accept the
|
437
|
+
# given keyword option `opt`; the argument must be a symbol:
|
236
438
|
#
|
237
|
-
#
|
439
|
+
# FileUtils.collect_method(:preserve) # => ["cp", "copy", "cp_r", "install"]
|
238
440
|
#
|
239
441
|
def self.collect_method: (Symbol opt) -> Array[String]
|
240
442
|
|
@@ -242,10 +444,10 @@ module FileUtils
|
|
242
444
|
# rdoc-file=lib/fileutils.rb
|
243
445
|
# - commands()
|
244
446
|
# -->
|
245
|
-
# Returns an
|
246
|
-
# arguments
|
447
|
+
# Returns an array of the string names of FileUtils methods that accept one or
|
448
|
+
# more keyword arguments:
|
247
449
|
#
|
248
|
-
#
|
450
|
+
# FileUtils.commands.sort.take(3) # => ["cd", "chdir", "chmod"]
|
249
451
|
#
|
250
452
|
def self.commands: () -> Array[String]
|
251
453
|
|
@@ -253,10 +455,15 @@ module FileUtils
|
|
253
455
|
# rdoc-file=lib/fileutils.rb
|
254
456
|
# - compare_file(a, b)
|
255
457
|
# -->
|
256
|
-
# Returns true if the contents of
|
458
|
+
# Returns `true` if the contents of files `a` and `b` are identical, `false`
|
459
|
+
# otherwise.
|
460
|
+
#
|
461
|
+
# Arguments `a` and `b` should be [interpretable as a
|
462
|
+
# path](rdoc-ref:FileUtils@Path+Arguments).
|
463
|
+
#
|
464
|
+
# FileUtils.identical? and FileUtils.cmp are aliases for FileUtils.compare_file.
|
257
465
|
#
|
258
|
-
#
|
259
|
-
# FileUtils.compare_file('/dev/null', '/dev/urandom') #=> false
|
466
|
+
# Related: FileUtils.compare_stream.
|
260
467
|
#
|
261
468
|
def self?.compare_file: (path a, path b) -> bool
|
262
469
|
|
@@ -292,7 +499,13 @@ module FileUtils
|
|
292
499
|
# rdoc-file=lib/fileutils.rb
|
293
500
|
# - compare_stream(a, b)
|
294
501
|
# -->
|
295
|
-
# Returns true if the contents of
|
502
|
+
# Returns `true` if the contents of streams `a` and `b` are identical, `false`
|
503
|
+
# otherwise.
|
504
|
+
#
|
505
|
+
# Arguments `a` and `b` should be [interpretable as a
|
506
|
+
# path](rdoc-ref:FileUtils@Path+Arguments).
|
507
|
+
#
|
508
|
+
# Related: FileUtils.compare_file.
|
296
509
|
#
|
297
510
|
def self?.compare_stream: (IO a, IO b) -> bool
|
298
511
|
|
@@ -300,20 +513,50 @@ module FileUtils
|
|
300
513
|
# rdoc-file=lib/fileutils.rb
|
301
514
|
# - copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
|
302
515
|
# -->
|
303
|
-
#
|
304
|
-
#
|
305
|
-
#
|
516
|
+
# Recursively copies files from `src` to `dest`.
|
517
|
+
#
|
518
|
+
# Arguments `src` and `dest` should be [interpretable as
|
519
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
520
|
+
#
|
521
|
+
# If `src` is the path to a file, copies `src` to `dest`:
|
522
|
+
#
|
523
|
+
# FileUtils.touch('src0.txt')
|
524
|
+
# File.exist?('dest0.txt') # => false
|
525
|
+
# FileUtils.copy_entry('src0.txt', 'dest0.txt')
|
526
|
+
# File.file?('dest0.txt') # => true
|
306
527
|
#
|
307
|
-
#
|
308
|
-
# not exist.
|
528
|
+
# If `src` is a directory, recursively copies `src` to `dest`:
|
309
529
|
#
|
310
|
-
#
|
311
|
-
#
|
530
|
+
# tree('src1')
|
531
|
+
# # => src1
|
532
|
+
# # |-- dir0
|
533
|
+
# # | |-- src0.txt
|
534
|
+
# # | `-- src1.txt
|
535
|
+
# # `-- dir1
|
536
|
+
# # |-- src2.txt
|
537
|
+
# # `-- src3.txt
|
538
|
+
# FileUtils.copy_entry('src1', 'dest1')
|
539
|
+
# tree('dest1')
|
540
|
+
# # => dest1
|
541
|
+
# # |-- dir0
|
542
|
+
# # | |-- src0.txt
|
543
|
+
# # | `-- src1.txt
|
544
|
+
# # `-- dir1
|
545
|
+
# # |-- src2.txt
|
546
|
+
# # `-- src3.txt
|
312
547
|
#
|
313
|
-
#
|
548
|
+
# The recursive copying preserves file types for regular files, directories, and
|
549
|
+
# symbolic links; other file types (FIFO streams, device files, etc.) are not
|
550
|
+
# supported.
|
314
551
|
#
|
315
|
-
#
|
316
|
-
#
|
552
|
+
# Keyword arguments:
|
553
|
+
#
|
554
|
+
# * `dereference_root: true` - if `src` is a symbolic link, follows the link.
|
555
|
+
# * `preserve: true` - preserves file times.
|
556
|
+
# * `remove_destination: true` - removes `dest` before copying files.
|
557
|
+
#
|
558
|
+
#
|
559
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
317
560
|
#
|
318
561
|
def self?.copy_entry: (path src, path dest, ?boolish preserve, ?boolish dereference_root, ?boolish remove_destination) -> void
|
319
562
|
|
@@ -321,8 +564,26 @@ module FileUtils
|
|
321
564
|
# rdoc-file=lib/fileutils.rb
|
322
565
|
# - copy_file(src, dest, preserve = false, dereference = true)
|
323
566
|
# -->
|
324
|
-
# Copies file
|
325
|
-
#
|
567
|
+
# Copies file from `src` to `dest`, which should not be directories.
|
568
|
+
#
|
569
|
+
# Arguments `src` and `dest` should be [interpretable as
|
570
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
571
|
+
#
|
572
|
+
# Examples:
|
573
|
+
#
|
574
|
+
# FileUtils.touch('src0.txt')
|
575
|
+
# FileUtils.copy_file('src0.txt', 'dest0.txt')
|
576
|
+
# File.file?('dest0.txt') # => true
|
577
|
+
#
|
578
|
+
# Keyword arguments:
|
579
|
+
#
|
580
|
+
# * `dereference: false` - if `src` is a symbolic link, does not follow the
|
581
|
+
# link.
|
582
|
+
# * `preserve: true` - preserves file times.
|
583
|
+
# * `remove_destination: true` - removes `dest` before copying files.
|
584
|
+
#
|
585
|
+
#
|
586
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
326
587
|
#
|
327
588
|
def self?.copy_file: (path src, path dest, ?boolish preserve, ?boolish dereference) -> void
|
328
589
|
|
@@ -330,8 +591,10 @@ module FileUtils
|
|
330
591
|
# rdoc-file=lib/fileutils.rb
|
331
592
|
# - copy_stream(src, dest)
|
332
593
|
# -->
|
333
|
-
# Copies stream `src` to
|
334
|
-
#
|
594
|
+
# Copies IO stream `src` to IO stream `dest` via
|
595
|
+
# [IO.copy_stream](rdoc-ref:IO.copy_stream).
|
596
|
+
#
|
597
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
335
598
|
#
|
336
599
|
def self?.copy_stream: (_Reader src, _Writer dest) -> void
|
337
600
|
|
@@ -339,15 +602,59 @@ module FileUtils
|
|
339
602
|
# rdoc-file=lib/fileutils.rb
|
340
603
|
# - cp(src, dest, preserve: nil, noop: nil, verbose: nil)
|
341
604
|
# -->
|
342
|
-
# Copies
|
343
|
-
#
|
605
|
+
# Copies files.
|
606
|
+
#
|
607
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
608
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments).
|
609
|
+
#
|
610
|
+
# If `src` is the path to a file and `dest` is not the path to a directory,
|
611
|
+
# copies `src` to `dest`:
|
612
|
+
#
|
613
|
+
# FileUtils.touch('src0.txt')
|
614
|
+
# File.exist?('dest0.txt') # => false
|
615
|
+
# FileUtils.cp('src0.txt', 'dest0.txt')
|
616
|
+
# File.file?('dest0.txt') # => true
|
617
|
+
#
|
618
|
+
# If `src` is the path to a file and `dest` is the path to a directory, copies
|
619
|
+
# `src` to `dest/src`:
|
344
620
|
#
|
345
|
-
#
|
621
|
+
# FileUtils.touch('src1.txt')
|
622
|
+
# FileUtils.mkdir('dest1')
|
623
|
+
# FileUtils.cp('src1.txt', 'dest1')
|
624
|
+
# File.file?('dest1/src1.txt') # => true
|
346
625
|
#
|
347
|
-
#
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
626
|
+
# If `src` is an array of paths to files and `dest` is the path to a directory,
|
627
|
+
# copies from each `src` to `dest`:
|
628
|
+
#
|
629
|
+
# src_file_paths = ['src2.txt', 'src2.dat']
|
630
|
+
# FileUtils.touch(src_file_paths)
|
631
|
+
# FileUtils.mkdir('dest2')
|
632
|
+
# FileUtils.cp(src_file_paths, 'dest2')
|
633
|
+
# File.file?('dest2/src2.txt') # => true
|
634
|
+
# File.file?('dest2/src2.dat') # => true
|
635
|
+
#
|
636
|
+
# Keyword arguments:
|
637
|
+
#
|
638
|
+
# * `preserve: true` - preserves file times.
|
639
|
+
# * `noop: true` - does not copy files.
|
640
|
+
# * `verbose: true` - prints an equivalent command:
|
641
|
+
#
|
642
|
+
# FileUtils.cp('src0.txt', 'dest0.txt', noop: true, verbose: true)
|
643
|
+
# FileUtils.cp('src1.txt', 'dest1', noop: true, verbose: true)
|
644
|
+
# FileUtils.cp(src_file_paths, 'dest2', noop: true, verbose: true)
|
645
|
+
#
|
646
|
+
# Output:
|
647
|
+
#
|
648
|
+
# cp src0.txt dest0.txt
|
649
|
+
# cp src1.txt dest1
|
650
|
+
# cp src2.txt src2.dat dest2
|
651
|
+
#
|
652
|
+
#
|
653
|
+
# Raises an exception if `src` is a directory.
|
654
|
+
#
|
655
|
+
# FileUtils.copy is an alias for FileUtils.cp.
|
656
|
+
#
|
657
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
351
658
|
#
|
352
659
|
def self?.cp: (pathlist src, path dest, ?preserve: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
353
660
|
|
@@ -369,27 +676,102 @@ module FileUtils
|
|
369
676
|
# rdoc-file=lib/fileutils.rb
|
370
677
|
# - cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false)
|
371
678
|
# -->
|
372
|
-
#
|
373
|
-
#
|
374
|
-
#
|
375
|
-
#
|
376
|
-
#
|
377
|
-
# If `
|
378
|
-
#
|
379
|
-
#
|
380
|
-
#
|
381
|
-
#
|
382
|
-
#
|
383
|
-
#
|
384
|
-
#
|
385
|
-
# #
|
386
|
-
#
|
387
|
-
#
|
388
|
-
#
|
389
|
-
#
|
390
|
-
#
|
391
|
-
# #
|
392
|
-
#
|
679
|
+
# Creates [hard links](https://en.wikipedia.org/wiki/Hard_link).
|
680
|
+
#
|
681
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
682
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments).
|
683
|
+
#
|
684
|
+
# If `src` is the path to a directory and `dest` does not exist, creates links
|
685
|
+
# `dest` and descendents pointing to `src` and its descendents:
|
686
|
+
#
|
687
|
+
# tree('src0')
|
688
|
+
# # => src0
|
689
|
+
# # |-- sub0
|
690
|
+
# # | |-- src0.txt
|
691
|
+
# # | `-- src1.txt
|
692
|
+
# # `-- sub1
|
693
|
+
# # |-- src2.txt
|
694
|
+
# # `-- src3.txt
|
695
|
+
# File.exist?('dest0') # => false
|
696
|
+
# FileUtils.cp_lr('src0', 'dest0')
|
697
|
+
# tree('dest0')
|
698
|
+
# # => dest0
|
699
|
+
# # |-- sub0
|
700
|
+
# # | |-- src0.txt
|
701
|
+
# # | `-- src1.txt
|
702
|
+
# # `-- sub1
|
703
|
+
# # |-- src2.txt
|
704
|
+
# # `-- src3.txt
|
705
|
+
#
|
706
|
+
# If `src` and `dest` are both paths to directories, creates links `dest/src`
|
707
|
+
# and descendents pointing to `src` and its descendents:
|
708
|
+
#
|
709
|
+
# tree('src1')
|
710
|
+
# # => src1
|
711
|
+
# # |-- sub0
|
712
|
+
# # | |-- src0.txt
|
713
|
+
# # | `-- src1.txt
|
714
|
+
# # `-- sub1
|
715
|
+
# # |-- src2.txt
|
716
|
+
# # `-- src3.txt
|
717
|
+
# FileUtils.mkdir('dest1')
|
718
|
+
# FileUtils.cp_lr('src1', 'dest1')
|
719
|
+
# tree('dest1')
|
720
|
+
# # => dest1
|
721
|
+
# # `-- src1
|
722
|
+
# # |-- sub0
|
723
|
+
# # | |-- src0.txt
|
724
|
+
# # | `-- src1.txt
|
725
|
+
# # `-- sub1
|
726
|
+
# # |-- src2.txt
|
727
|
+
# # `-- src3.txt
|
728
|
+
#
|
729
|
+
# If `src` is an array of paths to entries and `dest` is the path to a
|
730
|
+
# directory, for each path `filepath` in `src`, creates a link at
|
731
|
+
# `dest/filepath` pointing to that path:
|
732
|
+
#
|
733
|
+
# tree('src2')
|
734
|
+
# # => src2
|
735
|
+
# # |-- sub0
|
736
|
+
# # | |-- src0.txt
|
737
|
+
# # | `-- src1.txt
|
738
|
+
# # `-- sub1
|
739
|
+
# # |-- src2.txt
|
740
|
+
# # `-- src3.txt
|
741
|
+
# FileUtils.mkdir('dest2')
|
742
|
+
# FileUtils.cp_lr(['src2/sub0', 'src2/sub1'], 'dest2')
|
743
|
+
# tree('dest2')
|
744
|
+
# # => dest2
|
745
|
+
# # |-- sub0
|
746
|
+
# # | |-- src0.txt
|
747
|
+
# # | `-- src1.txt
|
748
|
+
# # `-- sub1
|
749
|
+
# # |-- src2.txt
|
750
|
+
# # `-- src3.txt
|
751
|
+
#
|
752
|
+
# Keyword arguments:
|
753
|
+
#
|
754
|
+
# * `dereference_root: false` - if `src` is a symbolic link, does not
|
755
|
+
# dereference it.
|
756
|
+
# * `noop: true` - does not create links.
|
757
|
+
# * `remove_destination: true` - removes `dest` before creating links.
|
758
|
+
# * `verbose: true` - prints an equivalent command:
|
759
|
+
#
|
760
|
+
# FileUtils.cp_lr('src0', 'dest0', noop: true, verbose: true)
|
761
|
+
# FileUtils.cp_lr('src1', 'dest1', noop: true, verbose: true)
|
762
|
+
# FileUtils.cp_lr(['src2/sub0', 'src2/sub1'], 'dest2', noop: true, verbose: true)
|
763
|
+
#
|
764
|
+
# Output:
|
765
|
+
#
|
766
|
+
# cp -lr src0 dest0
|
767
|
+
# cp -lr src1 dest1
|
768
|
+
# cp -lr src2/sub0 src2/sub1 dest2
|
769
|
+
#
|
770
|
+
#
|
771
|
+
# Raises an exception if `dest` is the path to an existing file or directory and
|
772
|
+
# keyword argument `remove_destination: true` is not given.
|
773
|
+
#
|
774
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
393
775
|
#
|
394
776
|
def self?.cp_lr: (pathlist src, path dest, ?noop: boolish, ?verbose: boolish, ?dereference_root: boolish, ?remove_destination: boolish) -> void
|
395
777
|
|
@@ -397,29 +779,105 @@ module FileUtils
|
|
397
779
|
# rdoc-file=lib/fileutils.rb
|
398
780
|
# - cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, dereference_root: true, remove_destination: nil)
|
399
781
|
# -->
|
400
|
-
#
|
401
|
-
#
|
402
|
-
#
|
403
|
-
#
|
404
|
-
#
|
405
|
-
#
|
406
|
-
#
|
407
|
-
#
|
408
|
-
#
|
409
|
-
#
|
410
|
-
#
|
411
|
-
# FileUtils.
|
412
|
-
#
|
413
|
-
#
|
414
|
-
# #
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
#
|
419
|
-
#
|
420
|
-
#
|
421
|
-
# FileUtils.cp_r
|
422
|
-
#
|
782
|
+
# Recursively copies files.
|
783
|
+
#
|
784
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
785
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments).
|
786
|
+
#
|
787
|
+
# The mode, owner, and group are retained in the copy; to change those, use
|
788
|
+
# FileUtils.install instead.
|
789
|
+
#
|
790
|
+
# If `src` is the path to a file and `dest` is not the path to a directory,
|
791
|
+
# copies `src` to `dest`:
|
792
|
+
#
|
793
|
+
# FileUtils.touch('src0.txt')
|
794
|
+
# File.exist?('dest0.txt') # => false
|
795
|
+
# FileUtils.cp_r('src0.txt', 'dest0.txt')
|
796
|
+
# File.file?('dest0.txt') # => true
|
797
|
+
#
|
798
|
+
# If `src` is the path to a file and `dest` is the path to a directory, copies
|
799
|
+
# `src` to `dest/src`:
|
800
|
+
#
|
801
|
+
# FileUtils.touch('src1.txt')
|
802
|
+
# FileUtils.mkdir('dest1')
|
803
|
+
# FileUtils.cp_r('src1.txt', 'dest1')
|
804
|
+
# File.file?('dest1/src1.txt') # => true
|
805
|
+
#
|
806
|
+
# If `src` is the path to a directory and `dest` does not exist, recursively
|
807
|
+
# copies `src` to `dest`:
|
808
|
+
#
|
809
|
+
# tree('src2')
|
810
|
+
# # => src2
|
811
|
+
# # |-- dir0
|
812
|
+
# # | |-- src0.txt
|
813
|
+
# # | `-- src1.txt
|
814
|
+
# # `-- dir1
|
815
|
+
# # |-- src2.txt
|
816
|
+
# # `-- src3.txt
|
817
|
+
# FileUtils.exist?('dest2') # => false
|
818
|
+
# FileUtils.cp_r('src2', 'dest2')
|
819
|
+
# tree('dest2')
|
820
|
+
# # => dest2
|
821
|
+
# # |-- dir0
|
822
|
+
# # | |-- src0.txt
|
823
|
+
# # | `-- src1.txt
|
824
|
+
# # `-- dir1
|
825
|
+
# # |-- src2.txt
|
826
|
+
# # `-- src3.txt
|
827
|
+
#
|
828
|
+
# If `src` and `dest` are paths to directories, recursively copies `src` to
|
829
|
+
# `dest/src`:
|
830
|
+
#
|
831
|
+
# tree('src3')
|
832
|
+
# # => src3
|
833
|
+
# # |-- dir0
|
834
|
+
# # | |-- src0.txt
|
835
|
+
# # | `-- src1.txt
|
836
|
+
# # `-- dir1
|
837
|
+
# # |-- src2.txt
|
838
|
+
# # `-- src3.txt
|
839
|
+
# FileUtils.mkdir('dest3')
|
840
|
+
# FileUtils.cp_r('src3', 'dest3')
|
841
|
+
# tree('dest3')
|
842
|
+
# # => dest3
|
843
|
+
# # `-- src3
|
844
|
+
# # |-- dir0
|
845
|
+
# # | |-- src0.txt
|
846
|
+
# # | `-- src1.txt
|
847
|
+
# # `-- dir1
|
848
|
+
# # |-- src2.txt
|
849
|
+
# # `-- src3.txt
|
850
|
+
#
|
851
|
+
# If `src` is an array of paths and `dest` is a directory, recursively copies
|
852
|
+
# from each path in `src` to `dest`; the paths in `src` may point to files
|
853
|
+
# and/or directories.
|
854
|
+
#
|
855
|
+
# Keyword arguments:
|
856
|
+
#
|
857
|
+
# * `dereference_root: false` - if `src` is a symbolic link, does not
|
858
|
+
# dereference it.
|
859
|
+
# * `noop: true` - does not copy files.
|
860
|
+
# * `preserve: true` - preserves file times.
|
861
|
+
# * `remove_destination: true` - removes `dest` before copying files.
|
862
|
+
# * `verbose: true` - prints an equivalent command:
|
863
|
+
#
|
864
|
+
# FileUtils.cp_r('src0.txt', 'dest0.txt', noop: true, verbose: true)
|
865
|
+
# FileUtils.cp_r('src1.txt', 'dest1', noop: true, verbose: true)
|
866
|
+
# FileUtils.cp_r('src2', 'dest2', noop: true, verbose: true)
|
867
|
+
# FileUtils.cp_r('src3', 'dest3', noop: true, verbose: true)
|
868
|
+
#
|
869
|
+
# Output:
|
870
|
+
#
|
871
|
+
# cp -r src0.txt dest0.txt
|
872
|
+
# cp -r src1.txt dest1
|
873
|
+
# cp -r src2 dest2
|
874
|
+
# cp -r src3 dest3
|
875
|
+
#
|
876
|
+
#
|
877
|
+
# Raises an exception of `src` is the path to a directory and `dest` is the path
|
878
|
+
# to a file.
|
879
|
+
#
|
880
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
423
881
|
#
|
424
882
|
def self?.cp_r: (pathlist src, path dest, ?preserve: boolish, ?noop: boolish, ?verbose: boolish, ?dereference_root: boolish, ?remove_destination: boolish) -> void
|
425
883
|
|
@@ -427,11 +885,11 @@ module FileUtils
|
|
427
885
|
# rdoc-file=lib/fileutils.rb
|
428
886
|
# - have_option?(mid, opt)
|
429
887
|
# -->
|
430
|
-
# Returns true if
|
888
|
+
# Returns `true` if method `mid` accepts the given option `opt`, `false`
|
889
|
+
# otherwise; the arguments may be strings or symbols:
|
431
890
|
#
|
432
|
-
#
|
433
|
-
#
|
434
|
-
# p FileUtils.have_option?(:rm, :preserve) #=> false
|
891
|
+
# FileUtils.have_option?(:chmod, :noop) # => true
|
892
|
+
# FileUtils.have_option?('chmod', 'secure') # => false
|
435
893
|
#
|
436
894
|
def self.have_option?: (Symbol mid, Symbol opt) -> bool
|
437
895
|
|
@@ -439,12 +897,69 @@ module FileUtils
|
|
439
897
|
# rdoc-file=lib/fileutils.rb
|
440
898
|
# - install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil)
|
441
899
|
# -->
|
442
|
-
#
|
443
|
-
#
|
444
|
-
#
|
900
|
+
# Copies a file entry. See
|
901
|
+
# [install(1)](https://man7.org/linux/man-pages/man1/install.1.html).
|
902
|
+
#
|
903
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
904
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments);
|
905
|
+
#
|
906
|
+
# If the entry at `dest` does not exist, copies from `src` to `dest`:
|
907
|
+
#
|
908
|
+
# File.read('src0.txt') # => "aaa\n"
|
909
|
+
# File.exist?('dest0.txt') # => false
|
910
|
+
# FileUtils.install('src0.txt', 'dest0.txt')
|
911
|
+
# File.read('dest0.txt') # => "aaa\n"
|
912
|
+
#
|
913
|
+
# If `dest` is a file entry, copies from `src` to `dest`, overwriting:
|
914
|
+
#
|
915
|
+
# File.read('src1.txt') # => "aaa\n"
|
916
|
+
# File.read('dest1.txt') # => "bbb\n"
|
917
|
+
# FileUtils.install('src1.txt', 'dest1.txt')
|
918
|
+
# File.read('dest1.txt') # => "aaa\n"
|
919
|
+
#
|
920
|
+
# If `dest` is a directory entry, copies from `src` to `dest/src`, overwriting
|
921
|
+
# if necessary:
|
922
|
+
#
|
923
|
+
# File.read('src2.txt') # => "aaa\n"
|
924
|
+
# File.read('dest2/src2.txt') # => "bbb\n"
|
925
|
+
# FileUtils.install('src2.txt', 'dest2')
|
926
|
+
# File.read('dest2/src2.txt') # => "aaa\n"
|
445
927
|
#
|
446
|
-
#
|
447
|
-
#
|
928
|
+
# If `src` is an array of paths and `dest` points to a directory, copies each
|
929
|
+
# path `path` in `src` to `dest/path`:
|
930
|
+
#
|
931
|
+
# File.file?('src3.txt') # => true
|
932
|
+
# File.file?('src3.dat') # => true
|
933
|
+
# FileUtils.mkdir('dest3')
|
934
|
+
# FileUtils.install(['src3.txt', 'src3.dat'], 'dest3')
|
935
|
+
# File.file?('dest3/src3.txt') # => true
|
936
|
+
# File.file?('dest3/src3.dat') # => true
|
937
|
+
#
|
938
|
+
# Keyword arguments:
|
939
|
+
#
|
940
|
+
# * `group: *group`* - changes the group if not `nil`, using
|
941
|
+
# [File.chown](rdoc-ref:File.chown).
|
942
|
+
# * `mode: *permissions`* - changes the permissions. using
|
943
|
+
# [File.chmod](rdoc-ref:File.chmod).
|
944
|
+
# * `noop: true` - does not copy entries; returns `nil`.
|
945
|
+
# * `owner: *owner`* - changes the owner if not `nil`, using
|
946
|
+
# [File.chown](rdoc-ref:File.chown).
|
947
|
+
# * `preserve: true` - preserve timestamps using
|
948
|
+
# [File.utime](rdoc-ref:File.utime).
|
949
|
+
# * `verbose: true` - prints an equivalent command:
|
950
|
+
#
|
951
|
+
# FileUtils.install('src0.txt', 'dest0.txt', noop: true, verbose: true)
|
952
|
+
# FileUtils.install('src1.txt', 'dest1.txt', noop: true, verbose: true)
|
953
|
+
# FileUtils.install('src2.txt', 'dest2', noop: true, verbose: true)
|
954
|
+
#
|
955
|
+
# Output:
|
956
|
+
#
|
957
|
+
# install -c src0.txt dest0.txt
|
958
|
+
# install -c src1.txt dest1.txt
|
959
|
+
# install -c src2.txt dest2
|
960
|
+
#
|
961
|
+
#
|
962
|
+
# Related: [methods for copying](rdoc-ref:FileUtils@Copying).
|
448
963
|
#
|
449
964
|
def self?.install: (path src, path dest, ?mode: mode?, ?owner: String?, ?group: String?, ?preserve: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
450
965
|
|
@@ -452,38 +967,108 @@ module FileUtils
|
|
452
967
|
# rdoc-file=lib/fileutils.rb
|
453
968
|
# - link_entry(src, dest, dereference_root = false, remove_destination = false)
|
454
969
|
# -->
|
455
|
-
#
|
456
|
-
#
|
970
|
+
# Creates [hard links](https://en.wikipedia.org/wiki/Hard_link); returns `nil`.
|
971
|
+
#
|
972
|
+
# Arguments `src` and `dest` should be [interpretable as
|
973
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
974
|
+
#
|
975
|
+
# If `src` is the path to a file and `dest` does not exist, creates a hard link
|
976
|
+
# at `dest` pointing to `src`:
|
457
977
|
#
|
458
|
-
#
|
459
|
-
#
|
978
|
+
# FileUtils.touch('src0.txt')
|
979
|
+
# File.exist?('dest0.txt') # => false
|
980
|
+
# FileUtils.link_entry('src0.txt', 'dest0.txt')
|
981
|
+
# File.file?('dest0.txt') # => true
|
460
982
|
#
|
461
|
-
# If `
|
983
|
+
# If `src` is the path to a directory and `dest` does not exist, recursively
|
984
|
+
# creates hard links at `dest` pointing to paths in `src`:
|
462
985
|
#
|
463
|
-
#
|
464
|
-
#
|
986
|
+
# FileUtils.mkdir_p(['src1/dir0', 'src1/dir1'])
|
987
|
+
# src_file_paths = [
|
988
|
+
# 'src1/dir0/t0.txt',
|
989
|
+
# 'src1/dir0/t1.txt',
|
990
|
+
# 'src1/dir1/t2.txt',
|
991
|
+
# 'src1/dir1/t3.txt',
|
992
|
+
# ]
|
993
|
+
# FileUtils.touch(src_file_paths)
|
994
|
+
# File.directory?('dest1') # => true
|
995
|
+
# FileUtils.link_entry('src1', 'dest1')
|
996
|
+
# File.file?('dest1/dir0/t0.txt') # => true
|
997
|
+
# File.file?('dest1/dir0/t1.txt') # => true
|
998
|
+
# File.file?('dest1/dir1/t2.txt') # => true
|
999
|
+
# File.file?('dest1/dir1/t3.txt') # => true
|
1000
|
+
#
|
1001
|
+
# Keyword arguments:
|
1002
|
+
#
|
1003
|
+
# * `dereference_root: true` - dereferences `src` if it is a symbolic link.
|
1004
|
+
# * `remove_destination: true` - removes `dest` before creating links.
|
1005
|
+
#
|
1006
|
+
#
|
1007
|
+
# Raises an exception if `dest` is the path to an existing file or directory and
|
1008
|
+
# keyword argument `remove_destination: true` is not given.
|
1009
|
+
#
|
1010
|
+
# Related: FileUtils.ln (has different options).
|
465
1011
|
#
|
466
1012
|
def self?.link_entry: (path src, path dest, ?boolish dereference_root, ?boolish remove_destination) -> void
|
467
1013
|
|
468
1014
|
# <!--
|
469
1015
|
# rdoc-file=lib/fileutils.rb
|
470
|
-
# -
|
471
|
-
# - FileUtils.ln(target, dir, force: nil, noop: nil, verbose: nil)
|
472
|
-
# - FileUtils.ln(targets, dir, force: nil, noop: nil, verbose: nil)
|
1016
|
+
# - ln(src, dest, force: nil, noop: nil, verbose: nil)
|
473
1017
|
# -->
|
474
|
-
#
|
475
|
-
#
|
476
|
-
#
|
1018
|
+
# Creates [hard links](https://en.wikipedia.org/wiki/Hard_link).
|
1019
|
+
#
|
1020
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
1021
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments).
|
1022
|
+
#
|
1023
|
+
# When `src` is the path to an existing file and `dest` is the path to a
|
1024
|
+
# non-existent file, creates a hard link at `dest` pointing to `src`; returns
|
1025
|
+
# zero:
|
1026
|
+
#
|
1027
|
+
# Dir.children('tmp0/') # => ["t.txt"]
|
1028
|
+
# Dir.children('tmp1/') # => []
|
1029
|
+
# FileUtils.ln('tmp0/t.txt', 'tmp1/t.lnk') # => 0
|
1030
|
+
# Dir.children('tmp1/') # => ["t.lnk"]
|
1031
|
+
#
|
1032
|
+
# When `src` is the path to an existing file and `dest` is the path to an
|
1033
|
+
# existing directory, creates a hard link at `dest/src` pointing to `src`;
|
1034
|
+
# returns zero:
|
1035
|
+
#
|
1036
|
+
# Dir.children('tmp2') # => ["t.dat"]
|
1037
|
+
# Dir.children('tmp3') # => []
|
1038
|
+
# FileUtils.ln('tmp2/t.dat', 'tmp3') # => 0
|
1039
|
+
# Dir.children('tmp3') # => ["t.dat"]
|
477
1040
|
#
|
478
|
-
#
|
479
|
-
#
|
1041
|
+
# When `src` is an array of paths to existing files and `dest` is the path to an
|
1042
|
+
# existing directory, then for each path `target` in `src`, creates a hard link
|
1043
|
+
# at `dest/target` pointing to `target`; returns `src`:
|
480
1044
|
#
|
481
|
-
#
|
482
|
-
#
|
483
|
-
#
|
1045
|
+
# Dir.children('tmp4/') # => []
|
1046
|
+
# FileUtils.ln(['tmp0/t.txt', 'tmp2/t.dat'], 'tmp4/') # => ["tmp0/t.txt", "tmp2/t.dat"]
|
1047
|
+
# Dir.children('tmp4/') # => ["t.dat", "t.txt"]
|
484
1048
|
#
|
485
|
-
#
|
486
|
-
#
|
1049
|
+
# Keyword arguments:
|
1050
|
+
#
|
1051
|
+
# * `force: true` - overwrites `dest` if it exists.
|
1052
|
+
# * `noop: true` - does not create links.
|
1053
|
+
# * `verbose: true` - prints an equivalent command:
|
1054
|
+
#
|
1055
|
+
# FileUtils.ln('tmp0/t.txt', 'tmp1/t.lnk', verbose: true)
|
1056
|
+
# FileUtils.ln('tmp2/t.dat', 'tmp3', verbose: true)
|
1057
|
+
# FileUtils.ln(['tmp0/t.txt', 'tmp2/t.dat'], 'tmp4/', verbose: true)
|
1058
|
+
#
|
1059
|
+
# Output:
|
1060
|
+
#
|
1061
|
+
# ln tmp0/t.txt tmp1/t.lnk
|
1062
|
+
# ln tmp2/t.dat tmp3
|
1063
|
+
# ln tmp0/t.txt tmp2/t.dat tmp4/
|
1064
|
+
#
|
1065
|
+
#
|
1066
|
+
# Raises an exception if `dest` is the path to an existing file and keyword
|
1067
|
+
# argument `force` is not `true`.
|
1068
|
+
#
|
1069
|
+
# FileUtils#link is an alias for FileUtils#ln.
|
1070
|
+
#
|
1071
|
+
# Related: FileUtils.link_entry (has different options).
|
487
1072
|
#
|
488
1073
|
def self?.ln: (pathlist src, path dest, ?force: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
489
1074
|
|
@@ -503,59 +1088,147 @@ module FileUtils
|
|
503
1088
|
|
504
1089
|
# <!--
|
505
1090
|
# rdoc-file=lib/fileutils.rb
|
506
|
-
# -
|
507
|
-
# - FileUtils.ln_s(target, dir, force: nil, noop: nil, verbose: nil)
|
508
|
-
# - FileUtils.ln_s(targets, dir, force: nil, noop: nil, verbose: nil)
|
1091
|
+
# - ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
|
509
1092
|
# -->
|
510
|
-
#
|
511
|
-
#
|
512
|
-
#
|
1093
|
+
# Creates [symbolic links](https://en.wikipedia.org/wiki/Symbolic_link).
|
1094
|
+
#
|
1095
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
1096
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments).
|
1097
|
+
#
|
1098
|
+
# If `src` is the path to an existing file:
|
513
1099
|
#
|
514
|
-
#
|
515
|
-
#
|
1100
|
+
# * When `dest` is the path to a non-existent file, creates a symbolic link at
|
1101
|
+
# `dest` pointing to `src`:
|
516
1102
|
#
|
517
|
-
#
|
518
|
-
#
|
519
|
-
#
|
1103
|
+
# FileUtils.touch('src0.txt')
|
1104
|
+
# File.exist?('dest0.txt') # => false
|
1105
|
+
# FileUtils.ln_s('src0.txt', 'dest0.txt')
|
1106
|
+
# File.symlink?('dest0.txt') # => true
|
520
1107
|
#
|
521
|
-
#
|
1108
|
+
# * When `dest` is the path to an existing file, creates a symbolic link at
|
1109
|
+
# `dest` pointing to `src` if and only if keyword argument `force: true` is
|
1110
|
+
# given (raises an exception otherwise):
|
522
1111
|
#
|
523
|
-
|
1112
|
+
# FileUtils.touch('src1.txt')
|
1113
|
+
# FileUtils.touch('dest1.txt')
|
1114
|
+
# FileUtils.ln_s('src1.txt', 'dest1.txt', force: true)
|
1115
|
+
# FileTest.symlink?('dest1.txt') # => true
|
1116
|
+
#
|
1117
|
+
# FileUtils.ln_s('src1.txt', 'dest1.txt') # Raises Errno::EEXIST.
|
1118
|
+
#
|
1119
|
+
#
|
1120
|
+
# If `dest` is the path to a directory, creates a symbolic link at `dest/src`
|
1121
|
+
# pointing to `src`:
|
1122
|
+
#
|
1123
|
+
# FileUtils.touch('src2.txt')
|
1124
|
+
# FileUtils.mkdir('destdir2')
|
1125
|
+
# FileUtils.ln_s('src2.txt', 'destdir2')
|
1126
|
+
# File.symlink?('destdir2/src2.txt') # => true
|
1127
|
+
#
|
1128
|
+
# If `src` is an array of paths to existing files and `dest` is a directory, for
|
1129
|
+
# each child `child` in `src` creates a symbolic link `dest/child` pointing to
|
1130
|
+
# `child`:
|
1131
|
+
#
|
1132
|
+
# FileUtils.mkdir('srcdir3')
|
1133
|
+
# FileUtils.touch('srcdir3/src0.txt')
|
1134
|
+
# FileUtils.touch('srcdir3/src1.txt')
|
1135
|
+
# FileUtils.mkdir('destdir3')
|
1136
|
+
# FileUtils.ln_s(['srcdir3/src0.txt', 'srcdir3/src1.txt'], 'destdir3')
|
1137
|
+
# File.symlink?('destdir3/src0.txt') # => true
|
1138
|
+
# File.symlink?('destdir3/src1.txt') # => true
|
1139
|
+
#
|
1140
|
+
# Keyword arguments:
|
1141
|
+
#
|
1142
|
+
# * `force: true` - overwrites `dest` if it exists.
|
1143
|
+
# * `relative: false` - create links relative to `dest`.
|
1144
|
+
# * `noop: true` - does not create links.
|
1145
|
+
# * `verbose: true` - prints an equivalent command:
|
1146
|
+
#
|
1147
|
+
# FileUtils.ln_s('src0.txt', 'dest0.txt', noop: true, verbose: true)
|
1148
|
+
# FileUtils.ln_s('src1.txt', 'destdir1', noop: true, verbose: true)
|
1149
|
+
# FileUtils.ln_s('src2.txt', 'dest2.txt', force: true, noop: true, verbose: true)
|
1150
|
+
# FileUtils.ln_s(['srcdir3/src0.txt', 'srcdir3/src1.txt'], 'destdir3', noop: true, verbose: true)
|
1151
|
+
#
|
1152
|
+
# Output:
|
1153
|
+
#
|
1154
|
+
# ln -s src0.txt dest0.txt
|
1155
|
+
# ln -s src1.txt destdir1
|
1156
|
+
# ln -sf src2.txt dest2.txt
|
1157
|
+
# ln -s srcdir3/src0.txt srcdir3/src1.txt destdir3
|
1158
|
+
#
|
1159
|
+
#
|
1160
|
+
# FileUtils.symlink is an alias for FileUtils.ln_s.
|
1161
|
+
#
|
1162
|
+
# Related: FileUtils.ln_sf.
|
1163
|
+
#
|
1164
|
+
def self?.ln_s: (pathlist src, path dest, ?force: boolish, ?relative: boolish, ?target_directory: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
524
1165
|
|
525
1166
|
# <!--
|
526
1167
|
# rdoc-file=lib/fileutils.rb
|
527
|
-
# - symlink(src, dest, force: nil, noop: nil, verbose: nil)
|
1168
|
+
# - symlink(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
|
528
1169
|
# -->
|
529
1170
|
#
|
530
1171
|
alias self.symlink self.ln_s
|
531
1172
|
|
532
1173
|
# <!--
|
533
1174
|
# rdoc-file=lib/fileutils.rb
|
534
|
-
# - symlink(src, dest, force: nil, noop: nil, verbose: nil)
|
1175
|
+
# - symlink(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
|
535
1176
|
# -->
|
536
1177
|
#
|
537
1178
|
alias symlink ln_s
|
538
1179
|
|
539
1180
|
# <!--
|
540
1181
|
# rdoc-file=lib/fileutils.rb
|
541
|
-
# -
|
1182
|
+
# - ln_sf(src, dest, noop: nil, verbose: nil)
|
542
1183
|
# -->
|
543
|
-
#
|
544
|
-
#
|
545
|
-
# FileUtils.ln_s(*args, force: true)
|
1184
|
+
# Like FileUtils.ln_s, but always with keyword argument `force: true` given.
|
546
1185
|
#
|
547
1186
|
def self?.ln_sf: (pathlist src, path dest, ?noop: boolish, ?verbose: boolish) -> void
|
548
1187
|
|
1188
|
+
# <!--
|
1189
|
+
# rdoc-file=lib/fileutils.rb
|
1190
|
+
# - ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
|
1191
|
+
# -->
|
1192
|
+
# Like FileUtils.ln_s, but create links relative to `dest`.
|
1193
|
+
#
|
1194
|
+
def self?.ln_sr: (pathlist src, path dest, ?target_directory: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
1195
|
+
|
549
1196
|
# <!--
|
550
1197
|
# rdoc-file=lib/fileutils.rb
|
551
1198
|
# - mkdir(list, mode: nil, noop: nil, verbose: nil)
|
552
1199
|
# -->
|
553
|
-
# Creates
|
1200
|
+
# Creates directories at the paths in the given `list` (a single path or an
|
1201
|
+
# array of paths); returns `list` if it is an array, `[list]` otherwise.
|
1202
|
+
#
|
1203
|
+
# Argument `list` or its elements should be [interpretable as
|
1204
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1205
|
+
#
|
1206
|
+
# With no keyword arguments, creates a directory at each `path` in `list` by
|
1207
|
+
# calling: `Dir.mkdir(path, mode)`; see [Dir.mkdir](rdoc-ref:Dir.mkdir):
|
1208
|
+
#
|
1209
|
+
# FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"]
|
1210
|
+
# FileUtils.mkdir('tmp4') # => ["tmp4"]
|
1211
|
+
#
|
1212
|
+
# Keyword arguments:
|
1213
|
+
#
|
1214
|
+
# * `mode: *mode`* - also calls `File.chmod(mode, path)`; see
|
1215
|
+
# [File.chmod](rdoc-ref:File.chmod).
|
1216
|
+
# * `noop: true` - does not create directories.
|
1217
|
+
# * `verbose: true` - prints an equivalent command:
|
1218
|
+
#
|
1219
|
+
# FileUtils.mkdir(%w[tmp0 tmp1], verbose: true)
|
1220
|
+
# FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
|
1221
|
+
#
|
1222
|
+
# Output:
|
1223
|
+
#
|
1224
|
+
# mkdir tmp0 tmp1
|
1225
|
+
# mkdir -m 700 tmp2 tmp3
|
1226
|
+
#
|
554
1227
|
#
|
555
|
-
#
|
556
|
-
#
|
557
|
-
#
|
558
|
-
#
|
1228
|
+
# Raises an exception if any path points to an existing file or directory, or if
|
1229
|
+
# for any reason a directory cannot be created.
|
1230
|
+
#
|
1231
|
+
# Related: FileUtils.mkdir_p.
|
559
1232
|
#
|
560
1233
|
def self?.mkdir: (pathlist list, ?mode: Integer?, ?noop: boolish, ?verbose: boolish) -> void
|
561
1234
|
|
@@ -563,19 +1236,41 @@ module FileUtils
|
|
563
1236
|
# rdoc-file=lib/fileutils.rb
|
564
1237
|
# - mkdir_p(list, mode: nil, noop: nil, verbose: nil)
|
565
1238
|
# -->
|
566
|
-
# Creates
|
1239
|
+
# Creates directories at the paths in the given `list` (a single path or an
|
1240
|
+
# array of paths), also creating ancestor directories as needed; returns `list`
|
1241
|
+
# if it is an array, `[list]` otherwise.
|
1242
|
+
#
|
1243
|
+
# Argument `list` or its elements should be [interpretable as
|
1244
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1245
|
+
#
|
1246
|
+
# With no keyword arguments, creates a directory at each `path` in `list`, along
|
1247
|
+
# with any needed ancestor directories, by calling: `Dir.mkdir(path, mode)`; see
|
1248
|
+
# [Dir.mkdir](rdoc-ref:Dir.mkdir):
|
1249
|
+
#
|
1250
|
+
# FileUtils.mkdir_p(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
|
1251
|
+
# FileUtils.mkdir_p('tmp4/tmp5') # => ["tmp4/tmp5"]
|
1252
|
+
#
|
1253
|
+
# Keyword arguments:
|
567
1254
|
#
|
568
|
-
#
|
1255
|
+
# * `mode: *mode`* - also calls `File.chmod(mode, path)`; see
|
1256
|
+
# [File.chmod](rdoc-ref:File.chmod).
|
1257
|
+
# * `noop: true` - does not create directories.
|
1258
|
+
# * `verbose: true` - prints an equivalent command:
|
569
1259
|
#
|
570
|
-
#
|
1260
|
+
# FileUtils.mkdir_p(%w[tmp0 tmp1], verbose: true)
|
1261
|
+
# FileUtils.mkdir_p(%w[tmp2 tmp3], mode: 0700, verbose: true)
|
571
1262
|
#
|
572
|
-
#
|
573
|
-
# * /usr/local
|
574
|
-
# * /usr/local/lib
|
575
|
-
# * /usr/local/lib/ruby
|
1263
|
+
# Output:
|
576
1264
|
#
|
1265
|
+
# mkdir -p tmp0 tmp1
|
1266
|
+
# mkdir -p -m 700 tmp2 tmp3
|
577
1267
|
#
|
578
|
-
#
|
1268
|
+
#
|
1269
|
+
# Raises an exception if for any reason a directory cannot be created.
|
1270
|
+
#
|
1271
|
+
# FileUtils.mkpath and FileUtils.makedirs are aliases for FileUtils.mkdir_p.
|
1272
|
+
#
|
1273
|
+
# Related: FileUtils.mkdir.
|
579
1274
|
#
|
580
1275
|
def self?.mkdir_p: (pathlist list, ?mode: mode?, ?noop: boolish, ?verbose: boolish) -> void
|
581
1276
|
|
@@ -611,14 +1306,70 @@ module FileUtils
|
|
611
1306
|
# rdoc-file=lib/fileutils.rb
|
612
1307
|
# - mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
|
613
1308
|
# -->
|
614
|
-
# Moves
|
615
|
-
#
|
1309
|
+
# Moves entries.
|
1310
|
+
#
|
1311
|
+
# Arguments `src` (a single path or an array of paths) and `dest` (a single
|
1312
|
+
# path) should be [interpretable as paths](rdoc-ref:FileUtils@Path+Arguments).
|
616
1313
|
#
|
617
|
-
#
|
618
|
-
#
|
1314
|
+
# If `src` and `dest` are on different file systems, first copies, then removes
|
1315
|
+
# `src`.
|
619
1316
|
#
|
620
|
-
#
|
621
|
-
#
|
1317
|
+
# May cause a local vulnerability if not called with keyword argument `secure:
|
1318
|
+
# true`; see [Avoiding the TOCTTOU
|
1319
|
+
# Vulnerability](rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability).
|
1320
|
+
#
|
1321
|
+
# If `src` is the path to a single file or directory and `dest` does not exist,
|
1322
|
+
# moves `src` to `dest`:
|
1323
|
+
#
|
1324
|
+
# tree('src0')
|
1325
|
+
# # => src0
|
1326
|
+
# # |-- src0.txt
|
1327
|
+
# # `-- src1.txt
|
1328
|
+
# File.exist?('dest0') # => false
|
1329
|
+
# FileUtils.mv('src0', 'dest0')
|
1330
|
+
# File.exist?('src0') # => false
|
1331
|
+
# tree('dest0')
|
1332
|
+
# # => dest0
|
1333
|
+
# # |-- src0.txt
|
1334
|
+
# # `-- src1.txt
|
1335
|
+
#
|
1336
|
+
# If `src` is an array of paths to files and directories and `dest` is the path
|
1337
|
+
# to a directory, copies from each path in the array to `dest`:
|
1338
|
+
#
|
1339
|
+
# File.file?('src1.txt') # => true
|
1340
|
+
# tree('src1')
|
1341
|
+
# # => src1
|
1342
|
+
# # |-- src.dat
|
1343
|
+
# # `-- src.txt
|
1344
|
+
# Dir.empty?('dest1') # => true
|
1345
|
+
# FileUtils.mv(['src1.txt', 'src1'], 'dest1')
|
1346
|
+
# tree('dest1')
|
1347
|
+
# # => dest1
|
1348
|
+
# # |-- src1
|
1349
|
+
# # | |-- src.dat
|
1350
|
+
# # | `-- src.txt
|
1351
|
+
# # `-- src1.txt
|
1352
|
+
#
|
1353
|
+
# Keyword arguments:
|
1354
|
+
#
|
1355
|
+
# * `force: true` - if the move includes removing `src` (that is, if `src` and
|
1356
|
+
# `dest` are on different file systems), ignores raised exceptions of
|
1357
|
+
# StandardError and its descendants.
|
1358
|
+
# * `noop: true` - does not move files.
|
1359
|
+
# * `secure: true` - removes `src` securely; see details at
|
1360
|
+
# FileUtils.remove_entry_secure.
|
1361
|
+
# * `verbose: true` - prints an equivalent command:
|
1362
|
+
#
|
1363
|
+
# FileUtils.mv('src0', 'dest0', noop: true, verbose: true)
|
1364
|
+
# FileUtils.mv(['src1.txt', 'src1'], 'dest1', noop: true, verbose: true)
|
1365
|
+
#
|
1366
|
+
# Output:
|
1367
|
+
#
|
1368
|
+
# mv src0 dest0
|
1369
|
+
# mv src1.txt src1 dest1
|
1370
|
+
#
|
1371
|
+
#
|
1372
|
+
# FileUtils.move is an alias for FileUtils.mv.
|
622
1373
|
#
|
623
1374
|
def self?.mv: (pathlist src, path dest, ?force: boolish, ?noop: boolish, ?verbose: boolish, ?secure: boolish) -> void
|
624
1375
|
|
@@ -640,9 +1391,9 @@ module FileUtils
|
|
640
1391
|
# rdoc-file=lib/fileutils.rb
|
641
1392
|
# - options()
|
642
1393
|
# -->
|
643
|
-
# Returns an
|
1394
|
+
# Returns an array of the string keyword names:
|
644
1395
|
#
|
645
|
-
#
|
1396
|
+
# FileUtils.options.take(3) # => ["noop", "verbose", "force"]
|
646
1397
|
#
|
647
1398
|
def self.options: () -> Array[String]
|
648
1399
|
|
@@ -650,9 +1401,11 @@ module FileUtils
|
|
650
1401
|
# rdoc-file=lib/fileutils.rb
|
651
1402
|
# - options_of(mid)
|
652
1403
|
# -->
|
653
|
-
# Returns an
|
1404
|
+
# Returns an array of the string keyword name for method `mid`; the argument may
|
1405
|
+
# be a string or a symbol:
|
654
1406
|
#
|
655
|
-
#
|
1407
|
+
# FileUtils.options_of(:rm) # => ["force", "noop", "verbose"]
|
1408
|
+
# FileUtils.options_of('mv') # => ["force", "noop", "verbose", "secure"]
|
656
1409
|
#
|
657
1410
|
def self.options_of: (Symbol mid) -> Array[String]
|
658
1411
|
|
@@ -660,7 +1413,13 @@ module FileUtils
|
|
660
1413
|
# rdoc-file=lib/fileutils.rb
|
661
1414
|
# - pwd()
|
662
1415
|
# -->
|
663
|
-
# Returns the
|
1416
|
+
# Returns a string containing the path to the current directory:
|
1417
|
+
#
|
1418
|
+
# FileUtils.pwd # => "/rdoc/fileutils"
|
1419
|
+
#
|
1420
|
+
# FileUtils.getwd is an alias for FileUtils.pwd.
|
1421
|
+
#
|
1422
|
+
# Related: FileUtils.cd.
|
664
1423
|
#
|
665
1424
|
def self?.pwd: () -> String
|
666
1425
|
|
@@ -682,8 +1441,16 @@ module FileUtils
|
|
682
1441
|
# rdoc-file=lib/fileutils.rb
|
683
1442
|
# - remove_dir(path, force = false)
|
684
1443
|
# -->
|
685
|
-
#
|
686
|
-
#
|
1444
|
+
# Recursively removes the directory entry given by `path`, which should be the
|
1445
|
+
# entry for a regular file, a symbolic link, or a directory.
|
1446
|
+
#
|
1447
|
+
# Argument `path` should be [interpretable as a
|
1448
|
+
# path](rdoc-ref:FileUtils@Path+Arguments).
|
1449
|
+
#
|
1450
|
+
# Optional argument `force` specifies whether to ignore raised exceptions of
|
1451
|
+
# StandardError and its descendants.
|
1452
|
+
#
|
1453
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
687
1454
|
#
|
688
1455
|
def self?.remove_dir: (path path, ?boolish force) -> void
|
689
1456
|
|
@@ -691,11 +1458,16 @@ module FileUtils
|
|
691
1458
|
# rdoc-file=lib/fileutils.rb
|
692
1459
|
# - remove_entry(path, force = false)
|
693
1460
|
# -->
|
694
|
-
#
|
695
|
-
# file, a
|
696
|
-
#
|
1461
|
+
# Removes the entry given by `path`, which should be the entry for a regular
|
1462
|
+
# file, a symbolic link, or a directory.
|
1463
|
+
#
|
1464
|
+
# Argument `path` should be [interpretable as a
|
1465
|
+
# path](rdoc-ref:FileUtils@Path+Arguments).
|
697
1466
|
#
|
698
|
-
#
|
1467
|
+
# Optional argument `force` specifies whether to ignore raised exceptions of
|
1468
|
+
# StandardError and its descendants.
|
1469
|
+
#
|
1470
|
+
# Related: FileUtils.remove_entry_secure.
|
699
1471
|
#
|
700
1472
|
def self?.remove_entry: (path path, ?boolish force) -> void
|
701
1473
|
|
@@ -703,37 +1475,20 @@ module FileUtils
|
|
703
1475
|
# rdoc-file=lib/fileutils.rb
|
704
1476
|
# - remove_entry_secure(path, force = false)
|
705
1477
|
# -->
|
706
|
-
#
|
707
|
-
# file, a
|
708
|
-
# recursively. This method is required to avoid TOCTTOU
|
709
|
-
# (time-of-check-to-time-of-use) local security vulnerability of rm_r. #rm_r
|
710
|
-
# causes security hole when:
|
711
|
-
#
|
712
|
-
# * Parent directory is world writable (including /tmp).
|
713
|
-
# * Removing directory tree includes world writable directory.
|
714
|
-
# * The system has symbolic link.
|
1478
|
+
# Securely removes the entry given by `path`, which should be the entry for a
|
1479
|
+
# regular file, a symbolic link, or a directory.
|
715
1480
|
#
|
1481
|
+
# Argument `path` should be [interpretable as a
|
1482
|
+
# path](rdoc-ref:FileUtils@Path+Arguments).
|
716
1483
|
#
|
717
|
-
#
|
718
|
-
#
|
719
|
-
#
|
720
|
-
# tree, or is the super user (root).
|
1484
|
+
# Avoids a local vulnerability that can exist in certain circumstances; see
|
1485
|
+
# [Avoiding the TOCTTOU
|
1486
|
+
# Vulnerability](rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability).
|
721
1487
|
#
|
722
|
-
#
|
723
|
-
#
|
724
|
-
# untrusted users, and should not be world writable except when the sticky bit
|
725
|
-
# set.
|
1488
|
+
# Optional argument `force` specifies whether to ignore raised exceptions of
|
1489
|
+
# StandardError and its descendants.
|
726
1490
|
#
|
727
|
-
#
|
728
|
-
# (root) should invoke this method. Otherwise this method does not work.
|
729
|
-
#
|
730
|
-
# For details of this security vulnerability, see Perl's case:
|
731
|
-
#
|
732
|
-
# * https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0448
|
733
|
-
# * https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452
|
734
|
-
#
|
735
|
-
#
|
736
|
-
# For fileutils.rb, this vulnerability is reported in [ruby-dev:26100].
|
1491
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
737
1492
|
#
|
738
1493
|
def self?.remove_entry_secure: (path path, ?boolish force) -> void
|
739
1494
|
|
@@ -741,7 +1496,16 @@ module FileUtils
|
|
741
1496
|
# rdoc-file=lib/fileutils.rb
|
742
1497
|
# - remove_file(path, force = false)
|
743
1498
|
# -->
|
744
|
-
# Removes
|
1499
|
+
# Removes the file entry given by `path`, which should be the entry for a
|
1500
|
+
# regular file or a symbolic link.
|
1501
|
+
#
|
1502
|
+
# Argument `path` should be [interpretable as a
|
1503
|
+
# path](rdoc-ref:FileUtils@Path+Arguments).
|
1504
|
+
#
|
1505
|
+
# Optional argument `force` specifies whether to ignore raised exceptions of
|
1506
|
+
# StandardError and its descendants.
|
1507
|
+
#
|
1508
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
745
1509
|
#
|
746
1510
|
def self?.remove_file: (path path, ?void force) -> void
|
747
1511
|
|
@@ -749,12 +1513,34 @@ module FileUtils
|
|
749
1513
|
# rdoc-file=lib/fileutils.rb
|
750
1514
|
# - rm(list, force: nil, noop: nil, verbose: nil)
|
751
1515
|
# -->
|
752
|
-
#
|
753
|
-
#
|
1516
|
+
# Removes entries at the paths in the given `list` (a single path or an array of
|
1517
|
+
# paths) returns `list`, if it is an array, `[list]` otherwise.
|
1518
|
+
#
|
1519
|
+
# Argument `list` or its elements should be [interpretable as
|
1520
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1521
|
+
#
|
1522
|
+
# With no keyword arguments, removes files at the paths given in `list`:
|
1523
|
+
#
|
1524
|
+
# FileUtils.touch(['src0.txt', 'src0.dat'])
|
1525
|
+
# FileUtils.rm(['src0.dat', 'src0.txt']) # => ["src0.dat", "src0.txt"]
|
754
1526
|
#
|
755
|
-
#
|
756
|
-
#
|
757
|
-
#
|
1527
|
+
# Keyword arguments:
|
1528
|
+
#
|
1529
|
+
# * `force: true` - ignores raised exceptions of StandardError and its
|
1530
|
+
# descendants.
|
1531
|
+
# * `noop: true` - does not remove files; returns `nil`.
|
1532
|
+
# * `verbose: true` - prints an equivalent command:
|
1533
|
+
#
|
1534
|
+
# FileUtils.rm(['src0.dat', 'src0.txt'], noop: true, verbose: true)
|
1535
|
+
#
|
1536
|
+
# Output:
|
1537
|
+
#
|
1538
|
+
# rm src0.dat src0.txt
|
1539
|
+
#
|
1540
|
+
#
|
1541
|
+
# FileUtils.remove is an alias for FileUtils.rm.
|
1542
|
+
#
|
1543
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
758
1544
|
#
|
759
1545
|
def self?.rm: (pathlist list, ?force: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
760
1546
|
|
@@ -776,9 +1562,18 @@ module FileUtils
|
|
776
1562
|
# rdoc-file=lib/fileutils.rb
|
777
1563
|
# - rm_f(list, noop: nil, verbose: nil)
|
778
1564
|
# -->
|
779
|
-
# Equivalent to
|
1565
|
+
# Equivalent to:
|
1566
|
+
#
|
1567
|
+
# FileUtils.rm(list, force: true, **kwargs)
|
1568
|
+
#
|
1569
|
+
# Argument `list` (a single path or an array of paths) should be [interpretable
|
1570
|
+
# as paths](rdoc-ref:FileUtils@Path+Arguments).
|
1571
|
+
#
|
1572
|
+
# See FileUtils.rm for keyword arguments.
|
780
1573
|
#
|
781
|
-
#
|
1574
|
+
# FileUtils.safe_unlink is an alias for FileUtils.rm_f.
|
1575
|
+
#
|
1576
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
782
1577
|
#
|
783
1578
|
def self?.rm_f: (pathlist list, ?noop: boolish, ?verbose: boolish) -> void
|
784
1579
|
|
@@ -800,22 +1595,55 @@ module FileUtils
|
|
800
1595
|
# rdoc-file=lib/fileutils.rb
|
801
1596
|
# - rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
|
802
1597
|
# -->
|
803
|
-
#
|
804
|
-
#
|
805
|
-
#
|
1598
|
+
# Removes entries at the paths in the given `list` (a single path or an array of
|
1599
|
+
# paths); returns `list`, if it is an array, `[list]` otherwise.
|
1600
|
+
#
|
1601
|
+
# Argument `list` or its elements should be [interpretable as
|
1602
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1603
|
+
#
|
1604
|
+
# May cause a local vulnerability if not called with keyword argument `secure:
|
1605
|
+
# true`; see [Avoiding the TOCTTOU
|
1606
|
+
# Vulnerability](rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability).
|
1607
|
+
#
|
1608
|
+
# For each file path, removes the file at that path:
|
1609
|
+
#
|
1610
|
+
# FileUtils.touch(['src0.txt', 'src0.dat'])
|
1611
|
+
# FileUtils.rm_r(['src0.dat', 'src0.txt'])
|
1612
|
+
# File.exist?('src0.txt') # => false
|
1613
|
+
# File.exist?('src0.dat') # => false
|
1614
|
+
#
|
1615
|
+
# For each directory path, recursively removes files and directories:
|
1616
|
+
#
|
1617
|
+
# tree('src1')
|
1618
|
+
# # => src1
|
1619
|
+
# # |-- dir0
|
1620
|
+
# # | |-- src0.txt
|
1621
|
+
# # | `-- src1.txt
|
1622
|
+
# # `-- dir1
|
1623
|
+
# # |-- src2.txt
|
1624
|
+
# # `-- src3.txt
|
1625
|
+
# FileUtils.rm_r('src1')
|
1626
|
+
# File.exist?('src1') # => false
|
1627
|
+
#
|
1628
|
+
# Keyword arguments:
|
1629
|
+
#
|
1630
|
+
# * `force: true` - ignores raised exceptions of StandardError and its
|
1631
|
+
# descendants.
|
1632
|
+
# * `noop: true` - does not remove entries; returns `nil`.
|
1633
|
+
# * `secure: true` - removes `src` securely; see details at
|
1634
|
+
# FileUtils.remove_entry_secure.
|
1635
|
+
# * `verbose: true` - prints an equivalent command:
|
1636
|
+
#
|
1637
|
+
# FileUtils.rm_r(['src0.dat', 'src0.txt'], noop: true, verbose: true)
|
1638
|
+
# FileUtils.rm_r('src1', noop: true, verbose: true)
|
806
1639
|
#
|
807
|
-
#
|
808
|
-
# FileUtils.rm_r 'some_dir', force: true
|
1640
|
+
# Output:
|
809
1641
|
#
|
810
|
-
#
|
811
|
-
#
|
812
|
-
# permission is 1777), and the current process has strong privilege such as Unix
|
813
|
-
# super user (root), and the system has symbolic link. For secure removing,
|
814
|
-
# read the documentation of remove_entry_secure carefully, and set :secure
|
815
|
-
# option to true. Default is `secure: false`.
|
1642
|
+
# rm -r src0.dat src0.txt
|
1643
|
+
# rm -r src1
|
816
1644
|
#
|
817
|
-
#
|
818
|
-
#
|
1645
|
+
#
|
1646
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
819
1647
|
#
|
820
1648
|
def self?.rm_r: (pathlist list, ?force: boolish, ?noop: boolish, ?verbose: boolish, ?secure: boolish) -> void
|
821
1649
|
|
@@ -823,12 +1651,22 @@ module FileUtils
|
|
823
1651
|
# rdoc-file=lib/fileutils.rb
|
824
1652
|
# - rm_rf(list, noop: nil, verbose: nil, secure: nil)
|
825
1653
|
# -->
|
826
|
-
# Equivalent to
|
1654
|
+
# Equivalent to:
|
1655
|
+
#
|
1656
|
+
# FileUtils.rm_r(list, force: true, **kwargs)
|
1657
|
+
#
|
1658
|
+
# Argument `list` or its elements should be [interpretable as
|
1659
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1660
|
+
#
|
1661
|
+
# May cause a local vulnerability if not called with keyword argument `secure:
|
1662
|
+
# true`; see [Avoiding the TOCTTOU
|
1663
|
+
# Vulnerability](rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability).
|
1664
|
+
#
|
1665
|
+
# See FileUtils.rm_r for keyword arguments.
|
827
1666
|
#
|
828
|
-
#
|
1667
|
+
# FileUtils.rmtree is an alias for FileUtils.rm_rf.
|
829
1668
|
#
|
830
|
-
#
|
831
|
-
# rm_r first.
|
1669
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
832
1670
|
#
|
833
1671
|
def self?.rm_rf: (pathlist list, ?noop: boolish, ?verbose: boolish, ?secure: boolish) -> void
|
834
1672
|
|
@@ -850,12 +1688,37 @@ module FileUtils
|
|
850
1688
|
# rdoc-file=lib/fileutils.rb
|
851
1689
|
# - rmdir(list, parents: nil, noop: nil, verbose: nil)
|
852
1690
|
# -->
|
853
|
-
# Removes
|
1691
|
+
# Removes directories at the paths in the given `list` (a single path or an
|
1692
|
+
# array of paths); returns `list`, if it is an array, `[list]` otherwise.
|
1693
|
+
#
|
1694
|
+
# Argument `list` or its elements should be [interpretable as
|
1695
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1696
|
+
#
|
1697
|
+
# With no keyword arguments, removes the directory at each `path` in `list`, by
|
1698
|
+
# calling: `Dir.rmdir(path)`; see [Dir.rmdir](rdoc-ref:Dir.rmdir):
|
1699
|
+
#
|
1700
|
+
# FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
|
1701
|
+
# FileUtils.rmdir('tmp4/tmp5') # => ["tmp4/tmp5"]
|
1702
|
+
#
|
1703
|
+
# Keyword arguments:
|
1704
|
+
#
|
1705
|
+
# * `parents: true` - removes successive ancestor directories if empty.
|
1706
|
+
# * `noop: true` - does not remove directories.
|
1707
|
+
# * `verbose: true` - prints an equivalent command:
|
854
1708
|
#
|
855
|
-
#
|
856
|
-
#
|
857
|
-
#
|
858
|
-
#
|
1709
|
+
# FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true)
|
1710
|
+
# FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true)
|
1711
|
+
#
|
1712
|
+
# Output:
|
1713
|
+
#
|
1714
|
+
# rmdir -p tmp0/tmp1 tmp2/tmp3
|
1715
|
+
# rmdir -p tmp4/tmp5
|
1716
|
+
#
|
1717
|
+
#
|
1718
|
+
# Raises an exception if a directory does not exist or if for any reason a
|
1719
|
+
# directory cannot be removed.
|
1720
|
+
#
|
1721
|
+
# Related: [methods for deleting](rdoc-ref:FileUtils@Deleting).
|
859
1722
|
#
|
860
1723
|
def self?.rmdir: (pathlist list, ?parents: boolish, ?noop: boolish, ?verbose: boolish) -> void
|
861
1724
|
|
@@ -863,11 +1726,50 @@ module FileUtils
|
|
863
1726
|
# rdoc-file=lib/fileutils.rb
|
864
1727
|
# - touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)
|
865
1728
|
# -->
|
866
|
-
# Updates modification
|
867
|
-
# `list
|
1729
|
+
# Updates modification times (mtime) and access times (atime) of the entries
|
1730
|
+
# given by the paths in `list` (a single path or an array of paths); returns
|
1731
|
+
# `list` if it is an array, `[list]` otherwise.
|
1732
|
+
#
|
1733
|
+
# By default, creates an empty file for any path to a non-existent entry; use
|
1734
|
+
# keyword argument `nocreate` to raise an exception instead.
|
1735
|
+
#
|
1736
|
+
# Argument `list` or its elements should be [interpretable as
|
1737
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments).
|
1738
|
+
#
|
1739
|
+
# Examples:
|
1740
|
+
#
|
1741
|
+
# # Single path.
|
1742
|
+
# f = File.new('src0.txt') # Existing file.
|
1743
|
+
# f.atime # => 2022-06-10 11:11:21.200277 -0700
|
1744
|
+
# f.mtime # => 2022-06-10 11:11:21.200277 -0700
|
1745
|
+
# FileUtils.touch('src0.txt')
|
1746
|
+
# f = File.new('src0.txt')
|
1747
|
+
# f.atime # => 2022-06-11 08:28:09.8185343 -0700
|
1748
|
+
# f.mtime # => 2022-06-11 08:28:09.8185343 -0700
|
1749
|
+
#
|
1750
|
+
# # Array of paths.
|
1751
|
+
# FileUtils.touch(['src0.txt', 'src0.dat'])
|
868
1752
|
#
|
869
|
-
#
|
870
|
-
#
|
1753
|
+
# Keyword arguments:
|
1754
|
+
#
|
1755
|
+
# * `mtime: *time`* - sets the entry's mtime to the given time, instead of the
|
1756
|
+
# current time.
|
1757
|
+
# * `nocreate: true` - raises an exception if the entry does not exist.
|
1758
|
+
# * `noop: true` - does not touch entries; returns `nil`.
|
1759
|
+
# * `verbose: true` - prints an equivalent command:
|
1760
|
+
#
|
1761
|
+
# FileUtils.touch('src0.txt', noop: true, verbose: true)
|
1762
|
+
# FileUtils.touch(['src0.txt', 'src0.dat'], noop: true, verbose: true)
|
1763
|
+
# FileUtils.touch(path, noop: true, verbose: true)
|
1764
|
+
#
|
1765
|
+
# Output:
|
1766
|
+
#
|
1767
|
+
# touch src0.txt
|
1768
|
+
# touch src0.txt src0.dat
|
1769
|
+
# touch src0.txt
|
1770
|
+
#
|
1771
|
+
#
|
1772
|
+
# Related: FileUtils.uptodate?.
|
871
1773
|
#
|
872
1774
|
def self?.touch: (pathlist list, ?noop: boolish, ?verbose: boolish, ?mtime: (Time | Numeric)?, ?nocreate: boolish) -> void
|
873
1775
|
|
@@ -875,11 +1777,18 @@ module FileUtils
|
|
875
1777
|
# rdoc-file=lib/fileutils.rb
|
876
1778
|
# - uptodate?(new, old_list)
|
877
1779
|
# -->
|
878
|
-
# Returns true if `new` is newer than all
|
879
|
-
#
|
1780
|
+
# Returns `true` if the file at path `new` is newer than all the files at paths
|
1781
|
+
# in array `old_list`; `false` otherwise.
|
1782
|
+
#
|
1783
|
+
# Argument `new` and the elements of `old_list` should be [interpretable as
|
1784
|
+
# paths](rdoc-ref:FileUtils@Path+Arguments):
|
1785
|
+
#
|
1786
|
+
# FileUtils.uptodate?('Rakefile', ['Gemfile', 'README.md']) # => true
|
1787
|
+
# FileUtils.uptodate?('Gemfile', ['Rakefile', 'README.md']) # => false
|
1788
|
+
#
|
1789
|
+
# A non-existent file is considered to be infinitely old.
|
880
1790
|
#
|
881
|
-
#
|
882
|
-
# system 'make hello.o'
|
1791
|
+
# Related: FileUtils.touch.
|
883
1792
|
#
|
884
1793
|
def self?.uptodate?: (path new, pathlist old_list) -> bool
|
885
1794
|
end
|