1 |
graaff 12/01/06 07:35:54 |
2 |
|
3 |
Added: fakefs-0.4.0-ruby193-pathname.patch |
4 |
fakefs-0.4.0-ruby193-ruby-pathname.patch |
5 |
fakefs-0.4.0-ruby193.patch |
6 |
fakefs-0.4.0-ruby193-advise.patch |
7 |
Log: |
8 |
Add a host of patches from upstream's tracker for Ruby 1.9.3. |
9 |
|
10 |
(Portage version: 2.1.10.41/cvs/Linux x86_64) |
11 |
|
12 |
Revision Changes Path |
13 |
1.1 dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-pathname.patch |
14 |
|
15 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-pathname.patch?rev=1.1&view=markup |
16 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-pathname.patch?rev=1.1&content-type=text/plain |
17 |
|
18 |
Index: fakefs-0.4.0-ruby193-pathname.patch |
19 |
=================================================================== |
20 |
commit dcc2ad6952e334b91f0f044a1f1083c99949d840 |
21 |
Author: Lukas Oberhuber <lukaso@×××××.com> |
22 |
Date: Wed Dec 21 16:55:19 2011 +0000 |
23 |
|
24 |
Substitute Pathname to get tests to pass in ruby 1.9.3 |
25 |
|
26 |
diff --git a/lib/fakefs/base.rb b/lib/fakefs/base.rb |
27 |
index 7e83e76..6c1741a 100644 |
28 |
--- a/lib/fakefs/base.rb |
29 |
+++ b/lib/fakefs/base.rb |
30 |
@@ -2,6 +2,7 @@ RealFile = File |
31 |
RealFileTest = FileTest |
32 |
RealFileUtils = FileUtils |
33 |
RealDir = Dir |
34 |
+RealPathname = Pathname |
35 |
|
36 |
module FakeFS |
37 |
def self.activate! |
38 |
@@ -10,11 +11,14 @@ module FakeFS |
39 |
remove_const(:File) |
40 |
remove_const(:FileTest) |
41 |
remove_const(:FileUtils) |
42 |
+ remove_const(:Pathname) if RUBY_VERSION >= "1.9.3" |
43 |
+ |
44 |
|
45 |
const_set(:Dir, FakeFS::Dir) |
46 |
const_set(:File, FakeFS::File) |
47 |
const_set(:FileUtils, FakeFS::FileUtils) |
48 |
const_set(:FileTest, FakeFS::FileTest) |
49 |
+ const_set(:Pathname, FakeFS::Pathname) if RUBY_VERSION >= "1.9.3" |
50 |
end |
51 |
true |
52 |
end |
53 |
@@ -25,11 +29,13 @@ module FakeFS |
54 |
remove_const(:File) |
55 |
remove_const(:FileTest) |
56 |
remove_const(:FileUtils) |
57 |
+ remove_const(:Pathname) if RUBY_VERSION >= "1.9.3" |
58 |
|
59 |
const_set(:Dir, RealDir) |
60 |
const_set(:File, RealFile) |
61 |
const_set(:FileTest, RealFileTest) |
62 |
const_set(:FileUtils, RealFileUtils) |
63 |
+ const_set(:Pathname, RealPathname) if RUBY_VERSION >= "1.9.3" |
64 |
end |
65 |
true |
66 |
end |
67 |
diff --git a/lib/fakefs/safe.rb b/lib/fakefs/safe.rb |
68 |
index a1b804c..783de74 100644 |
69 |
--- a/lib/fakefs/safe.rb |
70 |
+++ b/lib/fakefs/safe.rb |
71 |
@@ -9,3 +9,5 @@ require 'fakefs/fileutils' |
72 |
require 'fakefs/file' |
73 |
require 'fakefs/file_test' |
74 |
require 'fakefs/dir' |
75 |
+require 'fakefs/pathname' if RUBY_VERSION >= "1.9.3" |
76 |
+ |
77 |
|
78 |
|
79 |
|
80 |
1.1 dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-ruby-pathname.patch |
81 |
|
82 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-ruby-pathname.patch?rev=1.1&view=markup |
83 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-ruby-pathname.patch?rev=1.1&content-type=text/plain |
84 |
|
85 |
Index: fakefs-0.4.0-ruby193-ruby-pathname.patch |
86 |
=================================================================== |
87 |
commit cf580c9274ff774f540b374e07ed348916c14518 |
88 |
Author: Lukas Oberhuber <lukaso@×××××.com> |
89 |
Date: Wed Dec 21 17:27:26 2011 +0000 |
90 |
|
91 |
Bumped version. |
92 |
Moved pathname.rb from ruby 1.9.2 into project in order to continue compatibility to 1.9.3 where |
93 |
the functionality has been moved into c. In the c version of the file, the unset_const trick |
94 |
doesn't work because the constant rb_cFile in the c file is never modified. I think this is |
95 |
actually a bug in how ruby MRI operates, but the fix is a little bit complicated. |
96 |
|
97 |
diff --git a/lib/fakefs/pathname.rb b/lib/fakefs/pathname.rb |
98 |
new file mode 100644 |
99 |
index 0000000..181af36 |
100 |
--- /dev/null |
101 |
+++ lib/fakefs/pathname.rb |
102 |
@@ -0,0 +1,864 @@ |
103 |
+module FakeFS |
104 |
+ if RUBY_VERSION >= "1.9.3" |
105 |
+ |
106 |
+ # |
107 |
+ # = pathname.rb - From MRI 1.9.2 |
108 |
+ # |
109 |
+ # Object-Oriented Pathname Class |
110 |
+ # |
111 |
+ # Author:: Tanaka Akira <akr@××××.org> |
112 |
+ # Documentation:: Author and Gavin Sinclair |
113 |
+ # |
114 |
+ # For documentation, see class Pathname. |
115 |
+ # |
116 |
+ class Pathname |
117 |
+ |
118 |
+ # to_path is implemented so Pathname objects are usable with File.open, etc. |
119 |
+ TO_PATH = :to_path |
120 |
+ |
121 |
+ SAME_PATHS = if File::FNM_SYSCASE.nonzero? |
122 |
+ proc {|a, b| a.casecmp(b).zero?} |
123 |
+ else |
124 |
+ proc {|a, b| a == b} |
125 |
+ end |
126 |
+ |
127 |
+ # :startdoc: |
128 |
+ |
129 |
+ # |
130 |
+ # Create a Pathname object from the given String (or String-like object). |
131 |
+ # If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised. |
132 |
+ # |
133 |
+ def initialize(path) |
134 |
+ path = path.__send__(TO_PATH) if path.respond_to? TO_PATH |
135 |
+ @path = path.dup |
136 |
+ |
137 |
+ if /\0/ =~ @path |
138 |
+ raise ArgumentError, "pathname contains \\0: #{@path.inspect}" |
139 |
+ end |
140 |
+ |
141 |
+ self.taint if @path.tainted? |
142 |
+ end |
143 |
+ |
144 |
+ def freeze() super; @path.freeze; self end |
145 |
+ def taint() super; @path.taint; self end |
146 |
+ def untaint() super; @path.untaint; self end |
147 |
+ |
148 |
+ # |
149 |
+ # Compare this pathname with +other+. The comparison is string-based. |
150 |
+ # Be aware that two different paths (<tt>foo.txt</tt> and <tt>./foo.txt</tt>) |
151 |
+ # can refer to the same file. |
152 |
+ # |
153 |
+ def ==(other) |
154 |
+ return false unless Pathname === other |
155 |
+ other.to_s == @path |
156 |
+ end |
157 |
+ alias === == |
158 |
+ alias eql? == |
159 |
+ |
160 |
+ # Provides for comparing pathnames, case-sensitively. |
161 |
+ def <=>(other) |
162 |
+ return nil unless Pathname === other |
163 |
+ @path.tr('/', "\0") <=> other.to_s.tr('/', "\0") |
164 |
+ end |
165 |
+ |
166 |
+ def hash # :nodoc: |
167 |
+ @path.hash |
168 |
+ end |
169 |
+ |
170 |
+ # Return the path as a String. |
171 |
+ def to_s |
172 |
+ @path.dup |
173 |
+ end |
174 |
+ |
175 |
+ # to_path is implemented so Pathname objects are usable with File.open, etc. |
176 |
+ alias_method TO_PATH, :to_s |
177 |
+ |
178 |
+ def inspect # :nodoc: |
179 |
+ "#<#{self.class}:#{@path}>" |
180 |
+ end |
181 |
+ |
182 |
+ # Return a pathname which is substituted by String#sub. |
183 |
+ def sub(pattern, *rest, &block) |
184 |
+ if block |
185 |
+ path = @path.sub(pattern, *rest) {|*args| |
186 |
+ begin |
187 |
+ old = Thread.current[:pathname_sub_matchdata] |
188 |
+ Thread.current[:pathname_sub_matchdata] = $~ |
189 |
+ eval("$~ = Thread.current[:pathname_sub_matchdata]", block.binding) |
190 |
+ ensure |
191 |
+ Thread.current[:pathname_sub_matchdata] = old |
192 |
+ end |
193 |
+ yield(*args) |
194 |
+ } |
195 |
+ else |
196 |
+ path = @path.sub(pattern, *rest) |
197 |
+ end |
198 |
+ self.class.new(path) |
199 |
+ end |
200 |
+ |
201 |
+ if File::ALT_SEPARATOR |
202 |
+ SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}" |
203 |
+ SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/ |
204 |
+ else |
205 |
+ SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}" |
206 |
+ SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/ |
207 |
+ end |
208 |
+ |
209 |
+ # Return a pathname which the extension of the basename is substituted by |
210 |
+ # <i>repl</i>. |
211 |
+ # |
212 |
+ # If self has no extension part, <i>repl</i> is appended. |
213 |
+ def sub_ext(repl) |
214 |
+ ext = File.extname(@path) |
215 |
+ self.class.new(@path.chomp(ext) + repl) |
216 |
+ end |
217 |
+ |
218 |
+ # chop_basename(path) -> [pre-basename, basename] or nil |
219 |
+ def chop_basename(path) |
220 |
+ base = File.basename(path) |
221 |
+ if /\A#{SEPARATOR_PAT}?\z/o =~ base |
222 |
+ return nil |
223 |
+ else |
224 |
+ return path[0, path.rindex(base)], base |
225 |
+ end |
226 |
+ end |
227 |
+ private :chop_basename |
228 |
+ |
229 |
+ # split_names(path) -> prefix, [name, ...] |
230 |
+ def split_names(path) |
231 |
+ names = [] |
232 |
+ while r = chop_basename(path) |
233 |
+ path, basename = r |
234 |
+ names.unshift basename |
235 |
+ end |
236 |
+ return path, names |
237 |
+ end |
238 |
+ private :split_names |
239 |
+ |
240 |
+ def prepend_prefix(prefix, relpath) |
241 |
+ if relpath.empty? |
242 |
+ File.dirname(prefix) |
243 |
+ elsif /#{SEPARATOR_PAT}/o =~ prefix |
244 |
+ prefix = File.dirname(prefix) |
245 |
+ prefix = File.join(prefix, "") if File.basename(prefix + 'a') != 'a' |
246 |
+ prefix + relpath |
247 |
+ else |
248 |
+ prefix + relpath |
249 |
+ end |
250 |
+ end |
251 |
+ private :prepend_prefix |
252 |
+ |
253 |
+ # Returns clean pathname of +self+ with consecutive slashes and useless dots |
254 |
+ # removed. The filesystem is not accessed. |
255 |
+ # |
256 |
+ # If +consider_symlink+ is +true+, then a more conservative algorithm is used |
257 |
+ # to avoid breaking symbolic linkages. This may retain more <tt>..</tt> |
258 |
+ # entries than absolutely necessary, but without accessing the filesystem, |
259 |
+ # this can't be avoided. See #realpath. |
260 |
+ # |
261 |
+ def cleanpath(consider_symlink=false) |
262 |
+ if consider_symlink |
263 |
+ cleanpath_conservative |
264 |
+ else |
265 |
+ cleanpath_aggressive |
266 |
+ end |
267 |
+ end |
268 |
+ |
269 |
+ # |
270 |
+ # Clean the path simply by resolving and removing excess "." and ".." entries. |
271 |
+ # Nothing more, nothing less. |
272 |
+ # |
273 |
+ def cleanpath_aggressive |
274 |
+ path = @path |
275 |
+ names = [] |
276 |
+ pre = path |
277 |
+ while r = chop_basename(pre) |
278 |
+ pre, base = r |
279 |
+ case base |
280 |
+ when '.' |
281 |
+ when '..' |
282 |
+ names.unshift base |
283 |
+ else |
284 |
+ if names[0] == '..' |
285 |
+ names.shift |
286 |
+ else |
287 |
+ names.unshift base |
288 |
+ end |
289 |
+ end |
290 |
+ end |
291 |
+ if /#{SEPARATOR_PAT}/o =~ File.basename(pre) |
292 |
+ names.shift while names[0] == '..' |
293 |
+ end |
294 |
+ self.class.new(prepend_prefix(pre, File.join(*names))) |
295 |
+ end |
296 |
+ private :cleanpath_aggressive |
297 |
+ |
298 |
+ # has_trailing_separator?(path) -> bool |
299 |
+ def has_trailing_separator?(path) |
300 |
+ if r = chop_basename(path) |
301 |
+ pre, basename = r |
302 |
+ pre.length + basename.length < path.length |
303 |
+ else |
304 |
+ false |
305 |
+ end |
306 |
+ end |
307 |
+ private :has_trailing_separator? |
308 |
+ |
309 |
+ # add_trailing_separator(path) -> path |
310 |
+ def add_trailing_separator(path) |
311 |
+ if File.basename(path + 'a') == 'a' |
312 |
+ path |
313 |
+ else |
314 |
+ File.join(path, "") # xxx: Is File.join is appropriate to add separator? |
315 |
+ end |
316 |
+ end |
317 |
+ private :add_trailing_separator |
318 |
+ |
319 |
+ def del_trailing_separator(path) |
320 |
+ if r = chop_basename(path) |
321 |
+ pre, basename = r |
322 |
+ pre + basename |
323 |
+ elsif /#{SEPARATOR_PAT}+\z/o =~ path |
324 |
+ $` + File.dirname(path)[/#{SEPARATOR_PAT}*\z/o] |
325 |
+ else |
326 |
+ path |
327 |
+ end |
328 |
+ end |
329 |
+ private :del_trailing_separator |
330 |
+ |
331 |
+ def cleanpath_conservative |
332 |
+ path = @path |
333 |
+ names = [] |
334 |
+ pre = path |
335 |
+ while r = chop_basename(pre) |
336 |
+ pre, base = r |
337 |
+ names.unshift base if base != '.' |
338 |
+ end |
339 |
+ if /#{SEPARATOR_PAT}/o =~ File.basename(pre) |
340 |
+ names.shift while names[0] == '..' |
341 |
+ end |
342 |
+ if names.empty? |
343 |
+ self.class.new(File.dirname(pre)) |
344 |
+ else |
345 |
+ if names.last != '..' && File.basename(path) == '.' |
346 |
+ names << '.' |
347 |
+ end |
348 |
+ result = prepend_prefix(pre, File.join(*names)) |
349 |
+ if /\A(?:\.|\.\.)\z/ !~ names.last && has_trailing_separator?(path) |
350 |
+ self.class.new(add_trailing_separator(result)) |
351 |
+ else |
352 |
+ self.class.new(result) |
353 |
+ end |
354 |
+ end |
355 |
+ end |
356 |
+ private :cleanpath_conservative |
357 |
+ |
358 |
+ # |
359 |
+ # Returns the real (absolute) pathname of +self+ in the actual |
360 |
+ # filesystem not containing symlinks or useless dots. |
361 |
+ # |
362 |
+ # All components of the pathname must exist when this method is |
363 |
+ # called. |
364 |
+ # |
365 |
+ def realpath(basedir=nil) |
366 |
+ self.class.new(File.realpath(@path, basedir)) |
367 |
+ end |
368 |
+ |
369 |
+ # |
370 |
+ # Returns the real (absolute) pathname of +self+ in the actual filesystem. |
371 |
+ # The real pathname doesn't contain symlinks or useless dots. |
372 |
+ # |
373 |
+ # The last component of the real pathname can be nonexistent. |
374 |
+ # |
375 |
+ def realdirpath(basedir=nil) |
376 |
+ self.class.new(File.realdirpath(@path, basedir)) |
377 |
+ end |
378 |
+ |
379 |
+ # #parent returns the parent directory. |
380 |
+ # |
381 |
+ # This is same as <tt>self + '..'</tt>. |
382 |
+ def parent |
383 |
+ self + '..' |
384 |
+ end |
385 |
+ |
386 |
+ # #mountpoint? returns +true+ if <tt>self</tt> points to a mountpoint. |
387 |
+ def mountpoint? |
388 |
+ begin |
389 |
+ stat1 = self.lstat |
390 |
+ stat2 = self.parent.lstat |
391 |
+ stat1.dev == stat2.dev && stat1.ino == stat2.ino || |
392 |
+ stat1.dev != stat2.dev |
393 |
+ rescue Errno::ENOENT |
394 |
+ false |
395 |
+ end |
396 |
+ end |
397 |
+ |
398 |
+ # |
399 |
+ # #root? is a predicate for root directories. I.e. it returns +true+ if the |
400 |
+ # pathname consists of consecutive slashes. |
401 |
+ # |
402 |
+ # It doesn't access actual filesystem. So it may return +false+ for some |
403 |
+ # pathnames which points to roots such as <tt>/usr/..</tt>. |
404 |
+ # |
405 |
+ def root? |
406 |
+ !!(chop_basename(@path) == nil && /#{SEPARATOR_PAT}/o =~ @path) |
407 |
+ end |
408 |
+ |
409 |
+ # Predicate method for testing whether a path is absolute. |
410 |
+ # It returns +true+ if the pathname begins with a slash. |
411 |
+ def absolute? |
412 |
+ !relative? |
413 |
+ end |
414 |
+ |
415 |
+ # The opposite of #absolute? |
416 |
+ def relative? |
417 |
+ path = @path |
418 |
+ while r = chop_basename(path) |
419 |
+ path, basename = r |
420 |
+ end |
421 |
+ path == '' |
422 |
+ end |
423 |
+ |
424 |
+ # |
425 |
+ # Iterates over each component of the path. |
426 |
+ # |
427 |
+ # Pathname.new("/usr/bin/ruby").each_filename {|filename| ... } |
428 |
+ # # yields "usr", "bin", and "ruby". |
429 |
+ # |
430 |
+ def each_filename # :yield: filename |
431 |
+ return to_enum(__method__) unless block_given? |
432 |
+ prefix, names = split_names(@path) |
433 |
+ names.each {|filename| yield filename } |
434 |
+ nil |
435 |
+ end |
436 |
+ |
437 |
+ # Iterates over and yields a new Pathname object |
438 |
+ # for each element in the given path in descending order. |
439 |
+ # |
440 |
+ # Pathname.new('/path/to/some/file.rb').descend {|v| p v} |
441 |
+ # #<Pathname:/> |
442 |
+ # #<Pathname:/path> |
443 |
+ # #<Pathname:/path/to> |
444 |
+ # #<Pathname:/path/to/some> |
445 |
+ # #<Pathname:/path/to/some/file.rb> |
446 |
+ # |
447 |
+ # Pathname.new('path/to/some/file.rb').descend {|v| p v} |
448 |
+ # #<Pathname:path> |
449 |
+ # #<Pathname:path/to> |
450 |
+ # #<Pathname:path/to/some> |
451 |
+ # #<Pathname:path/to/some/file.rb> |
452 |
+ # |
453 |
+ # It doesn't access actual filesystem. |
454 |
+ # |
455 |
+ # This method is available since 1.8.5. |
456 |
+ # |
457 |
+ def descend |
458 |
+ vs = [] |
459 |
+ ascend {|v| vs << v } |
460 |
+ vs.reverse_each {|v| yield v } |
461 |
+ nil |
462 |
+ end |
463 |
+ |
464 |
+ # Iterates over and yields a new Pathname object |
465 |
+ # for each element in the given path in ascending order. |
466 |
+ # |
467 |
+ # Pathname.new('/path/to/some/file.rb').ascend {|v| p v} |
468 |
+ # #<Pathname:/path/to/some/file.rb> |
469 |
+ # #<Pathname:/path/to/some> |
470 |
+ # #<Pathname:/path/to> |
471 |
+ # #<Pathname:/path> |
472 |
+ # #<Pathname:/> |
473 |
+ # |
474 |
+ # Pathname.new('path/to/some/file.rb').ascend {|v| p v} |
475 |
+ # #<Pathname:path/to/some/file.rb> |
476 |
+ # #<Pathname:path/to/some> |
477 |
+ # #<Pathname:path/to> |
478 |
+ # #<Pathname:path> |
479 |
+ # |
480 |
+ # It doesn't access actual filesystem. |
481 |
+ # |
482 |
+ # This method is available since 1.8.5. |
483 |
+ # |
484 |
+ def ascend |
485 |
+ path = @path |
486 |
+ yield self |
487 |
+ while r = chop_basename(path) |
488 |
+ path, name = r |
489 |
+ break if path.empty? |
490 |
+ yield self.class.new(del_trailing_separator(path)) |
491 |
+ end |
492 |
+ end |
493 |
+ |
494 |
+ # |
495 |
+ # Pathname#+ appends a pathname fragment to this one to produce a new Pathname |
496 |
+ # object. |
497 |
+ # |
498 |
+ # p1 = Pathname.new("/usr") # Pathname:/usr |
499 |
+ # p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby |
500 |
+ # p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd |
501 |
+ # |
502 |
+ # This method doesn't access the file system; it is pure string manipulation. |
503 |
+ # |
504 |
+ def +(other) |
505 |
+ other = Pathname.new(other) unless Pathname === other |
506 |
+ Pathname.new(plus(@path, other.to_s)) |
507 |
+ end |
508 |
+ |
509 |
+ def plus(path1, path2) # -> path |
510 |
+ prefix2 = path2 |
511 |
+ index_list2 = [] |
512 |
+ basename_list2 = [] |
513 |
+ while r2 = chop_basename(prefix2) |
514 |
+ prefix2, basename2 = r2 |
515 |
+ index_list2.unshift prefix2.length |
516 |
+ basename_list2.unshift basename2 |
517 |
+ end |
518 |
+ return path2 if prefix2 != '' |
519 |
+ prefix1 = path1 |
520 |
+ while true |
521 |
+ while !basename_list2.empty? && basename_list2.first == '.' |
522 |
+ index_list2.shift |
523 |
+ basename_list2.shift |
524 |
+ end |
525 |
+ break unless r1 = chop_basename(prefix1) |
526 |
+ prefix1, basename1 = r1 |
527 |
+ next if basename1 == '.' |
528 |
+ if basename1 == '..' || basename_list2.empty? || basename_list2.first != '..' |
529 |
+ prefix1 = prefix1 + basename1 |
530 |
+ break |
531 |
+ end |
532 |
+ index_list2.shift |
533 |
+ basename_list2.shift |
534 |
+ end |
535 |
+ r1 = chop_basename(prefix1) |
536 |
+ if !r1 && /#{SEPARATOR_PAT}/o =~ File.basename(prefix1) |
537 |
+ while !basename_list2.empty? && basename_list2.first == '..' |
538 |
+ index_list2.shift |
539 |
+ basename_list2.shift |
540 |
+ end |
541 |
+ end |
542 |
+ if !basename_list2.empty? |
543 |
+ suffix2 = path2[index_list2.first..-1] |
544 |
+ r1 ? File.join(prefix1, suffix2) : prefix1 + suffix2 |
545 |
+ else |
546 |
+ r1 ? prefix1 : File.dirname(prefix1) |
547 |
+ end |
548 |
+ end |
549 |
+ private :plus |
550 |
+ |
551 |
+ # |
552 |
+ # Pathname#join joins pathnames. |
553 |
+ # |
554 |
+ # <tt>path0.join(path1, ..., pathN)</tt> is the same as |
555 |
+ # <tt>path0 + path1 + ... + pathN</tt>. |
556 |
+ # |
557 |
+ def join(*args) |
558 |
+ args.unshift self |
559 |
+ result = args.pop |
560 |
+ result = Pathname.new(result) unless Pathname === result |
561 |
+ return result if result.absolute? |
562 |
+ args.reverse_each {|arg| |
563 |
+ arg = Pathname.new(arg) unless Pathname === arg |
564 |
+ result = arg + result |
565 |
+ return result if result.absolute? |
566 |
+ } |
567 |
+ result |
568 |
+ end |
569 |
+ |
570 |
+ # |
571 |
+ # Returns the children of the directory (files and subdirectories, not |
572 |
+ # recursive) as an array of Pathname objects. By default, the returned |
573 |
+ # pathnames will have enough information to access the files. If you set |
574 |
+ # +with_directory+ to +false+, then the returned pathnames will contain the |
575 |
+ # filename only. |
576 |
+ # |
577 |
+ # For example: |
578 |
+ # pn = Pathname("/usr/lib/ruby/1.8") |
579 |
+ # pn.children |
580 |
+ # # -> [ Pathname:/usr/lib/ruby/1.8/English.rb, |
581 |
+ # Pathname:/usr/lib/ruby/1.8/Env.rb, |
582 |
+ # Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ] |
583 |
+ # pn.children(false) |
584 |
+ # # -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ] |
585 |
+ # |
586 |
+ # Note that the result never contain the entries <tt>.</tt> and <tt>..</tt> in |
587 |
+ # the directory because they are not children. |
588 |
+ # |
589 |
+ # This method has existed since 1.8.1. |
590 |
+ # |
591 |
+ def children(with_directory=true) |
592 |
+ with_directory = false if @path == '.' |
593 |
+ result = [] |
594 |
+ Dir.foreach(@path) {|e| |
595 |
+ next if e == '.' || e == '..' |
596 |
+ if with_directory |
597 |
+ result << self.class.new(File.join(@path, e)) |
598 |
+ else |
599 |
+ result << self.class.new(e) |
600 |
+ end |
601 |
+ } |
602 |
+ result |
603 |
+ end |
604 |
+ |
605 |
+ # Iterates over the children of the directory |
606 |
+ # (files and subdirectories, not recursive). |
607 |
+ # It yields Pathname object for each child. |
608 |
+ # By default, the yielded pathnames will have enough information to access the files. |
609 |
+ # If you set +with_directory+ to +false+, then the returned pathnames will contain the filename only. |
610 |
+ # |
611 |
+ # Pathname("/usr/local").each_child {|f| p f } |
612 |
+ # #=> #<Pathname:/usr/local/share> |
613 |
+ # # #<Pathname:/usr/local/bin> |
614 |
+ # # #<Pathname:/usr/local/games> |
615 |
+ # # #<Pathname:/usr/local/lib> |
616 |
+ # # #<Pathname:/usr/local/include> |
617 |
+ # # #<Pathname:/usr/local/sbin> |
618 |
+ # # #<Pathname:/usr/local/src> |
619 |
+ # # #<Pathname:/usr/local/man> |
620 |
+ # |
621 |
+ # Pathname("/usr/local").each_child(false) {|f| p f } |
622 |
+ # #=> #<Pathname:share> |
623 |
+ # # #<Pathname:bin> |
624 |
+ # # #<Pathname:games> |
625 |
+ # # #<Pathname:lib> |
626 |
+ # # #<Pathname:include> |
627 |
+ # # #<Pathname:sbin> |
628 |
+ # # #<Pathname:src> |
629 |
+ # # #<Pathname:man> |
630 |
+ # |
631 |
+ def each_child(with_directory=true, &b) |
632 |
+ children(with_directory).each(&b) |
633 |
+ end |
634 |
+ |
635 |
+ # |
636 |
+ # #relative_path_from returns a relative path from the argument to the |
637 |
+ # receiver. If +self+ is absolute, the argument must be absolute too. If |
638 |
+ # +self+ is relative, the argument must be relative too. |
639 |
+ # |
640 |
+ # #relative_path_from doesn't access the filesystem. It assumes no symlinks. |
641 |
+ # |
642 |
+ # ArgumentError is raised when it cannot find a relative path. |
643 |
+ # |
644 |
+ # This method has existed since 1.8.1. |
645 |
+ # |
646 |
+ def relative_path_from(base_directory) |
647 |
+ dest_directory = self.cleanpath.to_s |
648 |
+ base_directory = base_directory.cleanpath.to_s |
649 |
+ dest_prefix = dest_directory |
650 |
+ dest_names = [] |
651 |
+ while r = chop_basename(dest_prefix) |
652 |
+ dest_prefix, basename = r |
653 |
+ dest_names.unshift basename if basename != '.' |
654 |
+ end |
655 |
+ base_prefix = base_directory |
656 |
+ base_names = [] |
657 |
+ while r = chop_basename(base_prefix) |
658 |
+ base_prefix, basename = r |
659 |
+ base_names.unshift basename if basename != '.' |
660 |
+ end |
661 |
+ unless SAME_PATHS[dest_prefix, base_prefix] |
662 |
+ raise ArgumentError, "different prefix: #{dest_prefix.inspect} and #{base_directory.inspect}" |
663 |
+ end |
664 |
+ while !dest_names.empty? && |
665 |
+ !base_names.empty? && |
666 |
+ SAME_PATHS[dest_names.first, base_names.first] |
667 |
+ dest_names.shift |
668 |
+ base_names.shift |
669 |
+ end |
670 |
+ if base_names.include? '..' |
671 |
+ raise ArgumentError, "base_directory has ..: #{base_directory.inspect}" |
672 |
+ end |
673 |
+ base_names.fill('..') |
674 |
+ relpath_names = base_names + dest_names |
675 |
+ if relpath_names.empty? |
676 |
+ Pathname.new('.') |
677 |
+ else |
678 |
+ Pathname.new(File.join(*relpath_names)) |
679 |
+ end |
680 |
+ end |
681 |
+ end |
682 |
+ |
683 |
+ class Pathname # * IO * |
684 |
+ # |
685 |
+ # #each_line iterates over the line in the file. It yields a String object |
686 |
+ # for each line. |
687 |
+ # |
688 |
+ # This method has existed since 1.8.1. |
689 |
+ # |
690 |
+ def each_line(*args, &block) # :yield: line |
691 |
+ IO.foreach(@path, *args, &block) |
692 |
+ end |
693 |
+ |
694 |
+ # See <tt>IO.read</tt>. Returns all data from the file, or the first +N+ bytes |
695 |
+ # if specified. |
696 |
+ def read(*args) IO.read(@path, *args) end |
697 |
+ |
698 |
+ # See <tt>IO.binread</tt>. Returns all the bytes from the file, or the first +N+ |
699 |
+ # if specified. |
700 |
+ def binread(*args) IO.binread(@path, *args) end |
701 |
+ |
702 |
+ # See <tt>IO.readlines</tt>. Returns all the lines from the file. |
703 |
+ def readlines(*args) IO.readlines(@path, *args) end |
704 |
+ |
705 |
+ # See <tt>IO.sysopen</tt>. |
706 |
+ def sysopen(*args) IO.sysopen(@path, *args) end |
707 |
+ end |
708 |
+ |
709 |
+ |
710 |
+ class Pathname # * File * |
711 |
+ |
712 |
+ # See <tt>File.atime</tt>. Returns last access time. |
713 |
+ def atime() File.atime(@path) end |
714 |
+ |
715 |
+ # See <tt>File.ctime</tt>. Returns last (directory entry, not file) change time. |
716 |
+ def ctime() File.ctime(@path) end |
717 |
+ |
718 |
+ # See <tt>File.mtime</tt>. Returns last modification time. |
719 |
+ def mtime() File.mtime(@path) end |
720 |
+ |
721 |
+ # See <tt>File.chmod</tt>. Changes permissions. |
722 |
+ def chmod(mode) File.chmod(mode, @path) end |
723 |
+ |
724 |
+ # See <tt>File.lchmod</tt>. |
725 |
+ def lchmod(mode) File.lchmod(mode, @path) end |
726 |
+ |
727 |
+ # See <tt>File.chown</tt>. Change owner and group of file. |
728 |
+ def chown(owner, group) File.chown(owner, group, @path) end |
729 |
+ |
730 |
+ # See <tt>File.lchown</tt>. |
731 |
+ def lchown(owner, group) File.lchown(owner, group, @path) end |
732 |
+ |
733 |
+ # See <tt>File.fnmatch</tt>. Return +true+ if the receiver matches the given |
734 |
+ # pattern. |
735 |
+ def fnmatch(pattern, *args) File.fnmatch(pattern, @path, *args) end |
736 |
+ |
737 |
+ # See <tt>File.fnmatch?</tt> (same as #fnmatch). |
738 |
+ def fnmatch?(pattern, *args) File.fnmatch?(pattern, @path, *args) end |
739 |
+ |
740 |
+ # See <tt>File.ftype</tt>. Returns "type" of file ("file", "directory", |
741 |
+ # etc). |
742 |
+ def ftype() File.ftype(@path) end |
743 |
+ |
744 |
+ # See <tt>File.link</tt>. Creates a hard link. |
745 |
+ def make_link(old) File.link(old, @path) end |
746 |
+ |
747 |
+ # See <tt>File.open</tt>. Opens the file for reading or writing. |
748 |
+ def open(*args, &block) # :yield: file |
749 |
+ File.open(@path, *args, &block) |
750 |
+ end |
751 |
+ |
752 |
+ # See <tt>File.readlink</tt>. Read symbolic link. |
753 |
+ def readlink() self.class.new(File.readlink(@path)) end |
754 |
+ |
755 |
+ # See <tt>File.rename</tt>. Rename the file. |
756 |
+ def rename(to) File.rename(@path, to) end |
757 |
+ |
758 |
+ # See <tt>File.stat</tt>. Returns a <tt>File::Stat</tt> object. |
759 |
+ def stat() File.stat(@path) end |
760 |
+ |
761 |
+ # See <tt>File.lstat</tt>. |
762 |
+ def lstat() File.lstat(@path) end |
763 |
+ |
764 |
+ # See <tt>File.symlink</tt>. Creates a symbolic link. |
765 |
+ def make_symlink(old) File.symlink(old, @path) end |
766 |
+ |
767 |
+ # See <tt>File.truncate</tt>. Truncate the file to +length+ bytes. |
768 |
+ def truncate(length) File.truncate(@path, length) end |
769 |
+ |
770 |
+ # See <tt>File.utime</tt>. Update the access and modification times. |
771 |
+ def utime(atime, mtime) File.utime(atime, mtime, @path) end |
772 |
+ |
773 |
+ # See <tt>File.basename</tt>. Returns the last component of the path. |
774 |
+ def basename(*args) self.class.new(File.basename(@path, *args)) end |
775 |
+ |
776 |
+ # See <tt>File.dirname</tt>. Returns all but the last component of the path. |
777 |
+ def dirname() self.class.new(File.dirname(@path)) end |
778 |
+ |
779 |
+ # See <tt>File.extname</tt>. Returns the file's extension. |
780 |
+ def extname() File.extname(@path) end |
781 |
+ |
782 |
+ # See <tt>File.expand_path</tt>. |
783 |
+ def expand_path(*args) self.class.new(File.expand_path(@path, *args)) end |
784 |
+ |
785 |
+ # See <tt>File.split</tt>. Returns the #dirname and the #basename in an |
786 |
+ # Array. |
787 |
+ def split() File.split(@path).map {|f| self.class.new(f) } end |
788 |
+ end |
789 |
+ |
790 |
+ |
791 |
+ class Pathname # * FileTest * |
792 |
+ |
793 |
+ # See <tt>FileTest.blockdev?</tt>. |
794 |
+ def blockdev?() FileTest.blockdev?(@path) end |
795 |
+ |
796 |
+ # See <tt>FileTest.chardev?</tt>. |
797 |
+ def chardev?() FileTest.chardev?(@path) end |
798 |
+ |
799 |
+ # See <tt>FileTest.executable?</tt>. |
800 |
+ def executable?() FileTest.executable?(@path) end |
801 |
+ |
802 |
+ # See <tt>FileTest.executable_real?</tt>. |
803 |
+ def executable_real?() FileTest.executable_real?(@path) end |
804 |
+ |
805 |
+ # See <tt>FileTest.exist?</tt>. |
806 |
+ def exist?() FileTest.exist?(@path) end |
807 |
+ |
808 |
+ # See <tt>FileTest.grpowned?</tt>. |
809 |
+ def grpowned?() FileTest.grpowned?(@path) end |
810 |
+ |
811 |
+ # See <tt>FileTest.directory?</tt>. |
812 |
+ def directory?() FileTest.directory?(@path) end |
813 |
+ |
814 |
+ # See <tt>FileTest.file?</tt>. |
815 |
+ def file?() FileTest.file?(@path) end |
816 |
+ |
817 |
+ # See <tt>FileTest.pipe?</tt>. |
818 |
+ def pipe?() FileTest.pipe?(@path) end |
819 |
+ |
820 |
+ # See <tt>FileTest.socket?</tt>. |
821 |
+ def socket?() FileTest.socket?(@path) end |
822 |
+ |
823 |
+ # See <tt>FileTest.owned?</tt>. |
824 |
+ def owned?() FileTest.owned?(@path) end |
825 |
+ |
826 |
+ # See <tt>FileTest.readable?</tt>. |
827 |
+ def readable?() FileTest.readable?(@path) end |
828 |
+ |
829 |
+ # See <tt>FileTest.world_readable?</tt>. |
830 |
+ def world_readable?() FileTest.world_readable?(@path) end |
831 |
+ |
832 |
+ # See <tt>FileTest.readable_real?</tt>. |
833 |
+ def readable_real?() FileTest.readable_real?(@path) end |
834 |
+ |
835 |
+ # See <tt>FileTest.setuid?</tt>. |
836 |
+ def setuid?() FileTest.setuid?(@path) end |
837 |
+ |
838 |
+ # See <tt>FileTest.setgid?</tt>. |
839 |
+ def setgid?() FileTest.setgid?(@path) end |
840 |
+ |
841 |
+ # See <tt>FileTest.size</tt>. |
842 |
+ def size() FileTest.size(@path) end |
843 |
+ |
844 |
+ # See <tt>FileTest.size?</tt>. |
845 |
+ def size?() FileTest.size?(@path) end |
846 |
+ |
847 |
+ # See <tt>FileTest.sticky?</tt>. |
848 |
+ def sticky?() FileTest.sticky?(@path) end |
849 |
+ |
850 |
+ # See <tt>FileTest.symlink?</tt>. |
851 |
+ def symlink?() FileTest.symlink?(@path) end |
852 |
+ |
853 |
+ # See <tt>FileTest.writable?</tt>. |
854 |
+ def writable?() FileTest.writable?(@path) end |
855 |
+ |
856 |
+ # See <tt>FileTest.world_writable?</tt>. |
857 |
+ def world_writable?() FileTest.world_writable?(@path) end |
858 |
+ |
859 |
+ # See <tt>FileTest.writable_real?</tt>. |
860 |
+ def writable_real?() FileTest.writable_real?(@path) end |
861 |
+ |
862 |
+ # See <tt>FileTest.zero?</tt>. |
863 |
+ def zero?() FileTest.zero?(@path) end |
864 |
+ end |
865 |
+ |
866 |
+ |
867 |
+ class Pathname # * Dir * |
868 |
+ # See <tt>Dir.glob</tt>. Returns or yields Pathname objects. |
869 |
+ def Pathname.glob(*args) # :yield: pathname |
870 |
+ if block_given? |
871 |
+ Dir.glob(*args) {|f| yield self.new(f) } |
872 |
+ else |
873 |
+ Dir.glob(*args).map {|f| self.new(f) } |
874 |
+ end |
875 |
+ end |
876 |
+ |
877 |
+ # See <tt>Dir.getwd</tt>. Returns the current working directory as a Pathname. |
878 |
+ def Pathname.getwd() self.new(Dir.getwd) end |
879 |
+ class << self; alias pwd getwd end |
880 |
+ |
881 |
+ # Return the entries (files and subdirectories) in the directory, each as a |
882 |
+ # Pathname object. |
883 |
+ def entries() Dir.entries(@path).map {|f| self.class.new(f) } end |
884 |
+ |
885 |
+ # Iterates over the entries (files and subdirectories) in the directory. It |
886 |
+ # yields a Pathname object for each entry. |
887 |
+ # |
888 |
+ # This method has existed since 1.8.1. |
889 |
+ def each_entry(&block) # :yield: pathname |
890 |
+ Dir.foreach(@path) {|f| yield self.class.new(f) } |
891 |
+ end |
892 |
+ |
893 |
+ # See <tt>Dir.mkdir</tt>. Create the referenced directory. |
894 |
+ def mkdir(*args) Dir.mkdir(@path, *args) end |
895 |
+ |
896 |
+ # See <tt>Dir.rmdir</tt>. Remove the referenced directory. |
897 |
+ def rmdir() Dir.rmdir(@path) end |
898 |
+ |
899 |
+ # See <tt>Dir.open</tt>. |
900 |
+ def opendir(&block) # :yield: dir |
901 |
+ Dir.open(@path, &block) |
902 |
+ end |
903 |
+ end |
904 |
+ |
905 |
+ |
906 |
+ class Pathname # * Find * |
907 |
+ # |
908 |
+ # Pathname#find is an iterator to traverse a directory tree in a depth first |
909 |
+ # manner. It yields a Pathname for each file under "this" directory. |
910 |
+ # |
911 |
+ # Since it is implemented by <tt>find.rb</tt>, <tt>Find.prune</tt> can be used |
912 |
+ # to control the traverse. |
913 |
+ # |
914 |
+ # If +self+ is <tt>.</tt>, yielded pathnames begin with a filename in the |
915 |
+ # current directory, not <tt>./</tt>. |
916 |
+ # |
917 |
+ def find(&block) # :yield: pathname |
918 |
+ require 'find' |
919 |
+ if @path == '.' |
920 |
+ Find.find(@path) {|f| yield self.class.new(f.sub(%r{\A\./}, '')) } |
921 |
+ else |
922 |
+ Find.find(@path) {|f| yield self.class.new(f) } |
923 |
+ end |
924 |
+ end |
925 |
+ end |
926 |
+ |
927 |
+ |
928 |
+ class Pathname # * FileUtils * |
929 |
+ # See <tt>FileUtils.mkpath</tt>. Creates a full path, including any |
930 |
+ # intermediate directories that don't yet exist. |
931 |
+ def mkpath |
932 |
+ require 'fileutils' |
933 |
+ FileUtils.mkpath(@path) |
934 |
+ nil |
935 |
+ end |
936 |
+ |
937 |
+ # See <tt>FileUtils.rm_r</tt>. Deletes a directory and all beneath it. |
938 |
+ def rmtree |
939 |
+ # The name "rmtree" is borrowed from File::Path of Perl. |
940 |
+ # File::Path provides "mkpath" and "rmtree". |
941 |
+ require 'fileutils' |
942 |
+ FileUtils.rm_r(@path) |
943 |
+ nil |
944 |
+ end |
945 |
+ end |
946 |
+ |
947 |
+ |
948 |
+ class Pathname # * mixed * |
949 |
+ # Removes a file or directory, using <tt>File.unlink</tt> or |
950 |
+ # <tt>Dir.unlink</tt> as necessary. |
951 |
+ def unlink() |
952 |
+ begin |
953 |
+ Dir.unlink @path |
954 |
+ rescue Errno::ENOTDIR |
955 |
+ File.unlink @path |
956 |
+ end |
957 |
+ end |
958 |
+ alias delete unlink |
959 |
+ end |
960 |
+ |
961 |
+ class Pathname |
962 |
+ undef =~ |
963 |
+ end |
964 |
+ end # RUBY_VERSION >= 1.9.3 |
965 |
+end |
966 |
+ |
967 |
|
968 |
|
969 |
|
970 |
1.1 dev-ruby/fakefs/files/fakefs-0.4.0-ruby193.patch |
971 |
|
972 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193.patch?rev=1.1&view=markup |
973 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193.patch?rev=1.1&content-type=text/plain |
974 |
|
975 |
Index: fakefs-0.4.0-ruby193.patch |
976 |
=================================================================== |
977 |
commit af733ea5606391c594fb5e228fc1e94515c1e7e4 |
978 |
Author: Mateusz Juraszek <meceo00@×××××.com> |
979 |
Date: Tue Jan 3 11:00:56 2012 +0100 |
980 |
|
981 |
add external encoding as default to File @content string, |
982 |
handle hash as second parameter to File::new, |
983 |
extend FakeFS::FileSystem::clone method to accept 'target' as a optional parameter, |
984 |
fix Dir::mkdir for nested structure |
985 |
|
986 |
diff --git a/lib/fakefs/dir.rb b/lib/fakefs/dir.rb |
987 |
index 628626f..ed571ff 100644 |
988 |
--- a/lib/fakefs/dir.rb |
989 |
+++ b/lib/fakefs/dir.rb |
990 |
@@ -105,7 +105,7 @@ module FakeFS |
991 |
parent = string.split('/') |
992 |
parent.pop |
993 |
|
994 |
- joined_parent_path = parent.join |
995 |
+ joined_parent_path = parent.join("/") |
996 |
|
997 |
_check_for_valid_file(joined_parent_path) unless joined_parent_path == "" |
998 |
raise Errno::EEXIST, "File exists - #{string}" if File.exists?(string) |
999 |
diff --git a/lib/fakefs/fake/file.rb b/lib/fakefs/fake/file.rb |
1000 |
index 10bdf7f..22f32d9 100644 |
1001 |
--- a/lib/fakefs/fake/file.rb |
1002 |
+++ b/lib/fakefs/fake/file.rb |
1003 |
@@ -5,7 +5,8 @@ module FakeFS |
1004 |
|
1005 |
class Inode |
1006 |
def initialize(file_owner) |
1007 |
- @content = "" |
1008 |
+ #1.9.3 when possible set default external encoding |
1009 |
+ @content = "".respond_to?(:encode) ? "".encode(Encoding.default_external) : "" |
1010 |
@links = [file_owner] |
1011 |
end |
1012 |
|
1013 |
diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb |
1014 |
index 5684ede..5f36376 100644 |
1015 |
--- a/lib/fakefs/file.rb |
1016 |
+++ b/lib/fakefs/file.rb |
1017 |
@@ -275,7 +275,7 @@ module FakeFS |
1018 |
|
1019 |
def initialize(path, mode = READ_ONLY, perm = nil) |
1020 |
@path = path |
1021 |
- @mode = mode |
1022 |
+ @mode = mode.is_a?(Hash) ? (mode[:mode] || READ_ONLY) : mode |
1023 |
@file = FileSystem.find(path) |
1024 |
@autoclose = true |
1025 |
|
1026 |
@@ -283,7 +283,7 @@ module FakeFS |
1027 |
|
1028 |
file_creation_mode? ? create_missing_file : check_file_existence! |
1029 |
|
1030 |
- super(@file.content, mode) |
1031 |
+ super(@file.content, @mode) |
1032 |
end |
1033 |
|
1034 |
def exists? |
1035 |
diff --git a/lib/fakefs/file_system.rb b/lib/fakefs/file_system.rb |
1036 |
index a5c8087..da58ad9 100644 |
1037 |
--- a/lib/fakefs/file_system.rb |
1038 |
+++ b/lib/fakefs/file_system.rb |
1039 |
@@ -46,19 +46,20 @@ module FakeFS |
1040 |
|
1041 |
# copies directories and files from the real filesystem |
1042 |
# into our fake one |
1043 |
- def clone(path) |
1044 |
+ def clone(path, target = nil) |
1045 |
path = File.expand_path(path) |
1046 |
pattern = File.join(path, '**', '*') |
1047 |
files = RealFile.file?(path) ? [path] : [path] + RealDir.glob(pattern, RealFile::FNM_DOTMATCH) |
1048 |
|
1049 |
files.each do |f| |
1050 |
+ target_path = target ? f.gsub(path, target) : f |
1051 |
if RealFile.file?(f) |
1052 |
FileUtils.mkdir_p(File.dirname(f)) |
1053 |
- File.open(f, File::WRITE_ONLY) do |g| |
1054 |
+ File.open(target_path, File::WRITE_ONLY) do |g| |
1055 |
g.print RealFile.open(f){|h| h.read } |
1056 |
end |
1057 |
elsif RealFile.directory?(f) |
1058 |
- FileUtils.mkdir_p(f) |
1059 |
+ FileUtils.mkdir_p(target_path) |
1060 |
elsif RealFile.symlink?(f) |
1061 |
FileUtils.ln_s() |
1062 |
end |
1063 |
diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb |
1064 |
index 0f34950..7e2b8dc 100644 |
1065 |
--- a/test/fakefs_test.rb |
1066 |
+++ b/test/fakefs_test.rb |
1067 |
@@ -647,6 +647,21 @@ class FakeFSTest < Test::Unit::TestCase |
1068 |
assert_equal "Yatta!", File.new(path).read |
1069 |
end |
1070 |
|
1071 |
+ if RUBY_VERSION >= "1.9" |
1072 |
+ def test_file_object_has_default_external_encoding |
1073 |
+ Encoding.default_external = "UTF-8" |
1074 |
+ path = 'file.txt' |
1075 |
+ File.open(path, 'w'){|f| f.write 'Yatta!' } |
1076 |
+ assert_equal "UTF-8", File.new(path).read.encoding.name |
1077 |
+ end |
1078 |
+ end |
1079 |
+ |
1080 |
+ def test_file_object_initialization_with_mode_in_hash_parameter |
1081 |
+ assert_nothing_raised do |
1082 |
+ File.open("file.txt", {:mode => "w"}){ |f| f.write 'Yatta!' } |
1083 |
+ end |
1084 |
+ end |
1085 |
+ |
1086 |
def test_file_read_errors_appropriately |
1087 |
assert_raise Errno::ENOENT do |
1088 |
File.read('anything') |
1089 |
@@ -1132,24 +1147,18 @@ class FakeFSTest < Test::Unit::TestCase |
1090 |
end |
1091 |
|
1092 |
def test_clone_clones_directories |
1093 |
- FakeFS.deactivate! |
1094 |
- RealFileUtils.mkdir_p(here('subdir')) |
1095 |
- FakeFS.activate! |
1096 |
+ act_on_real_fs { RealFileUtils.mkdir_p(here('subdir')) } |
1097 |
|
1098 |
FileSystem.clone(here('subdir')) |
1099 |
|
1100 |
assert File.exists?(here('subdir')), 'subdir was cloned' |
1101 |
assert File.directory?(here('subdir')), 'subdir is a directory' |
1102 |
ensure |
1103 |
- FakeFS.deactivate! |
1104 |
- RealFileUtils.rm_rf(here('subdir')) |
1105 |
- FakeFS.activate! |
1106 |
+ act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) } |
1107 |
end |
1108 |
|
1109 |
def test_clone_clones_dot_files_even_hard_to_find_ones |
1110 |
- FakeFS.deactivate! |
1111 |
- RealFileUtils.mkdir_p(here('subdir/.bar/baz/.quux/foo')) |
1112 |
- FakeFS.activate! |
1113 |
+ act_on_real_fs { RealFileUtils.mkdir_p(here('subdir/.bar/baz/.quux/foo')) } |
1114 |
|
1115 |
assert !File.exists?(here('subdir')) |
1116 |
|
1117 |
@@ -1157,9 +1166,20 @@ class FakeFSTest < Test::Unit::TestCase |
1118 |
assert_equal ['.bar'], FileSystem.find(here('subdir')).keys |
1119 |
assert_equal ['foo'], FileSystem.find(here('subdir/.bar/baz/.quux')).keys |
1120 |
ensure |
1121 |
- FakeFS.deactivate! |
1122 |
- RealFileUtils.rm_rf(here('subdir')) |
1123 |
- FakeFS.activate! |
1124 |
+ act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) } |
1125 |
+ end |
1126 |
+ |
1127 |
+ def test_clone_with_target_specified |
1128 |
+ act_on_real_fs { RealFileUtils.mkdir_p(here('subdir/.bar/baz/.quux/foo')) } |
1129 |
+ |
1130 |
+ assert !File.exists?(here('subdir')) |
1131 |
+ |
1132 |
+ FileSystem.clone(here('subdir'), here('subdir2')) |
1133 |
+ assert !File.exists?(here('subdir')) |
1134 |
+ assert_equal ['.bar'], FileSystem.find(here('subdir2')).keys |
1135 |
+ assert_equal ['foo'], FileSystem.find(here('subdir2/.bar/baz/.quux')).keys |
1136 |
+ ensure |
1137 |
+ act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) } |
1138 |
end |
1139 |
|
1140 |
def test_putting_a_dot_at_end_copies_the_contents |
1141 |
@@ -1464,6 +1484,12 @@ class FakeFSTest < Test::Unit::TestCase |
1142 |
assert File.exists?('/path') |
1143 |
end |
1144 |
|
1145 |
+ def test_directory_mkdir_nested |
1146 |
+ Dir.mkdir("/tmp") |
1147 |
+ Dir.mkdir("/tmp/stream20120103-11847-xc8pb.lock") |
1148 |
+ assert File.exists?("/tmp/stream20120103-11847-xc8pb.lock") |
1149 |
+ end |
1150 |
+ |
1151 |
def test_directory_mkdir_relative |
1152 |
FileUtils.mkdir_p('/new/root') |
1153 |
FileSystem.chdir('/new/root') |
1154 |
diff --git a/test/test_helper.rb b/test/test_helper.rb |
1155 |
index c41dd67..b6596fa 100644 |
1156 |
--- a/test/test_helper.rb |
1157 |
+++ b/test/test_helper.rb |
1158 |
@@ -5,4 +5,11 @@ require 'test/unit' |
1159 |
begin |
1160 |
require 'redgreen' |
1161 |
rescue LoadError |
1162 |
-end |
1163 |
\ No newline at end of file |
1164 |
+end |
1165 |
+ |
1166 |
+def act_on_real_fs |
1167 |
+ raise ArgumentError unless block_given? |
1168 |
+ FakeFS.deactivate! |
1169 |
+ yield |
1170 |
+ FakeFS.activate! |
1171 |
+end |
1172 |
|
1173 |
|
1174 |
|
1175 |
1.1 dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-advise.patch |
1176 |
|
1177 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-advise.patch?rev=1.1&view=markup |
1178 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/fakefs/files/fakefs-0.4.0-ruby193-advise.patch?rev=1.1&content-type=text/plain |
1179 |
|
1180 |
Index: fakefs-0.4.0-ruby193-advise.patch |
1181 |
=================================================================== |
1182 |
commit 332735b52720466ca8eb9e089cc42f128d54b644 |
1183 |
Author: Lukas Oberhuber <lukaso@×××××.com> |
1184 |
Date: Tue Dec 20 09:19:05 2011 +0000 |
1185 |
|
1186 |
Add advise function to File which is in ruby 1.9.3. As it is only a hint to the |
1187 |
os in some cases, the function does nothing. |
1188 |
|
1189 |
diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb |
1190 |
index 5684ede..ebc3ff8 100644 |
1191 |
--- a/lib/fakefs/file.rb |
1192 |
+++ b/lib/fakefs/file.rb |
1193 |
@@ -392,6 +392,11 @@ module FakeFS |
1194 |
end |
1195 |
end |
1196 |
|
1197 |
+ if RUBY_VERSION >= "1.9.3" |
1198 |
+ def advise(advice, offset=0, len=0) |
1199 |
+ end |
1200 |
+ end |
1201 |
+ |
1202 |
private |
1203 |
|
1204 |
def check_modes! |
1205 |
diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb |
1206 |
index 0f34950..1d5bf7a 100644 |
1207 |
--- a/test/fakefs_test.rb |
1208 |
+++ b/test/fakefs_test.rb |
1209 |
@@ -1861,4 +1861,14 @@ class FakeFSTest < Test::Unit::TestCase |
1210 |
end |
1211 |
end |
1212 |
end |
1213 |
+ |
1214 |
+ if RUBY_VERSION >= "1.9.3" |
1215 |
+ def test_advise |
1216 |
+ File.open("foo", 'w') do |f| |
1217 |
+ assert_nothing_raised do |
1218 |
+ f.advise(:normal, 0, 0) |
1219 |
+ end |
1220 |
+ end |
1221 |
+ end |
1222 |
+ end |
1223 |
end |