Skip to content

Commit

Permalink
Ensuring File.new on a symlink raises if the target is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
simonc committed Aug 6, 2016
1 parent 5d8c2a5 commit 90607ac
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/memfs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ def initialize(filename, mode = File::RDONLY, *perm_and_or_opt)
fs.touch(filename) if create_file?

self.entry = fs.find!(filename)
# FIXME: this is an ugly way to ensure a symlink has a target
entry.dereferenced

entry.content.clear if truncate_file?
end
Expand Down
8 changes: 0 additions & 8 deletions spec/memfs/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -792,14 +792,6 @@ module MemFs
is_symlink = described_class.lstat('/test-link').symlink?
expect(is_symlink).to be true
end

context 'and its target does not exist' do
it 'ignores errors' do
expect {
described_class.lstat('/no-link')
}.not_to raise_error
end
end
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/memfs/file_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ module MemFs

describe '#symlink' do
it 'creates a symbolic link' do
subject.touch('/some-file')
subject.symlink('/some-file', '/some-link')
expect(subject.find!('/some-link')).to be_a(Fake::Symlink)
end
Expand Down

0 comments on commit 90607ac

Please sign in to comment.