From c0be5bd8f280a0ef9c7c880159243bcdb397d73b Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Mon, 1 Jun 2009 04:13:53 -0700 Subject: [PATCH] cp_r given a src ending in '/.' now copies over the contents of the src dir. --- lib/fakefs.rb | 8 +++++++- test/fakefs_test.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/fakefs.rb b/lib/fakefs.rb index 3197b68..9f670c3 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -38,8 +38,14 @@ module FakeFS raise Errno::ENOENT, dest end + # This last bit is a total abuse and should be thought hard + # about and cleaned up. if new_dir - new_dir[dir.name] = dir.entry.clone + if src[-2..-1] == '/.' + dir.values.each{|f| new_dir[f.name] = f } + else + new_dir[dir.name] = dir.entry.clone + end else FileSystem.add(dest, dir.entry.clone) end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index d48365c..de0d34f 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -354,6 +354,15 @@ class FakeFSTest < Test::Unit::TestCase RealFile.unlink(here('foo')) if RealFile.exists?(here('foo')) end + def test_putting_a_dot_at_end_copies_the_contents + FileUtils.mkdir_p 'subdir' + Dir.chdir('subdir'){ File.open('foo', 'w'){|f| f.write 'footext' } } + + FileUtils.mkdir_p 'newdir' + FileUtils.cp_r 'subdir/.', 'newdir' + assert_equal 'footext', File.open('newdir/foo'){|f| f.read } + end + def test_file_can_read_from_symlinks File.open('first', 'w'){|f| f.write '1'} FileUtils.ln_s 'first', 'one'