when copying or moving files, ensure the new parent gets set correctly
This commit is contained in:
parent
98215fe488
commit
04a6a7a527
@ -38,10 +38,10 @@ module FakeFS
|
||||
end
|
||||
|
||||
if dst_file and File.directory?(dst_file)
|
||||
FileSystem.add(File.join(dest, src), src_file.entry.clone)
|
||||
FileSystem.add(File.join(dest, src), src_file.entry.clone(dest))
|
||||
else
|
||||
FileSystem.delete(dest)
|
||||
FileSystem.add(dest, src_file.entry.clone)
|
||||
FileSystem.add(dest, src_file.entry.clone(dest))
|
||||
end
|
||||
end
|
||||
|
||||
@ -66,16 +66,16 @@ module FakeFS
|
||||
if src[-2..-1] == '/.'
|
||||
dir.values.each{|f| new_dir[f.name] = f }
|
||||
else
|
||||
new_dir[dir.name] = dir.entry.clone
|
||||
new_dir[dir.name] = dir.entry.clone(new_dir)
|
||||
end
|
||||
else
|
||||
FileSystem.add(dest, dir.entry.clone)
|
||||
FileSystem.add(dest, dir.entry.clone(dest))
|
||||
end
|
||||
end
|
||||
|
||||
def mv(src, dest)
|
||||
if target = FileSystem.find(src)
|
||||
FileSystem.add(dest, target.entry.clone)
|
||||
FileSystem.add(dest, target.entry.clone(dest))
|
||||
FileSystem.delete(src)
|
||||
else
|
||||
raise Errno::ENOENT, src
|
||||
@ -350,6 +350,12 @@ module FakeFS
|
||||
@content = ''
|
||||
end
|
||||
|
||||
def clone(parent)
|
||||
clone = super()
|
||||
clone.parent = parent
|
||||
clone
|
||||
end
|
||||
|
||||
def entry
|
||||
self
|
||||
end
|
||||
@ -371,6 +377,14 @@ module FakeFS
|
||||
self
|
||||
end
|
||||
|
||||
def clone(parent)
|
||||
clone = super()
|
||||
clone.each do |key, value|
|
||||
value.parent = parent
|
||||
end
|
||||
clone
|
||||
end
|
||||
|
||||
def to_s
|
||||
if parent && parent.to_s != '.'
|
||||
File.join(parent.to_s, name)
|
||||
|
@ -175,8 +175,15 @@ class FakeFSTest < Test::Unit::TestCase
|
||||
FileUtils.mkdir_p '/path'
|
||||
File.open('/path/foo', 'w'){|f| f.write 'foo' }
|
||||
File.open('/path/foobar', 'w'){|f| f.write 'foo' }
|
||||
|
||||
FileUtils.mkdir_p '/path/bar'
|
||||
File.open('/path/bar/baz', 'w'){|f| f.write 'foo' }
|
||||
|
||||
assert_equal ['/path'], Dir['/path']
|
||||
assert_equal ['/path/foo', '/path/foobar'], Dir['/path/*']
|
||||
assert_equal ['/path/bar', '/path/foo', '/path/foobar'], Dir['/path/*']
|
||||
|
||||
assert_equal ['/path/bar/baz'], Dir['/path/bar/*']
|
||||
|
||||
# Unsupported so far. More hackery than I want to work on right now
|
||||
# assert_equal ['/path'], Dir['/path*']
|
||||
end
|
||||
@ -445,7 +452,7 @@ class FakeFSTest < Test::Unit::TestCase
|
||||
FileUtils.ln_s 'subdir', 'new'
|
||||
assert_equal 'works', File.open('new/nother'){|f| f.read }
|
||||
end
|
||||
|
||||
|
||||
def test_files_can_be_touched
|
||||
FileUtils.touch('touched_file')
|
||||
assert File.exists?('touched_file')
|
||||
|
Loading…
Reference in New Issue
Block a user