fakefs 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +50 -0
- data/.travis.yml +0 -1
- data/Rakefile +16 -9
- data/fakefs.gemspec +1 -0
- data/lib/fakefs/base.rb +6 -5
- data/lib/fakefs/dir.rb +55 -45
- data/lib/fakefs/fake/dir.rb +5 -3
- data/lib/fakefs/fake/file.rb +9 -4
- data/lib/fakefs/fake/symlink.rb +2 -1
- data/lib/fakefs/file.rb +98 -103
- data/lib/fakefs/file_system.rb +50 -33
- data/lib/fakefs/file_test.rb +1 -0
- data/lib/fakefs/fileutils.rb +72 -71
- data/lib/fakefs/kernel.rb +8 -7
- data/lib/fakefs/pathname.rb +356 -202
- data/lib/fakefs/safe.rb +1 -1
- data/lib/fakefs/spec_helpers.rb +19 -11
- data/lib/fakefs/version.rb +2 -1
- data/spec/fakefs/fakefs_bug_ruby_2.1.0-preview2_spec.rb +2 -2
- data/spec/fakefs/spec_helpers_spec.rb +24 -23
- data/test/dir/tempfile_test.rb +1 -0
- data/test/fake/file/join_test.rb +4 -3
- data/test/fake/file/lstat_test.rb +22 -21
- data/test/fake/file/stat_test.rb +12 -11
- data/test/fake/file/sysseek_test.rb +15 -14
- data/test/fake/file/syswrite_test.rb +25 -24
- data/test/fake/file_test.rb +12 -11
- data/test/fake/symlink_test.rb +18 -10
- data/test/fakefs_test.rb +543 -542
- data/test/file/stat_test.rb +45 -41
- data/test/kernel_test.rb +5 -8
- data/test/safe_test.rb +9 -7
- data/test/test_helper.rb +2 -1
- data/test/verify.rb +6 -3
- metadata +28 -14
data/lib/fakefs/kernel.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
module FakeFS
|
2
|
+
# Kernel Module
|
2
3
|
module Kernel
|
4
|
+
@captives = { original: {}, hijacked: {} }
|
3
5
|
|
4
|
-
@captives = { :original => {}, :hijacked => {}}
|
5
6
|
class << self
|
6
7
|
attr_accessor :captives
|
7
8
|
end
|
8
9
|
|
9
10
|
def self.hijack!
|
10
|
-
captives[:hijacked].each do |name,prc|
|
11
|
+
captives[:hijacked].each do |name, prc|
|
11
12
|
::Kernel.send(:define_method, name.to_sym, &prc)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.unhijack!
|
16
|
-
captives[:original].each do |name,
|
17
|
-
::Kernel.send(:define_method, name.to_sym,
|
17
|
+
captives[:original].each do |name, _prc|
|
18
|
+
::Kernel.send(:define_method, name.to_sym, proc do |*args, &block|
|
18
19
|
::FakeFS::Kernel.captives[:original][name].call(*args, &block)
|
19
20
|
end)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
|
-
|
25
|
+
|
26
|
+
def self.hijack(name, &block)
|
25
27
|
captives[:original][name] = ::Kernel.method(name.to_sym)
|
26
|
-
captives[:hijacked][name] = block ||
|
28
|
+
captives[:hijacked][name] = block || proc { |_args| }
|
27
29
|
end
|
28
30
|
|
29
31
|
hijack :open do |*args, &block|
|
@@ -35,6 +37,5 @@ module FakeFS
|
|
35
37
|
FakeFS::File.open(name, *args, &block)
|
36
38
|
end
|
37
39
|
end
|
38
|
-
|
39
40
|
end
|
40
41
|
end
|
data/lib/fakefs/pathname.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# FakeFS module
|
1
2
|
module FakeFS
|
2
|
-
if RUBY_VERSION >=
|
3
|
-
|
3
|
+
if RUBY_VERSION >= '1.9.3'
|
4
|
+
|
4
5
|
#
|
5
6
|
# = pathname.rb - From MRI 1.9.2
|
6
7
|
#
|
@@ -12,52 +13,68 @@ module FakeFS
|
|
12
13
|
# For documentation, see class Pathname.
|
13
14
|
#
|
14
15
|
class Pathname
|
15
|
-
|
16
|
-
#
|
16
|
+
# to_path is implemented so Pathname objects are
|
17
|
+
# usable with File.open, etc.
|
17
18
|
TO_PATH = :to_path
|
18
19
|
|
19
20
|
SAME_PATHS = if File::FNM_SYSCASE.nonzero?
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
proc { |a, b| a.casecmp(b).zero? }
|
22
|
+
else
|
23
|
+
proc { |a, b| a == b }
|
24
|
+
end
|
24
25
|
|
25
26
|
# :startdoc:
|
26
27
|
|
27
28
|
#
|
28
29
|
# Create a Pathname object from the given String (or String-like object).
|
29
|
-
# If +path+ contains a NUL character (<tt>\0</tt>),
|
30
|
+
# If +path+ contains a NUL character (<tt>\0</tt>),
|
31
|
+
# an ArgumentError is raised.
|
30
32
|
#
|
31
33
|
def initialize(path)
|
32
34
|
path = path.__send__(TO_PATH) if path.respond_to? TO_PATH
|
33
35
|
@path = path.dup
|
34
36
|
|
35
37
|
if /\0/ =~ @path
|
36
|
-
|
38
|
+
fail ArgumentError, "pathname contains \\0: #{@path.inspect}"
|
37
39
|
end
|
38
40
|
|
39
|
-
|
41
|
+
taint if @path.tainted?
|
42
|
+
end
|
43
|
+
|
44
|
+
def freeze
|
45
|
+
super
|
46
|
+
@path.freeze
|
47
|
+
self
|
40
48
|
end
|
41
49
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
50
|
+
def taint
|
51
|
+
super
|
52
|
+
@path.taint
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def untaint
|
57
|
+
super
|
58
|
+
@path.untaint
|
59
|
+
self
|
60
|
+
end
|
45
61
|
|
46
62
|
#
|
47
63
|
# Compare this pathname with +other+. The comparison is string-based.
|
48
|
-
# Be aware that two different paths
|
49
|
-
# can refer to the same file.
|
64
|
+
# Be aware that two different paths
|
65
|
+
# (<tt>foo.txt</tt> and <tt>./foo.txt</tt>) can refer to the same file.
|
50
66
|
#
|
51
67
|
def ==(other)
|
52
|
-
return false unless Pathname
|
68
|
+
return false unless other.is_a?(Pathname)
|
53
69
|
other.to_s == @path
|
54
70
|
end
|
55
|
-
|
56
|
-
|
71
|
+
|
72
|
+
alias_method :===, :==
|
73
|
+
alias_method :eql?, :==
|
57
74
|
|
58
75
|
# Provides for comparing pathnames, case-sensitively.
|
59
76
|
def <=>(other)
|
60
|
-
return nil unless Pathname
|
77
|
+
return nil unless other.is_a?(Pathname)
|
61
78
|
@path.tr('/', "\0") <=> other.to_s.tr('/', "\0")
|
62
79
|
end
|
63
80
|
|
@@ -70,7 +87,8 @@ module FakeFS
|
|
70
87
|
@path.dup
|
71
88
|
end
|
72
89
|
|
73
|
-
# to_path is implemented so Pathname objects are usable
|
90
|
+
# to_path is implemented so Pathname objects are usable
|
91
|
+
# with File.open, etc.
|
74
92
|
alias_method TO_PATH, :to_s
|
75
93
|
|
76
94
|
def inspect # :nodoc:
|
@@ -80,16 +98,17 @@ module FakeFS
|
|
80
98
|
# Return a pathname which is substituted by String#sub.
|
81
99
|
def sub(pattern, *rest, &block)
|
82
100
|
if block
|
83
|
-
path = @path.sub(pattern, *rest)
|
101
|
+
path = @path.sub(pattern, *rest) do |*args|
|
84
102
|
begin
|
85
103
|
old = Thread.current[:pathname_sub_matchdata]
|
86
|
-
Thread.current[:pathname_sub_matchdata] =
|
87
|
-
eval(
|
104
|
+
Thread.current[:pathname_sub_matchdata] = $LAST_MATCH_INFO
|
105
|
+
eval('$~ = Thread.current[:pathname_sub_matchdata]',
|
106
|
+
block.binding)
|
88
107
|
ensure
|
89
108
|
Thread.current[:pathname_sub_matchdata] = old
|
90
109
|
end
|
91
110
|
yield(*args)
|
92
|
-
|
111
|
+
end
|
93
112
|
else
|
94
113
|
path = @path.sub(pattern, *rest)
|
95
114
|
end
|
@@ -97,7 +116,8 @@ module FakeFS
|
|
97
116
|
end
|
98
117
|
|
99
118
|
if File::ALT_SEPARATOR
|
100
|
-
SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}
|
119
|
+
SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}" \
|
120
|
+
"#{Regexp.quote File::SEPARATOR}"
|
101
121
|
SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/
|
102
122
|
else
|
103
123
|
SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}"
|
@@ -127,12 +147,14 @@ module FakeFS
|
|
127
147
|
# split_names(path) -> prefix, [name, ...]
|
128
148
|
def split_names(path)
|
129
149
|
names = []
|
130
|
-
while r = chop_basename(path)
|
150
|
+
while (r = chop_basename(path))
|
131
151
|
path, basename = r
|
132
152
|
names.unshift basename
|
133
153
|
end
|
134
|
-
|
154
|
+
|
155
|
+
[path, names]
|
135
156
|
end
|
157
|
+
|
136
158
|
private :split_names
|
137
159
|
|
138
160
|
def prepend_prefix(prefix, relpath)
|
@@ -140,7 +162,7 @@ module FakeFS
|
|
140
162
|
File.dirname(prefix)
|
141
163
|
elsif /#{SEPARATOR_PAT}/o =~ prefix
|
142
164
|
prefix = File.dirname(prefix)
|
143
|
-
prefix = File.join(prefix,
|
165
|
+
prefix = File.join(prefix, '') if File.basename(prefix + 'a') != 'a'
|
144
166
|
prefix + relpath
|
145
167
|
else
|
146
168
|
prefix + relpath
|
@@ -148,15 +170,16 @@ module FakeFS
|
|
148
170
|
end
|
149
171
|
private :prepend_prefix
|
150
172
|
|
151
|
-
# Returns clean pathname of +self+ with consecutive slashes and
|
152
|
-
# removed.
|
173
|
+
# Returns clean pathname of +self+ with consecutive slashes and
|
174
|
+
# useless dots removed. The filesystem is not accessed.
|
153
175
|
#
|
154
|
-
# If +consider_symlink+ is +true+, then a more conservative algorithm
|
155
|
-
# to avoid breaking symbolic linkages.
|
156
|
-
#
|
157
|
-
# this can't be avoided.
|
176
|
+
# If +consider_symlink+ is +true+, then a more conservative algorithm
|
177
|
+
# is used to avoid breaking symbolic linkages.
|
178
|
+
# This may retain more <tt>..</tt> entries than absolutely necessary,
|
179
|
+
# but without accessing the filesystem, this can't be avoided.
|
180
|
+
# See #realpath.
|
158
181
|
#
|
159
|
-
def cleanpath(consider_symlink=false)
|
182
|
+
def cleanpath(consider_symlink = false)
|
160
183
|
if consider_symlink
|
161
184
|
cleanpath_conservative
|
162
185
|
else
|
@@ -165,14 +188,15 @@ module FakeFS
|
|
165
188
|
end
|
166
189
|
|
167
190
|
#
|
168
|
-
# Clean the path simply by resolving and removing excess
|
191
|
+
# Clean the path simply by resolving and removing excess
|
192
|
+
# "." and ".." entries.
|
169
193
|
# Nothing more, nothing less.
|
170
194
|
#
|
171
195
|
def cleanpath_aggressive
|
172
196
|
path = @path
|
173
197
|
names = []
|
174
198
|
pre = path
|
175
|
-
while r = chop_basename(pre)
|
199
|
+
while (r = chop_basename(pre))
|
176
200
|
pre, base = r
|
177
201
|
case base
|
178
202
|
when '.'
|
@@ -193,29 +217,31 @@ module FakeFS
|
|
193
217
|
end
|
194
218
|
private :cleanpath_aggressive
|
195
219
|
|
196
|
-
#
|
197
|
-
def
|
198
|
-
if r = chop_basename(path)
|
220
|
+
# trailing_separator?(path) -> bool
|
221
|
+
def trailing_separator?(path)
|
222
|
+
if (r = chop_basename(path))
|
199
223
|
pre, basename = r
|
200
224
|
pre.length + basename.length < path.length
|
201
225
|
else
|
202
226
|
false
|
203
227
|
end
|
204
228
|
end
|
205
|
-
|
229
|
+
|
230
|
+
private :trailing_separator?
|
206
231
|
|
207
232
|
# add_trailing_separator(path) -> path
|
208
233
|
def add_trailing_separator(path)
|
209
234
|
if File.basename(path + 'a') == 'a'
|
210
235
|
path
|
211
236
|
else
|
212
|
-
|
237
|
+
# xxx: Is File.join is appropriate to add separator?
|
238
|
+
File.join(path, '')
|
213
239
|
end
|
214
240
|
end
|
215
241
|
private :add_trailing_separator
|
216
242
|
|
217
243
|
def del_trailing_separator(path)
|
218
|
-
if r = chop_basename(path)
|
244
|
+
if (r = chop_basename(path))
|
219
245
|
pre, basename = r
|
220
246
|
pre + basename
|
221
247
|
elsif /#{SEPARATOR_PAT}+\z/o =~ path
|
@@ -230,7 +256,7 @@ module FakeFS
|
|
230
256
|
path = @path
|
231
257
|
names = []
|
232
258
|
pre = path
|
233
|
-
while r = chop_basename(pre)
|
259
|
+
while (r = chop_basename(pre))
|
234
260
|
pre, base = r
|
235
261
|
names.unshift base if base != '.'
|
236
262
|
end
|
@@ -240,11 +266,10 @@ module FakeFS
|
|
240
266
|
if names.empty?
|
241
267
|
self.class.new(File.dirname(pre))
|
242
268
|
else
|
243
|
-
if names.last != '..' && File.basename(path) == '.'
|
244
|
-
|
245
|
-
end
|
269
|
+
names << '.' if names.last != '..' && File.basename(path) == '.'
|
270
|
+
|
246
271
|
result = prepend_prefix(pre, File.join(*names))
|
247
|
-
if /\A(?:\.|\.\.)\z/ !~ names.last &&
|
272
|
+
if /\A(?:\.|\.\.)\z/ !~ names.last && trailing_separator?(path)
|
248
273
|
self.class.new(add_trailing_separator(result))
|
249
274
|
else
|
250
275
|
self.class.new(result)
|
@@ -260,7 +285,7 @@ module FakeFS
|
|
260
285
|
# All components of the pathname must exist when this method is
|
261
286
|
# called.
|
262
287
|
#
|
263
|
-
def realpath(basedir=nil)
|
288
|
+
def realpath(basedir = nil)
|
264
289
|
self.class.new(File.realpath(@path, basedir))
|
265
290
|
end
|
266
291
|
|
@@ -270,7 +295,7 @@ module FakeFS
|
|
270
295
|
#
|
271
296
|
# The last component of the real pathname can be nonexistent.
|
272
297
|
#
|
273
|
-
def realdirpath(basedir=nil)
|
298
|
+
def realdirpath(basedir = nil)
|
274
299
|
self.class.new(File.realdirpath(@path, basedir))
|
275
300
|
end
|
276
301
|
|
@@ -283,9 +308,9 @@ module FakeFS
|
|
283
308
|
|
284
309
|
# #mountpoint? returns +true+ if <tt>self</tt> points to a mountpoint.
|
285
310
|
def mountpoint?
|
311
|
+
stat1 = lstat
|
286
312
|
begin
|
287
|
-
|
288
|
-
stat2 = self.parent.lstat
|
313
|
+
stat2 = parent.lstat
|
289
314
|
stat1.dev == stat2.dev && stat1.ino == stat2.ino ||
|
290
315
|
stat1.dev != stat2.dev
|
291
316
|
rescue Errno::ENOENT
|
@@ -294,14 +319,15 @@ module FakeFS
|
|
294
319
|
end
|
295
320
|
|
296
321
|
#
|
297
|
-
# #root? is a predicate for root directories.
|
322
|
+
# #root? is a predicate for root directories.
|
323
|
+
# I.e. it returns +true+ if the
|
298
324
|
# pathname consists of consecutive slashes.
|
299
325
|
#
|
300
326
|
# It doesn't access actual filesystem. So it may return +false+ for some
|
301
327
|
# pathnames which points to roots such as <tt>/usr/..</tt>.
|
302
328
|
#
|
303
329
|
def root?
|
304
|
-
|
330
|
+
!(chop_basename(@path).nil? && /#{SEPARATOR_PAT}/o =~ @path).nil?
|
305
331
|
end
|
306
332
|
|
307
333
|
# Predicate method for testing whether a path is absolute.
|
@@ -313,8 +339,8 @@ module FakeFS
|
|
313
339
|
# The opposite of #absolute?
|
314
340
|
def relative?
|
315
341
|
path = @path
|
316
|
-
while r = chop_basename(path)
|
317
|
-
path,
|
342
|
+
while (r = chop_basename(path))
|
343
|
+
path, _basename = r
|
318
344
|
end
|
319
345
|
path == ''
|
320
346
|
end
|
@@ -322,27 +348,27 @@ module FakeFS
|
|
322
348
|
#
|
323
349
|
# Iterates over each component of the path.
|
324
350
|
#
|
325
|
-
# Pathname.new("/usr/bin/ruby").each_filename {|filename| ... }
|
351
|
+
# Pathname.new("/usr/bin/ruby").each_filename { |filename| ... }
|
326
352
|
# # yields "usr", "bin", and "ruby".
|
327
353
|
#
|
328
354
|
def each_filename # :yield: filename
|
329
355
|
return to_enum(__method__) unless block_given?
|
330
|
-
|
331
|
-
names.each {|filename| yield filename }
|
356
|
+
_prefix, names = split_names(@path)
|
357
|
+
names.each { |filename| yield filename }
|
332
358
|
nil
|
333
359
|
end
|
334
360
|
|
335
361
|
# Iterates over and yields a new Pathname object
|
336
362
|
# for each element in the given path in descending order.
|
337
363
|
#
|
338
|
-
# Pathname.new('/path/to/some/file.rb').descend {|v| p v}
|
364
|
+
# Pathname.new('/path/to/some/file.rb').descend { |v| p v}
|
339
365
|
# #<Pathname:/>
|
340
366
|
# #<Pathname:/path>
|
341
367
|
# #<Pathname:/path/to>
|
342
368
|
# #<Pathname:/path/to/some>
|
343
369
|
# #<Pathname:/path/to/some/file.rb>
|
344
370
|
#
|
345
|
-
# Pathname.new('path/to/some/file.rb').descend {|v| p v}
|
371
|
+
# Pathname.new('path/to/some/file.rb').descend { |v| p v}
|
346
372
|
# #<Pathname:path>
|
347
373
|
# #<Pathname:path/to>
|
348
374
|
# #<Pathname:path/to/some>
|
@@ -354,22 +380,22 @@ module FakeFS
|
|
354
380
|
#
|
355
381
|
def descend
|
356
382
|
vs = []
|
357
|
-
ascend {|v| vs << v }
|
358
|
-
vs.reverse_each {|v| yield v }
|
383
|
+
ascend { |v| vs << v }
|
384
|
+
vs.reverse_each { |v| yield v }
|
359
385
|
nil
|
360
386
|
end
|
361
387
|
|
362
388
|
# Iterates over and yields a new Pathname object
|
363
389
|
# for each element in the given path in ascending order.
|
364
390
|
#
|
365
|
-
# Pathname.new('/path/to/some/file.rb').ascend {|v| p v}
|
391
|
+
# Pathname.new('/path/to/some/file.rb').ascend { |v| p v}
|
366
392
|
# #<Pathname:/path/to/some/file.rb>
|
367
393
|
# #<Pathname:/path/to/some>
|
368
394
|
# #<Pathname:/path/to>
|
369
395
|
# #<Pathname:/path>
|
370
396
|
# #<Pathname:/>
|
371
397
|
#
|
372
|
-
# Pathname.new('path/to/some/file.rb').ascend {|v| p v}
|
398
|
+
# Pathname.new('path/to/some/file.rb').ascend { |v| p v}
|
373
399
|
# #<Pathname:path/to/some/file.rb>
|
374
400
|
# #<Pathname:path/to/some>
|
375
401
|
# #<Pathname:path/to>
|
@@ -382,25 +408,27 @@ module FakeFS
|
|
382
408
|
def ascend
|
383
409
|
path = @path
|
384
410
|
yield self
|
385
|
-
while r = chop_basename(path)
|
386
|
-
path,
|
411
|
+
while (r = chop_basename(path))
|
412
|
+
path, _name = r
|
387
413
|
break if path.empty?
|
388
414
|
yield self.class.new(del_trailing_separator(path))
|
389
415
|
end
|
390
416
|
end
|
391
417
|
|
392
418
|
#
|
393
|
-
# Pathname#+ appends a pathname fragment to this one to produce a new
|
419
|
+
# Pathname#+ appends a pathname fragment to this one to produce a new
|
420
|
+
# Pathname
|
394
421
|
# object.
|
395
422
|
#
|
396
423
|
# p1 = Pathname.new("/usr") # Pathname:/usr
|
397
424
|
# p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby
|
398
425
|
# p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd
|
399
426
|
#
|
400
|
-
# This method doesn't access the file system; it is pure string
|
427
|
+
# This method doesn't access the file system; it is pure string
|
428
|
+
# manipulation.
|
401
429
|
#
|
402
430
|
def +(other)
|
403
|
-
other = Pathname.new(other) unless Pathname
|
431
|
+
other = Pathname.new(other) unless other.is_a?(Pathname)
|
404
432
|
Pathname.new(plus(@path, other.to_s))
|
405
433
|
end
|
406
434
|
|
@@ -408,28 +436,33 @@ module FakeFS
|
|
408
436
|
prefix2 = path2
|
409
437
|
index_list2 = []
|
410
438
|
basename_list2 = []
|
411
|
-
while r2 = chop_basename(prefix2)
|
439
|
+
while (r2 = chop_basename(prefix2))
|
412
440
|
prefix2, basename2 = r2
|
413
441
|
index_list2.unshift prefix2.length
|
414
442
|
basename_list2.unshift basename2
|
415
443
|
end
|
444
|
+
|
416
445
|
return path2 if prefix2 != ''
|
446
|
+
|
417
447
|
prefix1 = path1
|
418
|
-
while
|
448
|
+
while (r1 = chop_basename(prefix1))
|
419
449
|
while !basename_list2.empty? && basename_list2.first == '.'
|
420
450
|
index_list2.shift
|
421
451
|
basename_list2.shift
|
422
452
|
end
|
423
|
-
|
453
|
+
|
424
454
|
prefix1, basename1 = r1
|
425
455
|
next if basename1 == '.'
|
426
|
-
if basename1 == '..' ||
|
427
|
-
|
456
|
+
if basename1 == '..' ||
|
457
|
+
basename_list2.empty? ||
|
458
|
+
basename_list2.first != '..'
|
459
|
+
prefix1 += basename1
|
428
460
|
break
|
429
461
|
end
|
430
462
|
index_list2.shift
|
431
463
|
basename_list2.shift
|
432
464
|
end
|
465
|
+
|
433
466
|
r1 = chop_basename(prefix1)
|
434
467
|
if !r1 && /#{SEPARATOR_PAT}/o =~ File.basename(prefix1)
|
435
468
|
while !basename_list2.empty? && basename_list2.first == '..'
|
@@ -437,6 +470,7 @@ module FakeFS
|
|
437
470
|
basename_list2.shift
|
438
471
|
end
|
439
472
|
end
|
473
|
+
|
440
474
|
if !basename_list2.empty?
|
441
475
|
suffix2 = path2[index_list2.first..-1]
|
442
476
|
r1 ? File.join(prefix1, suffix2) : prefix1 + suffix2
|
@@ -455,13 +489,13 @@ module FakeFS
|
|
455
489
|
def join(*args)
|
456
490
|
args.unshift self
|
457
491
|
result = args.pop
|
458
|
-
result = Pathname.new(result) unless Pathname
|
492
|
+
result = Pathname.new(result) unless result.is_a?(Pathname)
|
459
493
|
return result if result.absolute?
|
460
|
-
args.reverse_each
|
461
|
-
arg = Pathname.new(arg) unless Pathname
|
494
|
+
args.reverse_each do |arg|
|
495
|
+
arg = Pathname.new(arg) unless arg.is_a?(Pathname)
|
462
496
|
result = arg + result
|
463
497
|
return result if result.absolute?
|
464
|
-
|
498
|
+
end
|
465
499
|
result
|
466
500
|
end
|
467
501
|
|
@@ -469,44 +503,50 @@ module FakeFS
|
|
469
503
|
# Returns the children of the directory (files and subdirectories, not
|
470
504
|
# recursive) as an array of Pathname objects. By default, the returned
|
471
505
|
# pathnames will have enough information to access the files. If you set
|
472
|
-
# +with_directory+ to +false+, then the returned
|
506
|
+
# +with_directory+ to +false+, then the returned
|
507
|
+
# pathnames will contain the
|
473
508
|
# filename only.
|
474
509
|
#
|
475
510
|
# For example:
|
476
511
|
# pn = Pathname("/usr/lib/ruby/1.8")
|
477
512
|
# pn.children
|
478
|
-
#
|
479
|
-
#
|
480
|
-
#
|
513
|
+
# # -> [ Pathname:/usr/lib/ruby/1.8/English.rb,
|
514
|
+
# Pathname:/usr/lib/ruby/1.8/Env.rb,
|
515
|
+
# Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ]
|
481
516
|
# pn.children(false)
|
482
|
-
#
|
517
|
+
# # -> [ Pathname:English.rb,
|
518
|
+
# Pathname:Env.rb,
|
519
|
+
# Pathname:abbrev.rb, ... ]
|
483
520
|
#
|
484
|
-
# Note that the result never contain the entries
|
521
|
+
# Note that the result never contain the entries
|
522
|
+
# <tt>.</tt> and <tt>..</tt> in
|
485
523
|
# the directory because they are not children.
|
486
524
|
#
|
487
525
|
# This method has existed since 1.8.1.
|
488
526
|
#
|
489
|
-
def children(with_directory=true)
|
527
|
+
def children(with_directory = true)
|
490
528
|
with_directory = false if @path == '.'
|
491
529
|
result = []
|
492
|
-
Dir.foreach(@path)
|
530
|
+
Dir.foreach(@path) do |e|
|
493
531
|
next if e == '.' || e == '..'
|
494
532
|
if with_directory
|
495
533
|
result << self.class.new(File.join(@path, e))
|
496
534
|
else
|
497
535
|
result << self.class.new(e)
|
498
536
|
end
|
499
|
-
|
537
|
+
end
|
500
538
|
result
|
501
539
|
end
|
502
540
|
|
503
541
|
# Iterates over the children of the directory
|
504
542
|
# (files and subdirectories, not recursive).
|
505
543
|
# It yields Pathname object for each child.
|
506
|
-
# By default, the yielded pathnames will have enough information to access
|
507
|
-
#
|
544
|
+
# By default, the yielded pathnames will have enough information to access
|
545
|
+
# the files.
|
546
|
+
# If you set +with_directory+ to +false+,
|
547
|
+
# then the returned pathnames will contain the filename only.
|
508
548
|
#
|
509
|
-
# Pathname("/usr/local").each_child {|f| p f }
|
549
|
+
# Pathname("/usr/local").each_child { |f| p f }
|
510
550
|
# #=> #<Pathname:/usr/local/share>
|
511
551
|
# # #<Pathname:/usr/local/bin>
|
512
552
|
# # #<Pathname:/usr/local/games>
|
@@ -516,7 +556,7 @@ module FakeFS
|
|
516
556
|
# # #<Pathname:/usr/local/src>
|
517
557
|
# # #<Pathname:/usr/local/man>
|
518
558
|
#
|
519
|
-
# Pathname("/usr/local").each_child(false) {|f| p f }
|
559
|
+
# Pathname("/usr/local").each_child(false) { |f| p f }
|
520
560
|
# #=> #<Pathname:share>
|
521
561
|
# # #<Pathname:bin>
|
522
562
|
# # #<Pathname:games>
|
@@ -526,38 +566,40 @@ module FakeFS
|
|
526
566
|
# # #<Pathname:src>
|
527
567
|
# # #<Pathname:man>
|
528
568
|
#
|
529
|
-
def each_child(with_directory=true, &b)
|
569
|
+
def each_child(with_directory = true, &b)
|
530
570
|
children(with_directory).each(&b)
|
531
571
|
end
|
532
572
|
|
533
573
|
#
|
534
574
|
# #relative_path_from returns a relative path from the argument to the
|
535
|
-
# receiver. If +self+ is absolute, the argument must be absolute too.
|
575
|
+
# receiver. If +self+ is absolute, the argument must be absolute too. If
|
536
576
|
# +self+ is relative, the argument must be relative too.
|
537
577
|
#
|
538
|
-
# #relative_path_from doesn't access the filesystem.
|
578
|
+
# #relative_path_from doesn't access the filesystem.
|
579
|
+
# It assumes no symlinks.
|
539
580
|
#
|
540
581
|
# ArgumentError is raised when it cannot find a relative path.
|
541
582
|
#
|
542
583
|
# This method has existed since 1.8.1.
|
543
584
|
#
|
544
585
|
def relative_path_from(base_directory)
|
545
|
-
dest_directory =
|
586
|
+
dest_directory = cleanpath.to_s
|
546
587
|
base_directory = base_directory.cleanpath.to_s
|
547
588
|
dest_prefix = dest_directory
|
548
589
|
dest_names = []
|
549
|
-
while r = chop_basename(dest_prefix)
|
590
|
+
while (r = chop_basename(dest_prefix)) == true
|
550
591
|
dest_prefix, basename = r
|
551
592
|
dest_names.unshift basename if basename != '.'
|
552
593
|
end
|
553
594
|
base_prefix = base_directory
|
554
595
|
base_names = []
|
555
|
-
while r = chop_basename(base_prefix)
|
596
|
+
while (r = chop_basename(base_prefix)) == true
|
556
597
|
base_prefix, basename = r
|
557
598
|
base_names.unshift basename if basename != '.'
|
558
599
|
end
|
559
600
|
unless SAME_PATHS[dest_prefix, base_prefix]
|
560
|
-
|
601
|
+
fail ArgumentError, "different prefix: #{dest_prefix.inspect} " \
|
602
|
+
"and #{base_directory.inspect}"
|
561
603
|
end
|
562
604
|
while !dest_names.empty? &&
|
563
605
|
!base_names.empty? &&
|
@@ -566,7 +608,7 @@ module FakeFS
|
|
566
608
|
base_names.shift
|
567
609
|
end
|
568
610
|
if base_names.include? '..'
|
569
|
-
|
611
|
+
fail ArgumentError, "base_directory has ..: #{base_directory.inspect}"
|
570
612
|
end
|
571
613
|
base_names.fill('..')
|
572
614
|
relpath_names = base_names + dest_names
|
@@ -578,10 +620,11 @@ module FakeFS
|
|
578
620
|
end
|
579
621
|
end
|
580
622
|
|
623
|
+
# Pathname class
|
581
624
|
class Pathname # * IO *
|
582
625
|
#
|
583
|
-
# #each_line iterates over the line in the file.
|
584
|
-
# for each line.
|
626
|
+
# #each_line iterates over the line in the file.
|
627
|
+
# It yields a String object for each line.
|
585
628
|
#
|
586
629
|
# This method has existed since 1.8.1.
|
587
630
|
#
|
@@ -589,58 +632,88 @@ module FakeFS
|
|
589
632
|
IO.foreach(@path, *args, &block)
|
590
633
|
end
|
591
634
|
|
592
|
-
# See <tt>IO.read</tt>.
|
593
|
-
# if specified.
|
594
|
-
def read(*args)
|
635
|
+
# See <tt>IO.read</tt>. Returns all data from the file,
|
636
|
+
# or the first +N+ bytes if specified.
|
637
|
+
def read(*args)
|
638
|
+
IO.read(@path, *args)
|
639
|
+
end
|
595
640
|
|
596
|
-
# See <tt>IO.binread</tt>. Returns all the bytes from the file,
|
597
|
-
# if specified.
|
598
|
-
def binread(*args)
|
641
|
+
# See <tt>IO.binread</tt>. Returns all the bytes from the file,
|
642
|
+
# or the first +N+ if specified.
|
643
|
+
def binread(*args)
|
644
|
+
IO.binread(@path, *args)
|
645
|
+
end
|
599
646
|
|
600
647
|
# See <tt>IO.readlines</tt>. Returns all the lines from the file.
|
601
|
-
def readlines(*args)
|
648
|
+
def readlines(*args)
|
649
|
+
IO.readlines(@path, *args)
|
650
|
+
end
|
602
651
|
|
603
652
|
# See <tt>IO.sysopen</tt>.
|
604
|
-
def sysopen(*args)
|
653
|
+
def sysopen(*args)
|
654
|
+
IO.sysopen(@path, *args)
|
655
|
+
end
|
605
656
|
end
|
606
657
|
|
607
|
-
|
658
|
+
# Pathnam class
|
608
659
|
class Pathname # * File *
|
609
|
-
|
610
660
|
# See <tt>File.atime</tt>. Returns last access time.
|
611
|
-
def atime
|
661
|
+
def atime
|
662
|
+
File.atime(@path)
|
663
|
+
end
|
612
664
|
|
613
|
-
# See <tt>File.ctime</tt>.
|
614
|
-
|
665
|
+
# See <tt>File.ctime</tt>.
|
666
|
+
# Returns last (directory entry, not file) change time.
|
667
|
+
def ctime
|
668
|
+
File.ctime(@path)
|
669
|
+
end
|
615
670
|
|
616
671
|
# See <tt>File.mtime</tt>. Returns last modification time.
|
617
|
-
def mtime
|
672
|
+
def mtime
|
673
|
+
File.mtime(@path)
|
674
|
+
end
|
618
675
|
|
619
676
|
# See <tt>File.chmod</tt>. Changes permissions.
|
620
|
-
def chmod(mode)
|
677
|
+
def chmod(mode)
|
678
|
+
File.chmod(mode, @path)
|
679
|
+
end
|
621
680
|
|
622
681
|
# See <tt>File.lchmod</tt>.
|
623
|
-
def lchmod(mode)
|
682
|
+
def lchmod(mode)
|
683
|
+
File.lchmod(mode, @path)
|
684
|
+
end
|
624
685
|
|
625
686
|
# See <tt>File.chown</tt>. Change owner and group of file.
|
626
|
-
def chown(owner, group)
|
687
|
+
def chown(owner, group)
|
688
|
+
File.chown(owner, group, @path)
|
689
|
+
end
|
627
690
|
|
628
691
|
# See <tt>File.lchown</tt>.
|
629
|
-
def lchown(owner, group)
|
692
|
+
def lchown(owner, group)
|
693
|
+
File.lchown(owner, group, @path)
|
694
|
+
end
|
630
695
|
|
631
|
-
# See <tt>File.fnmatch</tt>. Return +true+
|
632
|
-
# pattern
|
633
|
-
def fnmatch(pattern, *args)
|
696
|
+
# See <tt>File.fnmatch</tt>. Return +true+
|
697
|
+
# if the receiver matches the given pattern
|
698
|
+
def fnmatch(pattern, *args)
|
699
|
+
File.fnmatch(pattern, @path, *args)
|
700
|
+
end
|
634
701
|
|
635
702
|
# See <tt>File.fnmatch?</tt> (same as #fnmatch).
|
636
|
-
def fnmatch?(pattern, *args)
|
703
|
+
def fnmatch?(pattern, *args)
|
704
|
+
File.fnmatch?(pattern, @path, *args)
|
705
|
+
end
|
637
706
|
|
638
707
|
# See <tt>File.ftype</tt>. Returns "type" of file ("file", "directory",
|
639
708
|
# etc).
|
640
|
-
def ftype
|
709
|
+
def ftype
|
710
|
+
File.ftype(@path)
|
711
|
+
end
|
641
712
|
|
642
713
|
# See <tt>File.link</tt>. Creates a hard link.
|
643
|
-
def make_link(old)
|
714
|
+
def make_link(old)
|
715
|
+
File.link(old, @path)
|
716
|
+
end
|
644
717
|
|
645
718
|
# See <tt>File.open</tt>. Opens the file for reading or writing.
|
646
719
|
def open(*args, &block) # :yield: file
|
@@ -648,151 +721,233 @@ module FakeFS
|
|
648
721
|
end
|
649
722
|
|
650
723
|
# See <tt>File.readlink</tt>. Read symbolic link.
|
651
|
-
def readlink
|
724
|
+
def readlink
|
725
|
+
self.class.new(File.readlink(@path))
|
726
|
+
end
|
652
727
|
|
653
728
|
# See <tt>File.rename</tt>. Rename the file.
|
654
|
-
def rename(to)
|
729
|
+
def rename(to)
|
730
|
+
File.rename(@path, to)
|
731
|
+
end
|
655
732
|
|
656
733
|
# See <tt>File.stat</tt>. Returns a <tt>File::Stat</tt> object.
|
657
|
-
def stat
|
734
|
+
def stat
|
735
|
+
File.stat(@path)
|
736
|
+
end
|
658
737
|
|
659
738
|
# See <tt>File.lstat</tt>.
|
660
|
-
def lstat
|
739
|
+
def lstat
|
740
|
+
File.lstat(@path)
|
741
|
+
end
|
661
742
|
|
662
743
|
# See <tt>File.symlink</tt>. Creates a symbolic link.
|
663
|
-
def make_symlink(old)
|
744
|
+
def make_symlink(old)
|
745
|
+
File.symlink(old, @path)
|
746
|
+
end
|
664
747
|
|
665
748
|
# See <tt>File.truncate</tt>. Truncate the file to +length+ bytes.
|
666
|
-
def truncate(length)
|
749
|
+
def truncate(length)
|
750
|
+
File.truncate(@path, length)
|
751
|
+
end
|
667
752
|
|
668
753
|
# See <tt>File.utime</tt>. Update the access and modification times.
|
669
|
-
def utime(atime, mtime)
|
754
|
+
def utime(atime, mtime)
|
755
|
+
File.utime(atime, mtime, @path)
|
756
|
+
end
|
670
757
|
|
671
758
|
# See <tt>File.basename</tt>. Returns the last component of the path.
|
672
|
-
def basename(*args)
|
759
|
+
def basename(*args)
|
760
|
+
self.class.new(File.basename(@path, *args))
|
761
|
+
end
|
673
762
|
|
674
|
-
# See <tt>File.dirname</tt>. Returns all but the last
|
675
|
-
|
763
|
+
# See <tt>File.dirname</tt>. Returns all but the last
|
764
|
+
# component of the path.
|
765
|
+
def dirname
|
766
|
+
self.class.new(File.dirname(@path))
|
767
|
+
end
|
676
768
|
|
677
769
|
# See <tt>File.extname</tt>. Returns the file's extension.
|
678
|
-
def extname
|
770
|
+
def extname
|
771
|
+
File.extname(@path)
|
772
|
+
end
|
679
773
|
|
680
774
|
# See <tt>File.expand_path</tt>.
|
681
|
-
def expand_path(*args)
|
775
|
+
def expand_path(*args)
|
776
|
+
self.class.new(File.expand_path(@path, *args))
|
777
|
+
end
|
682
778
|
|
683
779
|
# See <tt>File.split</tt>. Returns the #dirname and the #basename in an
|
684
780
|
# Array.
|
685
|
-
def split
|
781
|
+
def split
|
782
|
+
File.split(@path).map { |f| self.class.new(f) }
|
783
|
+
end
|
686
784
|
end
|
687
785
|
|
688
|
-
|
786
|
+
# Pathname class
|
689
787
|
class Pathname # * FileTest *
|
690
|
-
|
691
788
|
# See <tt>FileTest.blockdev?</tt>.
|
692
|
-
def blockdev?
|
789
|
+
def blockdev?
|
790
|
+
FileTest.blockdev?(@path)
|
791
|
+
end
|
693
792
|
|
694
793
|
# See <tt>FileTest.chardev?</tt>.
|
695
|
-
def chardev?
|
794
|
+
def chardev?
|
795
|
+
FileTest.chardev?(@path)
|
796
|
+
end
|
696
797
|
|
697
798
|
# See <tt>FileTest.executable?</tt>.
|
698
|
-
def executable?
|
799
|
+
def executable?
|
800
|
+
FileTest.executable?(@path)
|
801
|
+
end
|
699
802
|
|
700
803
|
# See <tt>FileTest.executable_real?</tt>.
|
701
|
-
def executable_real?
|
804
|
+
def executable_real?
|
805
|
+
FileTest.executable_real?(@path)
|
806
|
+
end
|
702
807
|
|
703
808
|
# See <tt>FileTest.exist?</tt>.
|
704
|
-
def exist?
|
809
|
+
def exist?
|
810
|
+
FileTest.exist?(@path)
|
811
|
+
end
|
705
812
|
|
706
813
|
# See <tt>FileTest.grpowned?</tt>.
|
707
|
-
def grpowned?
|
814
|
+
def grpowned?
|
815
|
+
FileTest.grpowned?(@path)
|
816
|
+
end
|
708
817
|
|
709
818
|
# See <tt>FileTest.directory?</tt>.
|
710
|
-
def directory?
|
819
|
+
def directory?
|
820
|
+
FileTest.directory?(@path)
|
821
|
+
end
|
711
822
|
|
712
823
|
# See <tt>FileTest.file?</tt>.
|
713
|
-
def file?
|
824
|
+
def file?
|
825
|
+
FileTest.file?(@path)
|
826
|
+
end
|
714
827
|
|
715
828
|
# See <tt>FileTest.pipe?</tt>.
|
716
|
-
def pipe?
|
829
|
+
def pipe?
|
830
|
+
FileTest.pipe?(@path)
|
831
|
+
end
|
717
832
|
|
718
833
|
# See <tt>FileTest.socket?</tt>.
|
719
|
-
def socket?
|
834
|
+
def socket?
|
835
|
+
FileTest.socket?(@path)
|
836
|
+
end
|
720
837
|
|
721
838
|
# See <tt>FileTest.owned?</tt>.
|
722
|
-
def owned?
|
839
|
+
def owned?
|
840
|
+
FileTest.owned?(@path)
|
841
|
+
end
|
723
842
|
|
724
843
|
# See <tt>FileTest.readable?</tt>.
|
725
|
-
def readable?
|
844
|
+
def readable?
|
845
|
+
FileTest.readable?(@path)
|
846
|
+
end
|
726
847
|
|
727
848
|
# See <tt>FileTest.world_readable?</tt>.
|
728
|
-
def world_readable?
|
849
|
+
def world_readable?
|
850
|
+
FileTest.world_readable?(@path)
|
851
|
+
end
|
729
852
|
|
730
853
|
# See <tt>FileTest.readable_real?</tt>.
|
731
|
-
def readable_real?
|
854
|
+
def readable_real?
|
855
|
+
FileTest.readable_real?(@path)
|
856
|
+
end
|
732
857
|
|
733
858
|
# See <tt>FileTest.setuid?</tt>.
|
734
|
-
def setuid?
|
859
|
+
def setuid?
|
860
|
+
FileTest.setuid?(@path)
|
861
|
+
end
|
735
862
|
|
736
863
|
# See <tt>FileTest.setgid?</tt>.
|
737
|
-
def setgid?
|
864
|
+
def setgid?
|
865
|
+
FileTest.setgid?(@path)
|
866
|
+
end
|
738
867
|
|
739
868
|
# See <tt>FileTest.size</tt>.
|
740
|
-
def size
|
869
|
+
def size
|
870
|
+
FileTest.size(@path)
|
871
|
+
end
|
741
872
|
|
742
873
|
# See <tt>FileTest.size?</tt>.
|
743
|
-
def size?
|
874
|
+
def size?
|
875
|
+
FileTest.size?(@path)
|
876
|
+
end
|
744
877
|
|
745
878
|
# See <tt>FileTest.sticky?</tt>.
|
746
|
-
def sticky?
|
879
|
+
def sticky?
|
880
|
+
FileTest.sticky?(@path)
|
881
|
+
end
|
747
882
|
|
748
883
|
# See <tt>FileTest.symlink?</tt>.
|
749
|
-
def symlink?
|
884
|
+
def symlink?
|
885
|
+
FileTest.symlink?(@path)
|
886
|
+
end
|
750
887
|
|
751
888
|
# See <tt>FileTest.writable?</tt>.
|
752
|
-
def writable?
|
889
|
+
def writable?
|
890
|
+
FileTest.writable?(@path)
|
891
|
+
end
|
753
892
|
|
754
893
|
# See <tt>FileTest.world_writable?</tt>.
|
755
|
-
def world_writable?
|
894
|
+
def world_writable?
|
895
|
+
FileTest.world_writable?(@path)
|
896
|
+
end
|
756
897
|
|
757
898
|
# See <tt>FileTest.writable_real?</tt>.
|
758
|
-
def writable_real?
|
899
|
+
def writable_real?
|
900
|
+
FileTest.writable_real?(@path)
|
901
|
+
end
|
759
902
|
|
760
903
|
# See <tt>FileTest.zero?</tt>.
|
761
|
-
def zero?
|
904
|
+
def zero?
|
905
|
+
FileTest.zero?(@path)
|
906
|
+
end
|
762
907
|
end
|
763
908
|
|
764
|
-
|
909
|
+
# Pathname class
|
765
910
|
class Pathname # * Dir *
|
766
911
|
# See <tt>Dir.glob</tt>. Returns or yields Pathname objects.
|
767
|
-
def
|
912
|
+
def self.glob(*args) # :yield: pathname
|
768
913
|
if block_given?
|
769
|
-
Dir.glob(*args) {|f| yield
|
914
|
+
Dir.glob(*args) { |f| yield new(f) }
|
770
915
|
else
|
771
|
-
Dir.glob(*args).map {|f|
|
916
|
+
Dir.glob(*args).map { |f| new(f) }
|
772
917
|
end
|
773
918
|
end
|
774
919
|
|
775
|
-
# See <tt>Dir.getwd</tt>. Returns the current working directory
|
776
|
-
|
777
|
-
|
920
|
+
# See <tt>Dir.getwd</tt>. Returns the current working directory
|
921
|
+
# as a Pathname.
|
922
|
+
def self.getwd
|
923
|
+
new(Dir.getwd)
|
924
|
+
end
|
778
925
|
|
779
|
-
|
780
|
-
# Pathname object.
|
781
|
-
def entries() Dir.entries(@path).map {|f| self.class.new(f) } end
|
926
|
+
class << self; alias_method :pwd, :getwd end
|
782
927
|
|
783
|
-
#
|
784
|
-
#
|
928
|
+
# Return the entries (files and subdirectories) in the directory, each as
|
929
|
+
# a Pathname object.
|
930
|
+
def entries
|
931
|
+
Dir.entries(@path).map { |f| self.class.new(f) }
|
932
|
+
end
|
933
|
+
|
934
|
+
# Iterates over the entries (files and subdirectories) in the directory.
|
935
|
+
# It yields a Pathname object for each entry.
|
785
936
|
#
|
786
937
|
# This method has existed since 1.8.1.
|
787
|
-
def each_entry(
|
788
|
-
Dir.foreach(@path) {|f| yield self.class.new(f) }
|
938
|
+
def each_entry(*) # :yield: pathname
|
939
|
+
Dir.foreach(@path) { |f| yield self.class.new(f) }
|
789
940
|
end
|
790
941
|
|
791
942
|
# See <tt>Dir.mkdir</tt>. Create the referenced directory.
|
792
|
-
def mkdir(*args)
|
943
|
+
def mkdir(*args)
|
944
|
+
Dir.mkdir(@path, *args)
|
945
|
+
end
|
793
946
|
|
794
947
|
# See <tt>Dir.rmdir</tt>. Remove the referenced directory.
|
795
|
-
def rmdir
|
948
|
+
def rmdir
|
949
|
+
Dir.rmdir(@path)
|
950
|
+
end
|
796
951
|
|
797
952
|
# See <tt>Dir.open</tt>.
|
798
953
|
def opendir(&block) # :yield: dir
|
@@ -800,29 +955,30 @@ module FakeFS
|
|
800
955
|
end
|
801
956
|
end
|
802
957
|
|
803
|
-
|
958
|
+
# Pathname class
|
804
959
|
class Pathname # * Find *
|
805
960
|
#
|
806
|
-
# Pathname#find is an iterator to traverse a directory tree
|
807
|
-
#
|
961
|
+
# Pathname#find is an iterator to traverse a directory tree
|
962
|
+
# in a depth first manner.
|
963
|
+
# It yields a Pathname for each file under "this" directory.
|
808
964
|
#
|
809
|
-
# Since it is implemented by <tt>find.rb</tt>, <tt>Find.prune</tt>
|
810
|
-
# to control the traverse.
|
965
|
+
# Since it is implemented by <tt>find.rb</tt>, <tt>Find.prune</tt>
|
966
|
+
# can be used to control the traverse.
|
811
967
|
#
|
812
|
-
# If +self+ is <tt>.</tt>, yielded pathnames begin with
|
813
|
-
# current directory, not <tt>./</tt>.
|
968
|
+
# If +self+ is <tt>.</tt>, yielded pathnames begin with
|
969
|
+
# a filename in the current directory, not <tt>./</tt>.
|
814
970
|
#
|
815
|
-
def find(
|
971
|
+
def find(*) # :yield: pathname
|
816
972
|
require 'find'
|
817
973
|
if @path == '.'
|
818
|
-
Find.find(@path) {|f| yield self.class.new(f.sub(%r{
|
974
|
+
Find.find(@path) { |f| yield self.class.new(f.sub(%r{/\A\./}, '')) }
|
819
975
|
else
|
820
|
-
Find.find(@path) {|f| yield self.class.new(f) }
|
976
|
+
Find.find(@path) { |f| yield self.class.new(f) }
|
821
977
|
end
|
822
978
|
end
|
823
979
|
end
|
824
980
|
|
825
|
-
|
981
|
+
# Pathname class
|
826
982
|
class Pathname # * FileUtils *
|
827
983
|
# See <tt>FileUtils.mkpath</tt>. Creates a full path, including any
|
828
984
|
# intermediate directories that don't yet exist.
|
@@ -842,23 +998,21 @@ module FakeFS
|
|
842
998
|
end
|
843
999
|
end
|
844
1000
|
|
845
|
-
|
1001
|
+
# Pathname class
|
846
1002
|
class Pathname # * mixed *
|
847
1003
|
# Removes a file or directory, using <tt>File.unlink</tt> or
|
848
1004
|
# <tt>Dir.unlink</tt> as necessary.
|
849
|
-
def unlink
|
850
|
-
|
851
|
-
|
852
|
-
rescue Errno::ENOTDIR
|
853
|
-
File.unlink @path
|
854
|
-
end
|
1005
|
+
def unlink
|
1006
|
+
Dir.unlink @path if File.directory? @path
|
1007
|
+
File.unlink @path unless File.directory? @path
|
855
1008
|
end
|
856
|
-
|
1009
|
+
|
1010
|
+
alias_method :delete, :unlink
|
857
1011
|
end
|
858
1012
|
|
1013
|
+
# Pathname class
|
859
1014
|
class Pathname
|
860
1015
|
undef =~
|
861
1016
|
end
|
862
1017
|
end # RUBY_VERSION >= 1.9.3
|
863
1018
|
end
|
864
|
-
|