fakefs 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fakefs/dir.rb +2 -2
- data/lib/fakefs/file_system.rb +6 -6
- data/lib/fakefs/globber.rb +6 -2
- data/lib/fakefs/pathname.rb +167 -176
- data/lib/fakefs/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bfa54005c100676feb93956681fe9cd686030fe16e3dab3a54109e5c29b2361
|
4
|
+
data.tar.gz: 30c51f9bcf1e221ca4cd3fbb43ee987979c7fa57b2aa1865f9387bfab755d66b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6929e502b22c9f1f632b0d98379caad07a7abcda53c658fb258d321dda15e53d60e4c927365beb6ec62d2e9d30c77aa70e746e0cd693bf6f02256c64eb4ab5a2
|
7
|
+
data.tar.gz: 2d80c942fbfea67e1dfa031f1b859115cefe783e9cb35a246a7f44b6f1d55511c40a758782dafad2557eefcbf7cabcea7f338c35a6f207a7ea94ec204bb99aea
|
data/lib/fakefs/dir.rb
CHANGED
@@ -117,9 +117,9 @@ module FakeFS
|
|
117
117
|
Dir.open(dirname) { |file| yield file }
|
118
118
|
end
|
119
119
|
|
120
|
-
def self.glob(pattern,
|
120
|
+
def self.glob(pattern, flags = 0, &block)
|
121
121
|
matches_for_pattern = lambda do |matcher|
|
122
|
-
[FileSystem.find(matcher) || []].flatten.map do |e|
|
122
|
+
[FileSystem.find(matcher, flags) || []].flatten.map do |e|
|
123
123
|
if Dir.pwd.match(%r{\A/?\z}) ||
|
124
124
|
!e.to_s.match(%r{\A#{Dir.pwd}/?})
|
125
125
|
e.to_s
|
data/lib/fakefs/file_system.rb
CHANGED
@@ -20,13 +20,13 @@ module FakeFS
|
|
20
20
|
fs.entries
|
21
21
|
end
|
22
22
|
|
23
|
-
def find(path)
|
23
|
+
def find(path, find_flags = 0)
|
24
24
|
parts = path_parts(normalize_path(path))
|
25
25
|
return fs if parts.empty? # '/'
|
26
26
|
|
27
27
|
entries = Globber.expand(path).flat_map do |pattern|
|
28
28
|
parts = path_parts(normalize_path(pattern))
|
29
|
-
find_recurser(fs, parts).flatten
|
29
|
+
find_recurser(fs, parts, find_flags).flatten
|
30
30
|
end
|
31
31
|
|
32
32
|
case entries.length
|
@@ -116,9 +116,9 @@ module FakeFS
|
|
116
116
|
|
117
117
|
private
|
118
118
|
|
119
|
-
def find_recurser(dir, parts)
|
119
|
+
def find_recurser(dir, parts, find_flags = 0)
|
120
120
|
return [] unless dir.respond_to? :[]
|
121
|
-
pattern, *parts = parts
|
121
|
+
pattern, *parts = parts
|
122
122
|
matches =
|
123
123
|
case pattern
|
124
124
|
when '**'
|
@@ -139,14 +139,14 @@ module FakeFS
|
|
139
139
|
end
|
140
140
|
else
|
141
141
|
Globber.expand(pattern).flat_map do |subpattern|
|
142
|
-
dir.matches(Globber.regexp(subpattern))
|
142
|
+
dir.matches(Globber.regexp(subpattern, find_flags))
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
146
|
if parts.empty? # we're done recursing
|
147
147
|
matches
|
148
148
|
else
|
149
|
-
matches.map { |entry| find_recurser(entry, parts) }
|
149
|
+
matches.map { |entry| find_recurser(entry, parts, find_flags) }
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
data/lib/fakefs/globber.rb
CHANGED
@@ -60,7 +60,7 @@ module FakeFS
|
|
60
60
|
drop_root(result).reject(&:empty?)
|
61
61
|
end
|
62
62
|
|
63
|
-
def regexp(pattern)
|
63
|
+
def regexp(pattern, find_flags = 0)
|
64
64
|
pattern = pattern.to_s
|
65
65
|
|
66
66
|
regex_body =
|
@@ -82,8 +82,12 @@ module FakeFS
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
# if we are matching dot files/directories, add that to the regex
|
86
|
+
if find_flags == File::FNM_DOTMATCH
|
87
|
+
regex_body = "(\.)?" + regex_body
|
88
|
+
end
|
86
89
|
|
90
|
+
regex_body = regex_body.gsub(/\A\./, '(?!\.).')
|
87
91
|
/\A#{regex_body}\Z/
|
88
92
|
end
|
89
93
|
|
data/lib/fakefs/pathname.rb
CHANGED
@@ -138,43 +138,6 @@ module FakeFS
|
|
138
138
|
self.class.new(@path.chomp(ext) + repl)
|
139
139
|
end
|
140
140
|
|
141
|
-
# chop_basename(path) -> [pre-basename, basename] or nil
|
142
|
-
def chop_basename(path)
|
143
|
-
base = File.basename(path)
|
144
|
-
if /\A#{SEPARATOR_PAT}?\z/o =~ base
|
145
|
-
return nil
|
146
|
-
else
|
147
|
-
return path[0, path.rindex(base)], base
|
148
|
-
end
|
149
|
-
end
|
150
|
-
private :chop_basename
|
151
|
-
|
152
|
-
# split_names(path) -> prefix, [name, ...]
|
153
|
-
def split_names(path)
|
154
|
-
names = []
|
155
|
-
while (r = chop_basename(path))
|
156
|
-
path, basename = r
|
157
|
-
names.unshift basename
|
158
|
-
end
|
159
|
-
|
160
|
-
[path, names]
|
161
|
-
end
|
162
|
-
|
163
|
-
private :split_names
|
164
|
-
|
165
|
-
def prepend_prefix(prefix, relpath)
|
166
|
-
if relpath.empty?
|
167
|
-
File.dirname(prefix)
|
168
|
-
elsif /#{SEPARATOR_PAT}/o =~ prefix
|
169
|
-
prefix = File.dirname(prefix)
|
170
|
-
prefix = File.join(prefix, '') if File.basename(prefix + 'a') != 'a'
|
171
|
-
prefix + relpath
|
172
|
-
else
|
173
|
-
prefix + relpath
|
174
|
-
end
|
175
|
-
end
|
176
|
-
private :prepend_prefix
|
177
|
-
|
178
141
|
# Returns clean pathname of +self+ with consecutive slashes and
|
179
142
|
# useless dots removed. The filesystem is not accessed.
|
180
143
|
#
|
@@ -192,97 +155,6 @@ module FakeFS
|
|
192
155
|
end
|
193
156
|
end
|
194
157
|
|
195
|
-
#
|
196
|
-
# Clean the path simply by resolving and removing excess
|
197
|
-
# "." and ".." entries.
|
198
|
-
# Nothing more, nothing less.
|
199
|
-
#
|
200
|
-
def cleanpath_aggressive
|
201
|
-
path = @path
|
202
|
-
names = []
|
203
|
-
pre = path
|
204
|
-
while (r = chop_basename(pre))
|
205
|
-
pre, base = r
|
206
|
-
case base
|
207
|
-
when '.' # rubocop:disable Lint/EmptyWhen
|
208
|
-
when '..'
|
209
|
-
names.unshift base
|
210
|
-
else
|
211
|
-
if names[0] == '..'
|
212
|
-
names.shift
|
213
|
-
else
|
214
|
-
names.unshift base
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
|
219
|
-
names.shift while names[0] == '..'
|
220
|
-
end
|
221
|
-
self.class.new(prepend_prefix(pre, File.join(*names)))
|
222
|
-
end
|
223
|
-
private :cleanpath_aggressive
|
224
|
-
|
225
|
-
# trailing_separator?(path) -> bool
|
226
|
-
def trailing_separator?(path)
|
227
|
-
if (r = chop_basename(path))
|
228
|
-
pre, basename = r
|
229
|
-
pre.length + basename.length < path.length
|
230
|
-
else
|
231
|
-
false
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
private :trailing_separator?
|
236
|
-
|
237
|
-
# add_trailing_separator(path) -> path
|
238
|
-
def add_trailing_separator(path)
|
239
|
-
if File.basename(path + 'a') == 'a'
|
240
|
-
path
|
241
|
-
else
|
242
|
-
# xxx: Is File.join is appropriate to add separator?
|
243
|
-
File.join(path, '')
|
244
|
-
end
|
245
|
-
end
|
246
|
-
private :add_trailing_separator
|
247
|
-
|
248
|
-
def del_trailing_separator(path)
|
249
|
-
if (r = chop_basename(path))
|
250
|
-
pre, basename = r
|
251
|
-
pre + basename
|
252
|
-
elsif /#{SEPARATOR_PAT}+\z/o =~ path
|
253
|
-
$` + File.dirname(path)[/#{SEPARATOR_PAT}*\z/o]
|
254
|
-
else
|
255
|
-
path
|
256
|
-
end
|
257
|
-
end
|
258
|
-
private :del_trailing_separator
|
259
|
-
|
260
|
-
def cleanpath_conservative
|
261
|
-
path = @path
|
262
|
-
names = []
|
263
|
-
pre = path
|
264
|
-
while (r = chop_basename(pre))
|
265
|
-
pre, base = r
|
266
|
-
names.unshift base if base != '.'
|
267
|
-
end
|
268
|
-
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
|
269
|
-
names.shift while names[0] == '..'
|
270
|
-
end
|
271
|
-
if names.empty?
|
272
|
-
self.class.new(File.dirname(pre))
|
273
|
-
else
|
274
|
-
names << '.' if names.last != '..' && File.basename(path) == '.'
|
275
|
-
|
276
|
-
result = prepend_prefix(pre, File.join(*names))
|
277
|
-
if /\A(?:\.|\.\.)\z/ !~ names.last && trailing_separator?(path)
|
278
|
-
self.class.new(add_trailing_separator(result))
|
279
|
-
else
|
280
|
-
self.class.new(result)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
private :cleanpath_conservative
|
285
|
-
|
286
158
|
#
|
287
159
|
# Returns the real (absolute) pathname of +self+ in the actual
|
288
160
|
# filesystem not containing symlinks or useless dots.
|
@@ -438,54 +310,6 @@ module FakeFS
|
|
438
310
|
end
|
439
311
|
alias / +
|
440
312
|
|
441
|
-
def plus(path1, path2) # -> path
|
442
|
-
prefix2 = path2
|
443
|
-
index_list2 = []
|
444
|
-
basename_list2 = []
|
445
|
-
while (r2 = chop_basename(prefix2))
|
446
|
-
prefix2, basename2 = r2
|
447
|
-
index_list2.unshift prefix2.length
|
448
|
-
basename_list2.unshift basename2
|
449
|
-
end
|
450
|
-
|
451
|
-
return path2 if prefix2 != ''
|
452
|
-
|
453
|
-
prefix1 = path1
|
454
|
-
while (r1 = chop_basename(prefix1))
|
455
|
-
while !basename_list2.empty? && basename_list2.first == '.'
|
456
|
-
index_list2.shift
|
457
|
-
basename_list2.shift
|
458
|
-
end
|
459
|
-
|
460
|
-
prefix1, basename1 = r1
|
461
|
-
next if basename1 == '.'
|
462
|
-
if basename1 == '..' ||
|
463
|
-
basename_list2.empty? ||
|
464
|
-
basename_list2.first != '..'
|
465
|
-
prefix1 += basename1
|
466
|
-
break
|
467
|
-
end
|
468
|
-
index_list2.shift
|
469
|
-
basename_list2.shift
|
470
|
-
end
|
471
|
-
|
472
|
-
r1 = chop_basename(prefix1)
|
473
|
-
if !r1 && /#{SEPARATOR_PAT}/o =~ File.basename(prefix1)
|
474
|
-
while !basename_list2.empty? && basename_list2.first == '..'
|
475
|
-
index_list2.shift
|
476
|
-
basename_list2.shift
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
if !basename_list2.empty?
|
481
|
-
suffix2 = path2[index_list2.first..-1]
|
482
|
-
r1 ? File.join(prefix1, suffix2) : prefix1 + suffix2
|
483
|
-
else
|
484
|
-
r1 ? prefix1 : File.dirname(prefix1)
|
485
|
-
end
|
486
|
-
end
|
487
|
-
private :plus
|
488
|
-
|
489
313
|
#
|
490
314
|
# Pathname#join joins pathnames.
|
491
315
|
#
|
@@ -625,6 +449,173 @@ module FakeFS
|
|
625
449
|
Pathname.new(File.join(*relpath_names))
|
626
450
|
end
|
627
451
|
end
|
452
|
+
|
453
|
+
private
|
454
|
+
|
455
|
+
# chop_basename(path) -> [pre-basename, basename] or nil
|
456
|
+
def chop_basename(path)
|
457
|
+
base = File.basename(path)
|
458
|
+
if /\A#{SEPARATOR_PAT}?\z/o =~ base
|
459
|
+
return nil
|
460
|
+
else
|
461
|
+
return path[0, path.rindex(base)], base
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
# split_names(path) -> prefix, [name, ...]
|
466
|
+
def split_names(path)
|
467
|
+
names = []
|
468
|
+
while (r = chop_basename(path))
|
469
|
+
path, basename = r
|
470
|
+
names.unshift basename
|
471
|
+
end
|
472
|
+
|
473
|
+
[path, names]
|
474
|
+
end
|
475
|
+
|
476
|
+
def prepend_prefix(prefix, relpath)
|
477
|
+
if relpath.empty?
|
478
|
+
File.dirname(prefix)
|
479
|
+
elsif /#{SEPARATOR_PAT}/o =~ prefix
|
480
|
+
prefix = File.dirname(prefix)
|
481
|
+
prefix = File.join(prefix, '') if File.basename(prefix + 'a') != 'a'
|
482
|
+
prefix + relpath
|
483
|
+
else
|
484
|
+
prefix + relpath
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
#
|
489
|
+
# Clean the path simply by resolving and removing excess
|
490
|
+
# "." and ".." entries.
|
491
|
+
# Nothing more, nothing less.
|
492
|
+
#
|
493
|
+
def cleanpath_aggressive
|
494
|
+
path = @path
|
495
|
+
names = []
|
496
|
+
pre = path
|
497
|
+
while (r = chop_basename(pre))
|
498
|
+
pre, base = r
|
499
|
+
case base
|
500
|
+
when '.' # rubocop:disable Lint/EmptyWhen
|
501
|
+
when '..'
|
502
|
+
names.unshift base
|
503
|
+
else
|
504
|
+
if names[0] == '..'
|
505
|
+
names.shift
|
506
|
+
else
|
507
|
+
names.unshift base
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
|
512
|
+
names.shift while names[0] == '..'
|
513
|
+
end
|
514
|
+
self.class.new(prepend_prefix(pre, File.join(*names)))
|
515
|
+
end
|
516
|
+
|
517
|
+
# trailing_separator?(path) -> bool
|
518
|
+
def trailing_separator?(path)
|
519
|
+
if (r = chop_basename(path))
|
520
|
+
pre, basename = r
|
521
|
+
pre.length + basename.length < path.length
|
522
|
+
else
|
523
|
+
false
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
# add_trailing_separator(path) -> path
|
528
|
+
def add_trailing_separator(path)
|
529
|
+
if File.basename(path + 'a') == 'a'
|
530
|
+
path
|
531
|
+
else
|
532
|
+
# xxx: Is File.join is appropriate to add separator?
|
533
|
+
File.join(path, '')
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
def del_trailing_separator(path)
|
538
|
+
if (r = chop_basename(path))
|
539
|
+
pre, basename = r
|
540
|
+
pre + basename
|
541
|
+
elsif /#{SEPARATOR_PAT}+\z/o =~ path
|
542
|
+
$` + File.dirname(path)[/#{SEPARATOR_PAT}*\z/o]
|
543
|
+
else
|
544
|
+
path
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
def cleanpath_conservative
|
549
|
+
path = @path
|
550
|
+
names = []
|
551
|
+
pre = path
|
552
|
+
while (r = chop_basename(pre))
|
553
|
+
pre, base = r
|
554
|
+
names.unshift base if base != '.'
|
555
|
+
end
|
556
|
+
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
|
557
|
+
names.shift while names[0] == '..'
|
558
|
+
end
|
559
|
+
if names.empty?
|
560
|
+
self.class.new(File.dirname(pre))
|
561
|
+
else
|
562
|
+
names << '.' if names.last != '..' && File.basename(path) == '.'
|
563
|
+
|
564
|
+
result = prepend_prefix(pre, File.join(*names))
|
565
|
+
if /\A(?:\.|\.\.)\z/ !~ names.last && trailing_separator?(path)
|
566
|
+
self.class.new(add_trailing_separator(result))
|
567
|
+
else
|
568
|
+
self.class.new(result)
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
def plus(path1, path2) # -> path
|
574
|
+
prefix2 = path2
|
575
|
+
index_list2 = []
|
576
|
+
basename_list2 = []
|
577
|
+
while (r2 = chop_basename(prefix2))
|
578
|
+
prefix2, basename2 = r2
|
579
|
+
index_list2.unshift prefix2.length
|
580
|
+
basename_list2.unshift basename2
|
581
|
+
end
|
582
|
+
|
583
|
+
return path2 if prefix2 != ''
|
584
|
+
|
585
|
+
prefix1 = path1
|
586
|
+
while (r1 = chop_basename(prefix1))
|
587
|
+
while !basename_list2.empty? && basename_list2.first == '.'
|
588
|
+
index_list2.shift
|
589
|
+
basename_list2.shift
|
590
|
+
end
|
591
|
+
|
592
|
+
prefix1, basename1 = r1
|
593
|
+
next if basename1 == '.'
|
594
|
+
if basename1 == '..' ||
|
595
|
+
basename_list2.empty? ||
|
596
|
+
basename_list2.first != '..'
|
597
|
+
prefix1 += basename1
|
598
|
+
break
|
599
|
+
end
|
600
|
+
index_list2.shift
|
601
|
+
basename_list2.shift
|
602
|
+
end
|
603
|
+
|
604
|
+
r1 = chop_basename(prefix1)
|
605
|
+
if !r1 && /#{SEPARATOR_PAT}/o =~ File.basename(prefix1)
|
606
|
+
while !basename_list2.empty? && basename_list2.first == '..'
|
607
|
+
index_list2.shift
|
608
|
+
basename_list2.shift
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
612
|
+
if !basename_list2.empty?
|
613
|
+
suffix2 = path2[index_list2.first..-1]
|
614
|
+
r1 ? File.join(prefix1, suffix2) : prefix1 + suffix2
|
615
|
+
else
|
616
|
+
r1 ? prefix1 : File.dirname(prefix1)
|
617
|
+
end
|
618
|
+
end
|
628
619
|
end
|
629
620
|
|
630
621
|
# Pathname class
|
data/lib/fakefs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakefs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2018-07-
|
15
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bump
|
@@ -104,14 +104,14 @@ dependencies:
|
|
104
104
|
requirements:
|
105
105
|
- - "~>"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: 0.
|
107
|
+
version: 0.58.1
|
108
108
|
type: :development
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
112
|
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: 0.
|
114
|
+
version: 0.58.1
|
115
115
|
description: A fake filesystem. Use it in your tests.
|
116
116
|
email:
|
117
117
|
- chris@ozmm.org
|