virtfs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +154 -0
- data/Rakefile +5 -0
- data/lib/virtfs-nativefs-thick.rb +1 -0
- data/lib/virtfs-nativefs-thin.rb +1 -0
- data/lib/virtfs.rb +38 -0
- data/lib/virtfs/activation.rb +97 -0
- data/lib/virtfs/block_io.rb +140 -0
- data/lib/virtfs/byte_range.rb +71 -0
- data/lib/virtfs/context.rb +300 -0
- data/lib/virtfs/context_manager.rb +175 -0
- data/lib/virtfs/context_switch_class_methods.rb +96 -0
- data/lib/virtfs/delegate_module.rb +40 -0
- data/lib/virtfs/dir_instance_delegate.rb +3 -0
- data/lib/virtfs/exception.rb +13 -0
- data/lib/virtfs/file_instance_delegate.rb +3 -0
- data/lib/virtfs/file_modes_and_options.rb +293 -0
- data/lib/virtfs/find_class_methods.rb +106 -0
- data/lib/virtfs/io_buffer.rb +133 -0
- data/lib/virtfs/io_instance_delegate.rb +3 -0
- data/lib/virtfs/kernel.rb +146 -0
- data/lib/virtfs/nativefs/thick.rb +30 -0
- data/lib/virtfs/nativefs/thick/dir_class_methods.rb +38 -0
- data/lib/virtfs/nativefs/thick/file_class_methods.rb +178 -0
- data/lib/virtfs/nativefs/thin.rb +32 -0
- data/lib/virtfs/nativefs/thin/dir.rb +30 -0
- data/lib/virtfs/nativefs/thin/dir_class_methods.rb +41 -0
- data/lib/virtfs/nativefs/thin/file.rb +112 -0
- data/lib/virtfs/nativefs/thin/file_class_methods.rb +181 -0
- data/lib/virtfs/protofs/protofs.rb +7 -0
- data/lib/virtfs/protofs/protofs_base.rb +12 -0
- data/lib/virtfs/protofs/protofs_dir.rb +13 -0
- data/lib/virtfs/protofs/protofs_dir_class.rb +31 -0
- data/lib/virtfs/protofs/protofs_file.rb +27 -0
- data/lib/virtfs/protofs/protofs_file_class.rb +136 -0
- data/lib/virtfs/stat.rb +100 -0
- data/lib/virtfs/thin_dir_delegator.rb +79 -0
- data/lib/virtfs/thin_file_delegator.rb +77 -0
- data/lib/virtfs/thin_io_delegator_methods.rb +301 -0
- data/lib/virtfs/thin_io_delegator_methods_bufferio.rb +337 -0
- data/lib/virtfs/v_dir.rb +238 -0
- data/lib/virtfs/v_file.rb +480 -0
- data/lib/virtfs/v_io.rb +243 -0
- data/lib/virtfs/v_pathname.rb +128 -0
- data/lib/virtfs/version.rb +3 -0
- data/spec/activate_spec.rb +202 -0
- data/spec/chroot_spec.rb +120 -0
- data/spec/context_manager_class_spec.rb +246 -0
- data/spec/context_manager_instance_spec.rb +255 -0
- data/spec/context_spec.rb +335 -0
- data/spec/data/UTF-16LE-data.txt +0 -0
- data/spec/data/UTF-8-data.txt +212 -0
- data/spec/dir_class_spec.rb +506 -0
- data/spec/dir_instance_spec.rb +208 -0
- data/spec/file_class_spec.rb +2106 -0
- data/spec/file_instance_spec.rb +154 -0
- data/spec/file_modes_and_options_spec.rb +1556 -0
- data/spec/find_spec.rb +142 -0
- data/spec/io_bufferio_size_shared_examples.rb +371 -0
- data/spec/io_bufferio_size_spec.rb +861 -0
- data/spec/io_bufferio_spec.rb +801 -0
- data/spec/io_class_spec.rb +145 -0
- data/spec/io_instance_spec.rb +516 -0
- data/spec/kernel_spec.rb +285 -0
- data/spec/mount_spec.rb +186 -0
- data/spec/nativefs_local_root_spec.rb +132 -0
- data/spec/path_spec.rb +39 -0
- data/spec/spec_helper.rb +126 -0
- data/tasks/rspec.rake +3 -0
- data/tasks/yard.rake +7 -0
- data/test/UTF-8-demo.txt +212 -0
- data/test/bench.rb +18 -0
- data/test/bio_internal_test.rb +45 -0
- data/test/delegate_io.rb +31 -0
- data/test/delegate_module.rb +62 -0
- data/test/encode_test.rb +42 -0
- data/test/enoent_test.rb +30 -0
- data/test/namespace_test.rb +42 -0
- data/test/read_block_valid_encoding.rb +44 -0
- data/test/read_test.rb +78 -0
- data/test/stream_readers.rb +46 -0
- data/test/utf-16-demo.txt +0 -0
- data/test/utf8_to_utf16.rb +77 -0
- data/test/wrapper_test.rb +34 -0
- data/virtfs.gemspec +29 -0
- metadata +230 -0
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VirtFS::VDir, "(#{$fs_interface} interface)" do
|
4
|
+
before(:all) do
|
5
|
+
@full_path = File.expand_path(__FILE__)
|
6
|
+
@rel_path = File.basename(@full_path)
|
7
|
+
@spec_dir = File.dirname(@full_path)
|
8
|
+
@this_dir = VfsRealDir.getwd
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
reset_context
|
13
|
+
@root = File::SEPARATOR
|
14
|
+
|
15
|
+
@native_fs = nativefs_class.new
|
16
|
+
VirtFS.mount(@native_fs, @root)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#close" do
|
20
|
+
it "should return nil" do
|
21
|
+
dir = VirtFS::VDir.new(@spec_dir)
|
22
|
+
expect(dir.close).to be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should cause subsequent access to raise IOError: closed directory" do
|
26
|
+
dir = VirtFS::VDir.new(@spec_dir)
|
27
|
+
dir.close
|
28
|
+
|
29
|
+
expect { dir.close }.to raise_error(IOError, "closed directory")
|
30
|
+
expect { dir.each.to_a }.to raise_error(IOError, "closed directory")
|
31
|
+
expect { dir.pos = 0 }.to raise_error(IOError, "closed directory")
|
32
|
+
expect { dir.read }.to raise_error(IOError, "closed directory")
|
33
|
+
expect { dir.rewind }.to raise_error(IOError, "closed directory")
|
34
|
+
expect { dir.seek(0) }.to raise_error(IOError, "closed directory")
|
35
|
+
expect { dir.tell }.to raise_error(IOError, "closed directory")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#each" do
|
40
|
+
it "should return an enum when no block is given" do
|
41
|
+
VirtFS::VDir.open(@spec_dir) { |dir| expect(dir.each).to be_kind_of(Enumerator) }
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the directory object when block is given" do
|
45
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
46
|
+
expect(dir.each { |f| true }).to eq(dir)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should enumerate the same files as the standard Dir method" do
|
51
|
+
VirtFS::VDir.open(@spec_dir) do |dir1|
|
52
|
+
VfsRealDir.open(@spec_dir) do |dir2|
|
53
|
+
expect(dir1.each.to_a).to match_array(dir2.each.to_a)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#path #to_path" do
|
60
|
+
it "should return full path when opened with full path" do
|
61
|
+
VirtFS::VDir.open(@spec_dir) { |dir| expect(dir.path).to eq(@spec_dir) }
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return relative path when opened with relative path" do
|
65
|
+
parent, target_dir = VfsRealFile.split(@spec_dir)
|
66
|
+
VirtFS::VDir.chdir(parent)
|
67
|
+
VirtFS::VDir.open(target_dir) { |dir| expect(dir.path).to eq(target_dir) }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#pos #tell" do
|
72
|
+
it "should return the same value when the current position hasn't changed" do
|
73
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
74
|
+
expect(dir.pos).to eq(dir.pos)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return a different value when the current position has changed" do
|
79
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
80
|
+
pos1 = dir.pos
|
81
|
+
dir.read
|
82
|
+
expect(dir.pos).to_not eq(pos1)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#pos=" do
|
88
|
+
it "should return the passed value" do
|
89
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
90
|
+
(0..4).each { |p| expect(dir.pos = p).to eq(p) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should change the position when given a value previously returned by #tell or #pos" do
|
95
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
96
|
+
pos0 = dir.pos
|
97
|
+
dir.read
|
98
|
+
pos1 = dir.pos
|
99
|
+
expect(pos0).to_not eq(pos1)
|
100
|
+
expect(dir.pos).to eq(pos1)
|
101
|
+
dir.pos = pos0
|
102
|
+
expect(dir.pos).to eq(pos0)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# NOTE: This test fails when run under Fusion shared folders,
|
108
|
+
# but only for the thick interface. Passes on Travis.
|
109
|
+
#
|
110
|
+
it "should change the position for subsequent reads" do
|
111
|
+
reads_by_pos = {}
|
112
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
113
|
+
reads_by_pos[dir.pos] = dir.read
|
114
|
+
dir.read
|
115
|
+
dir.read
|
116
|
+
reads_by_pos[dir.pos] = dir.read
|
117
|
+
dir.read
|
118
|
+
reads_by_pos[dir.pos] = dir.read
|
119
|
+
|
120
|
+
reads_by_pos.each do |p, r|
|
121
|
+
dir.pos = p
|
122
|
+
expect(dir.read).to eq(r)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#read" do
|
129
|
+
it "should read successive directory entries, returning the same files as Dir#each" do
|
130
|
+
dir_entries = []
|
131
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
132
|
+
while de = dir.read
|
133
|
+
dir_entries << de
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
VfsRealDir.open(@spec_dir) do |dir|
|
138
|
+
expect(dir.each.to_a).to match_array(dir_entries)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return nil when at end of directory" do
|
143
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
144
|
+
while (de = dir.read); end
|
145
|
+
expect(dir.read).to be_nil
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#rewind" do
|
151
|
+
it "should return the directory object" do
|
152
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
153
|
+
expect(dir.rewind).to eq(dir)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should reset the current position so reading starts at the beginning" do
|
158
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
159
|
+
first_entry = dir.read
|
160
|
+
while (de = dir.read); end
|
161
|
+
expect(dir.read).to be_nil
|
162
|
+
dir.rewind
|
163
|
+
expect(dir.read).to eq(first_entry)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#seek" do
|
169
|
+
it "should return the directory object" do
|
170
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
171
|
+
(0..4).each { |p| expect(dir.seek(p)).to eq(dir) }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should change the position when given a value previously returned by #tell or #pos" do
|
176
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
177
|
+
pos0 = dir.tell
|
178
|
+
dir.read
|
179
|
+
pos1 = dir.tell
|
180
|
+
expect(pos0).to_not eq(pos1)
|
181
|
+
expect(dir.tell).to eq(pos1)
|
182
|
+
dir.seek(pos0)
|
183
|
+
expect(dir.tell).to eq(pos0)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# NOTE: This test fails when run under Fusion shared folders,
|
189
|
+
# but only for the thick interface. Passes on Travis.
|
190
|
+
#
|
191
|
+
it "should change the position for subsequent reads" do
|
192
|
+
reads_by_pos = {}
|
193
|
+
VirtFS::VDir.open(@spec_dir) do |dir|
|
194
|
+
reads_by_pos[dir.tell] = dir.read
|
195
|
+
dir.read
|
196
|
+
dir.read
|
197
|
+
reads_by_pos[dir.tell] = dir.read
|
198
|
+
dir.read
|
199
|
+
reads_by_pos[dir.tell] = dir.read
|
200
|
+
|
201
|
+
reads_by_pos.each do |p, r|
|
202
|
+
dir.seek(p)
|
203
|
+
expect(dir.read).to eq(r)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,2106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Class methods.
|
5
|
+
#
|
6
|
+
describe VirtFS::VFile, "(#{$fs_interface} interface)" do
|
7
|
+
before(:all) do
|
8
|
+
@spec_name = VfsRealFile.basename(__FILE__, ".rb")
|
9
|
+
@temp_prefix = "#{@spec_name}-"
|
10
|
+
@this_dir = VfsRealDir.getwd
|
11
|
+
@root = File::SEPARATOR
|
12
|
+
@slink_path = temp_name(@temp_prefix, ".symlink")
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
reset_context
|
17
|
+
@ext = ".rb"
|
18
|
+
@temp_file = Tempfile.new([@temp_prefix, @ext])
|
19
|
+
@data1 = "0123456789" * 4
|
20
|
+
@temp_file.write(@data1)
|
21
|
+
@temp_file.close
|
22
|
+
@full_path = @temp_file.path
|
23
|
+
@rel_path = File.basename(@full_path)
|
24
|
+
@parent_dir = File.dirname(@full_path)
|
25
|
+
VfsRealFile.chown(Process.uid, Process.gid, @full_path)
|
26
|
+
|
27
|
+
@ext2 = ".c"
|
28
|
+
@temp_file2 = Tempfile.new([@temp_prefix, @ext2])
|
29
|
+
@temp_file2.close
|
30
|
+
@full_path2 = @temp_file2.path
|
31
|
+
@rel_path2 = File.basename(@full_path2)
|
32
|
+
@parent_dir2 = File.dirname(@full_path2)
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:each) do
|
36
|
+
@temp_file.delete
|
37
|
+
@temp_file2.delete
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".absolute_path" do
|
41
|
+
it "should return the same path as the standard File.absolute_path, when given a dirstring" do
|
42
|
+
expect(
|
43
|
+
VirtFS::VFile.absolute_path(@rel_path, @parent_dir)
|
44
|
+
).to eq(
|
45
|
+
VfsRealFile.absolute_path(@rel_path, @parent_dir)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return the same path as the standard File.absolute_path, when using pwd" do
|
50
|
+
VfsRealDir.chdir(@parent_dir) do
|
51
|
+
VirtFS.cwd = VfsRealDir.getwd
|
52
|
+
expect(VirtFS::VFile.absolute_path(@rel_path)).to eq(VfsRealFile.absolute_path(@rel_path))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".atime" do
|
58
|
+
context "with no filesystems mounted" do
|
59
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
60
|
+
expect do
|
61
|
+
VirtFS::VFile.atime("nonexistent_file")
|
62
|
+
end.to raise_error(
|
63
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
68
|
+
expect do
|
69
|
+
VirtFS::VFile.atime(@full_path)
|
70
|
+
end.to raise_error(
|
71
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with FS mounted on '/'" do
|
77
|
+
before(:each) do
|
78
|
+
@native_fs = nativefs_class.new
|
79
|
+
VirtFS.mount(@native_fs, @root)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
83
|
+
expect do
|
84
|
+
VirtFS::VFile.atime("nonexistent_file")
|
85
|
+
end.to raise_error(
|
86
|
+
Errno::ENOENT, /No such file or directory/
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return the same value as the standard File.atime, when given a full path" do
|
91
|
+
expect(VirtFS::VFile.atime(@full_path)).to eq(VfsRealFile.atime(@full_path))
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return the same value as the standard File.atime, when given relative path" do
|
95
|
+
VfsRealDir.chdir(@parent_dir) do
|
96
|
+
VirtFS.dir_chdir(@parent_dir)
|
97
|
+
expect(VirtFS::VFile.atime(@rel_path)).to eq(VfsRealFile.atime(@rel_path))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe ".basename" do
|
104
|
+
it "should return the same value as the standard File.basename" do
|
105
|
+
expect(VirtFS::VFile.basename(@full_path)).to eq(VfsRealFile.basename(@full_path))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe ".blockdev?" do
|
110
|
+
context "with no filesystems mounted" do
|
111
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
112
|
+
expect do
|
113
|
+
VirtFS::VFile.blockdev?("nonexistent_file")
|
114
|
+
end.to raise_error(
|
115
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
120
|
+
expect do
|
121
|
+
VirtFS::VFile.blockdev?(@full_path)
|
122
|
+
end.to raise_error(
|
123
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
124
|
+
)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with FS mounted on '/'" do
|
129
|
+
before(:each) do
|
130
|
+
@native_fs = nativefs_class.new
|
131
|
+
VirtFS.mount(@native_fs, @root)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return false when given a nonexistent file" do
|
135
|
+
expect(VirtFS::VFile.blockdev?("nonexistent_file")).to be false
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should return false when given a non-blockdev file" do
|
139
|
+
expect(VirtFS::VFile.blockdev?(@full_path)).to be false
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# The block_dev_file method fails to find a block device
|
144
|
+
# file in the Travis environment - disabling this test.
|
145
|
+
#
|
146
|
+
# it "should return true when given a blockdev file" do
|
147
|
+
# expect(bdev = block_dev_file).to_not eq(nil)
|
148
|
+
# expect(VirtFS::VFile.blockdev?(bdev)).to be true
|
149
|
+
# end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe ".chardev?" do
|
154
|
+
context "with no filesystems mounted" do
|
155
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
156
|
+
expect do
|
157
|
+
VirtFS::VFile.chardev?("nonexistent_file")
|
158
|
+
end.to raise_error(
|
159
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
164
|
+
expect do
|
165
|
+
VirtFS::VFile.chardev?(@full_path)
|
166
|
+
end.to raise_error(
|
167
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
168
|
+
)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "with FS mounted on '/'" do
|
173
|
+
before(:each) do
|
174
|
+
@native_fs = nativefs_class.new
|
175
|
+
VirtFS.mount(@native_fs, @root)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should return false when given a nonexistent file" do
|
179
|
+
expect(VirtFS::VFile.chardev?("nonexistent_file")).to be false
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should return false when given a non-chardev file" do
|
183
|
+
expect(VirtFS::VFile.chardev?(@full_path)).to be false
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should return true when given a chardev file" do
|
187
|
+
expect(cdev = char_dev_file).to_not eq(nil)
|
188
|
+
expect(VirtFS::VFile.chardev?(cdev)).to be true
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe ".chmod" do
|
194
|
+
context "with no filesystems mounted" do
|
195
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
196
|
+
expect do
|
197
|
+
VirtFS::VFile.chmod(0755, "nonexistent_file")
|
198
|
+
end.to raise_error(
|
199
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
204
|
+
expect do
|
205
|
+
VirtFS::VFile.chmod(0755, @full_path)
|
206
|
+
end.to raise_error(
|
207
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
208
|
+
)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "with FS mounted on '/'" do
|
213
|
+
before(:each) do
|
214
|
+
@native_fs = nativefs_class.new
|
215
|
+
VirtFS.mount(@native_fs, @root)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
219
|
+
expect do
|
220
|
+
VirtFS::VFile.chmod(0755, "nonexistent_file")
|
221
|
+
end.to raise_error(
|
222
|
+
Errno::ENOENT, /No such file or directory/
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should return the number of files processed" do
|
227
|
+
expect(VirtFS::VFile.chmod(0777, @full_path)).to eq(1)
|
228
|
+
expect(VirtFS::VFile.chmod(0777, @full_path, @full_path2)).to eq(2)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should change the permission bits on an existing file" do
|
232
|
+
target_mode = 0755
|
233
|
+
expect(VfsRealFile.stat(@full_path).mode & 0777).to_not eq(target_mode)
|
234
|
+
VirtFS::VFile.chmod(target_mode, @full_path)
|
235
|
+
expect(VfsRealFile.stat(@full_path).mode & 0777).to eq(target_mode)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe ".chown" do
|
241
|
+
before(:each) do
|
242
|
+
stat = VfsRealFile.stat(@full_path)
|
243
|
+
@owner = stat.uid
|
244
|
+
@group = stat.gid
|
245
|
+
end
|
246
|
+
|
247
|
+
context "with no filesystems mounted" do
|
248
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
249
|
+
expect do
|
250
|
+
VirtFS::VFile.chown(@owner, @group, "nonexistent_file")
|
251
|
+
end.to raise_error(
|
252
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
253
|
+
)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
257
|
+
expect do
|
258
|
+
VirtFS::VFile.chown(@owner, @group, @full_path)
|
259
|
+
end.to raise_error(
|
260
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
261
|
+
)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "with FS mounted on '/'" do
|
266
|
+
before(:each) do
|
267
|
+
@native_fs = nativefs_class.new
|
268
|
+
VirtFS.mount(@native_fs, @root)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
272
|
+
expect do
|
273
|
+
VirtFS::VFile.chown(@owner, @group, "nonexistent_file")
|
274
|
+
end.to raise_error(
|
275
|
+
Errno::ENOENT, /No such file or directory/
|
276
|
+
)
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should return the number of files processed" do
|
280
|
+
expect(VirtFS::VFile.chown(@owner, @group, @full_path)).to eq(1)
|
281
|
+
expect(VirtFS::VFile.chown(@owner, @group, @full_path, @full_path2)).to eq(2)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
describe ".ctime" do
|
287
|
+
context "with no filesystems mounted" do
|
288
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
289
|
+
expect do
|
290
|
+
VirtFS::VFile.ctime("nonexistent_file")
|
291
|
+
end.to raise_error(
|
292
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
293
|
+
)
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
297
|
+
expect do
|
298
|
+
VirtFS::VFile.ctime(@full_path)
|
299
|
+
end.to raise_error(
|
300
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
301
|
+
)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "with FS mounted on '/'" do
|
306
|
+
before(:each) do
|
307
|
+
@native_fs = nativefs_class.new
|
308
|
+
VirtFS.mount(@native_fs, @root)
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
312
|
+
expect do
|
313
|
+
VirtFS::VFile.ctime("nonexistent_file")
|
314
|
+
end.to raise_error(
|
315
|
+
Errno::ENOENT, /No such file or directory/
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should return the same value as the standard File.ctime, when given a full path" do
|
320
|
+
expect(VirtFS::VFile.ctime(@full_path)).to eq(VfsRealFile.ctime(@full_path))
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should return the same value as the standard File.ctime, when given relative path" do
|
324
|
+
VfsRealDir.chdir(@parent_dir) do
|
325
|
+
VirtFS.dir_chdir(@parent_dir)
|
326
|
+
expect(VirtFS::VFile.ctime(@rel_path)).to eq(VfsRealFile.ctime(@rel_path))
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe ".delete" do
|
333
|
+
context "with no filesystems mounted" do
|
334
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
335
|
+
expect do
|
336
|
+
VirtFS::VFile.delete("nonexistent_file")
|
337
|
+
end.to raise_error(
|
338
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
339
|
+
)
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
343
|
+
expect do
|
344
|
+
VirtFS::VFile.delete(@full_path)
|
345
|
+
end.to raise_error(
|
346
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
347
|
+
)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context "with FS mounted on '/'" do
|
352
|
+
before(:each) do
|
353
|
+
@native_fs = nativefs_class.new
|
354
|
+
VirtFS.mount(@native_fs, @root)
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
358
|
+
expect do
|
359
|
+
VirtFS::VFile.delete("nonexistent_file")
|
360
|
+
end.to raise_error(
|
361
|
+
Errno::ENOENT, /No such file or directory/
|
362
|
+
)
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should return the number of files processed - 1" do
|
366
|
+
expect(VirtFS::VFile.delete(@full_path)).to eq(1)
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should return the number of files processed - 2" do
|
370
|
+
expect(VirtFS::VFile.delete(@full_path, @full_path2)).to eq(2)
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should change the permission bits on an existing file" do
|
374
|
+
expect(VfsRealFile.exist?(@full_path)).to be true
|
375
|
+
VirtFS::VFile.delete(@full_path)
|
376
|
+
expect(VfsRealFile.exist?(@full_path)).to_not be true
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe ".directory?" do
|
382
|
+
context "with no filesystems mounted" do
|
383
|
+
it "should raise Errno::ENOENT when given a nonexistent directory" do
|
384
|
+
expect do
|
385
|
+
VirtFS::VFile.directory?("nonexistent_directory")
|
386
|
+
end.to raise_error(
|
387
|
+
Errno::ENOENT, "No such file or directory - nonexistent_directory"
|
388
|
+
)
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should raise Errno::ENOENT when given a directory that exists in the native FS" do
|
392
|
+
expect do
|
393
|
+
VirtFS::VFile.directory?(@parent_dir)
|
394
|
+
end.to raise_error(
|
395
|
+
Errno::ENOENT, "No such file or directory - #{@parent_dir}"
|
396
|
+
)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context "with FS mounted on '/'" do
|
401
|
+
before(:each) do
|
402
|
+
@native_fs = nativefs_class.new
|
403
|
+
VirtFS.mount(@native_fs, @root)
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should return false when given a nonexistent directory" do
|
407
|
+
expect(VirtFS::VFile.directory?("nonexistent_directory")).to be false
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should return false when given a regular file" do
|
411
|
+
expect(VirtFS::VFile.directory?(@full_path)).to be false
|
412
|
+
end
|
413
|
+
|
414
|
+
it "should return true when given a directory" do
|
415
|
+
expect(VirtFS::VFile.directory?(@parent_dir)).to be true
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe ".executable?" do
|
421
|
+
context "with no filesystems mounted" do
|
422
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
423
|
+
expect do
|
424
|
+
VirtFS::VFile.executable?("nonexistent_file")
|
425
|
+
end.to raise_error(
|
426
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
427
|
+
)
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
431
|
+
expect do
|
432
|
+
VirtFS::VFile.executable?(@full_path)
|
433
|
+
end.to raise_error(
|
434
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
435
|
+
)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
context "with FS mounted on '/'" do
|
440
|
+
before(:each) do
|
441
|
+
@native_fs = nativefs_class.new
|
442
|
+
VirtFS.mount(@native_fs, @root)
|
443
|
+
end
|
444
|
+
|
445
|
+
it "should return false when given a nonexistent file" do
|
446
|
+
expect(VirtFS::VFile.executable?("nonexistent_file")).to be false
|
447
|
+
end
|
448
|
+
|
449
|
+
it "should return false when given a non-executable file" do
|
450
|
+
expect(VirtFS::VFile.executable?(@full_path)).to be false
|
451
|
+
end
|
452
|
+
|
453
|
+
it "should return true when given a executable file" do
|
454
|
+
VfsRealFile.chmod(0100, @full_path)
|
455
|
+
expect(VirtFS::VFile.executable?(@full_path)).to be true
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
describe ".executable_real?" do
|
461
|
+
context "with no filesystems mounted" do
|
462
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
463
|
+
expect do
|
464
|
+
VirtFS::VFile.executable_real?("nonexistent_file")
|
465
|
+
end.to raise_error(
|
466
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
467
|
+
)
|
468
|
+
end
|
469
|
+
|
470
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
471
|
+
expect do
|
472
|
+
VirtFS::VFile.executable_real?(@full_path)
|
473
|
+
end.to raise_error(
|
474
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
475
|
+
)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
context "with FS mounted on '/'" do
|
480
|
+
before(:each) do
|
481
|
+
@native_fs = nativefs_class.new
|
482
|
+
VirtFS.mount(@native_fs, @root)
|
483
|
+
end
|
484
|
+
|
485
|
+
it "should return false when given a nonexistent file" do
|
486
|
+
expect(VirtFS::VFile.executable_real?("nonexistent_file")).to be false
|
487
|
+
end
|
488
|
+
|
489
|
+
it "should return false when given a non-executable file" do
|
490
|
+
expect(VirtFS::VFile.executable_real?(@full_path)).to be false
|
491
|
+
end
|
492
|
+
|
493
|
+
it "should return true when given a executable file" do
|
494
|
+
VfsRealFile.chmod(0100, @full_path)
|
495
|
+
expect(VirtFS::VFile.executable_real?(@full_path)).to be true
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
describe ".exist?" do
|
501
|
+
context "with no filesystems mounted" do
|
502
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
503
|
+
expect do
|
504
|
+
VirtFS::VFile.exist?("nonexistent_file")
|
505
|
+
end.to raise_error(
|
506
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
507
|
+
)
|
508
|
+
end
|
509
|
+
|
510
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
511
|
+
expect do
|
512
|
+
VirtFS::VFile.exist?(@parent_dir)
|
513
|
+
end.to raise_error(
|
514
|
+
Errno::ENOENT, "No such file or directory - #{@parent_dir}"
|
515
|
+
)
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
context "with FS mounted on '/'" do
|
520
|
+
before(:each) do
|
521
|
+
@native_fs = nativefs_class.new
|
522
|
+
VirtFS.mount(@native_fs, @root)
|
523
|
+
end
|
524
|
+
|
525
|
+
it "should return false when given a nonexistent file" do
|
526
|
+
expect(VirtFS::VFile.exist?("nonexistent_directory")).to be false
|
527
|
+
end
|
528
|
+
|
529
|
+
it "should return true when given a regular file" do
|
530
|
+
expect(VirtFS::VFile.exist?(@full_path)).to be true
|
531
|
+
end
|
532
|
+
|
533
|
+
it "should return true when given a directory" do
|
534
|
+
expect(VirtFS::VFile.exist?(@parent_dir)).to be true
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
describe ".expand_path" do
|
540
|
+
it "should return the same path as the standard File.expand_path, when given a dirstring" do
|
541
|
+
expect(VirtFS::VFile.expand_path(@rel_path, @parent_dir)).to eq(VfsRealFile.expand_path(@rel_path, @parent_dir))
|
542
|
+
end
|
543
|
+
|
544
|
+
it "should return the same path as the standard File.expand_path, when using pwd" do
|
545
|
+
VfsRealDir.chdir(@parent_dir) do
|
546
|
+
VirtFS.cwd = VfsRealDir.getwd
|
547
|
+
expect(VirtFS::VFile.expand_path(@rel_path)).to eq(VfsRealFile.expand_path(@rel_path))
|
548
|
+
end
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
describe ".extname" do
|
553
|
+
it "should return the known extension of tempfile 1" do
|
554
|
+
expect(VirtFS::VFile.extname(@full_path)).to eq(@ext)
|
555
|
+
end
|
556
|
+
|
557
|
+
it "should return the known extension of tempfile 2" do
|
558
|
+
expect(VirtFS::VFile.extname(@full_path2)).to eq(@ext2)
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
describe ".file?" do
|
563
|
+
context "with no filesystems mounted" do
|
564
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
565
|
+
expect do
|
566
|
+
VirtFS::VFile.file?("nonexistent_file")
|
567
|
+
end.to raise_error(
|
568
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
569
|
+
)
|
570
|
+
end
|
571
|
+
|
572
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
573
|
+
expect do
|
574
|
+
VirtFS::VFile.file?(@parent_dir)
|
575
|
+
end.to raise_error(
|
576
|
+
Errno::ENOENT, "No such file or directory - #{@parent_dir}"
|
577
|
+
)
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
context "with FS mounted on '/'" do
|
582
|
+
before(:each) do
|
583
|
+
@native_fs = nativefs_class.new
|
584
|
+
VirtFS.mount(@native_fs, @root)
|
585
|
+
end
|
586
|
+
|
587
|
+
it "should return false when given a nonexistent file" do
|
588
|
+
expect(VirtFS::VFile.file?("nonexistent_directory")).to be false
|
589
|
+
end
|
590
|
+
|
591
|
+
it "should return true when given a regular file" do
|
592
|
+
expect(VirtFS::VFile.file?(@full_path)).to be true
|
593
|
+
end
|
594
|
+
|
595
|
+
it "should return false when given a directory" do
|
596
|
+
expect(VirtFS::VFile.file?(@parent_dir)).to be false
|
597
|
+
end
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
describe ".fnmatch" do
|
602
|
+
it "should match representative examples" do
|
603
|
+
expect(VirtFS::VFile.fnmatch('cat', 'cat')).to be true
|
604
|
+
expect(VirtFS::VFile.fnmatch('cat', 'category')).to be false
|
605
|
+
expect(VirtFS::VFile.fnmatch('c?t', 'cat')).to be true
|
606
|
+
expect(VirtFS::VFile.fnmatch('c\?t', 'cat')).to be false
|
607
|
+
expect(VirtFS::VFile.fnmatch('c??t', 'cat')).to be false
|
608
|
+
expect(VirtFS::VFile.fnmatch('c*', 'cats')).to be true
|
609
|
+
expect(VirtFS::VFile.fnmatch('c/**/t', 'c/a/b/c/t')).to be true
|
610
|
+
expect(VirtFS::VFile.fnmatch('c**t', 'c/a/b/c/t')).to be true
|
611
|
+
expect(VirtFS::VFile.fnmatch('c**t', 'cat')).to be true
|
612
|
+
expect(VirtFS::VFile.fnmatch('**.txt', 'notes.txt')).to be true
|
613
|
+
expect(VirtFS::VFile.fnmatch('**.txt', 'some/dir/tree/notes.txt')).to be true
|
614
|
+
expect(VirtFS::VFile.fnmatch('c*t', 'cat')).to be true
|
615
|
+
expect(VirtFS::VFile.fnmatch('c\at', 'cat')).to be true
|
616
|
+
expect(VirtFS::VFile.fnmatch('c\at', 'cat', File::FNM_NOESCAPE)).to be false
|
617
|
+
expect(VirtFS::VFile.fnmatch('a?b', 'a/b')).to be true
|
618
|
+
expect(VirtFS::VFile.fnmatch('a?b', 'a/b', File::FNM_PATHNAME)).to be false
|
619
|
+
expect(VirtFS::VFile.fnmatch('*', '.profile')).to be false
|
620
|
+
expect(VirtFS::VFile.fnmatch('*', '.profile', File::FNM_DOTMATCH)).to be true
|
621
|
+
expect(VirtFS::VFile.fnmatch('*', 'dave/.profile')).to be true
|
622
|
+
expect(VirtFS::VFile.fnmatch('*', 'dave/.profile', File::FNM_DOTMATCH)).to be true
|
623
|
+
expect(VirtFS::VFile.fnmatch('*', 'dave/.profile', File::FNM_PATHNAME)).to be false
|
624
|
+
expect(VirtFS::VFile.fnmatch('*/*', 'dave/.profile', File::FNM_PATHNAME)).to be false
|
625
|
+
strict = File::FNM_PATHNAME | File::FNM_DOTMATCH
|
626
|
+
expect(VirtFS::VFile.fnmatch('*/*', 'dave/.profile', strict)).to be true
|
627
|
+
end
|
628
|
+
end
|
629
|
+
|
630
|
+
describe ".ftype" do
|
631
|
+
context "with no filesystems mounted" do
|
632
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
633
|
+
expect do
|
634
|
+
VirtFS::VFile.ftype("nonexistent_file")
|
635
|
+
end.to raise_error(
|
636
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
637
|
+
)
|
638
|
+
end
|
639
|
+
|
640
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
641
|
+
expect do
|
642
|
+
VirtFS::VFile.ftype(@full_path)
|
643
|
+
end.to raise_error(
|
644
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
645
|
+
)
|
646
|
+
end
|
647
|
+
end
|
648
|
+
|
649
|
+
context "with FS mounted on '/'" do
|
650
|
+
before(:each) do
|
651
|
+
@native_fs = nativefs_class.new
|
652
|
+
VirtFS.mount(@native_fs, @root)
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
656
|
+
expect do
|
657
|
+
VirtFS::VFile.ftype("nonexistent_file")
|
658
|
+
end.to raise_error(
|
659
|
+
Errno::ENOENT, /No such file or directory/
|
660
|
+
)
|
661
|
+
end
|
662
|
+
|
663
|
+
it "should return 'file' when given a regular file" do
|
664
|
+
expect(VirtFS::VFile.ftype(@full_path)).to eq('file')
|
665
|
+
end
|
666
|
+
|
667
|
+
it "should return 'directory' when given a directory" do
|
668
|
+
expect(VirtFS::VFile.ftype(@parent_dir)).to eq('directory')
|
669
|
+
end
|
670
|
+
|
671
|
+
#
|
672
|
+
# The block_dev_file method fails to find a block device
|
673
|
+
# file in the Travis environment - disabling this test.
|
674
|
+
#
|
675
|
+
# it "should return 'blockSpecial,' when given a block device file" do
|
676
|
+
# expect(bdev = block_dev_file).to_not eq(nil)
|
677
|
+
# expect(VirtFS::VFile.ftype(bdev)).to eq('blockSpecial')
|
678
|
+
# end
|
679
|
+
|
680
|
+
it "should return 'characterSpecial,' when given a block device file" do
|
681
|
+
expect(cdev = char_dev_file).to_not eq(nil)
|
682
|
+
expect(VirtFS::VFile.ftype(cdev)).to eq('characterSpecial')
|
683
|
+
end
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
describe ".grpowned?" do
|
688
|
+
context "with no filesystems mounted" do
|
689
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
690
|
+
expect do
|
691
|
+
VirtFS::VFile.grpowned?("nonexistent_file")
|
692
|
+
end.to raise_error(
|
693
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
694
|
+
)
|
695
|
+
end
|
696
|
+
|
697
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
698
|
+
expect do
|
699
|
+
VirtFS::VFile.grpowned?(@full_path)
|
700
|
+
end.to raise_error(
|
701
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
702
|
+
)
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
context "with FS mounted on '/'" do
|
707
|
+
before(:each) do
|
708
|
+
@native_fs = nativefs_class.new
|
709
|
+
VirtFS.mount(@native_fs, @root)
|
710
|
+
end
|
711
|
+
|
712
|
+
it "should return false when given a nonexistent file" do
|
713
|
+
expect(VirtFS::VFile.grpowned?("nonexistent_file")).to be false
|
714
|
+
end
|
715
|
+
|
716
|
+
it "should return true when given a file we created" do
|
717
|
+
expect(VirtFS::VFile.grpowned?(@full_path)).to be true
|
718
|
+
end
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
describe ".identical?" do
|
723
|
+
before(:each) do
|
724
|
+
VfsRealFile.symlink(@full_path, @slink_path)
|
725
|
+
end
|
726
|
+
|
727
|
+
after(:each) do
|
728
|
+
VfsRealFile.delete(@slink_path)
|
729
|
+
end
|
730
|
+
|
731
|
+
context "with no filesystems mounted" do
|
732
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
733
|
+
expect do
|
734
|
+
VirtFS::VFile.identical?("nonexistent_file1", "nonexistent_file2")
|
735
|
+
end.to raise_error(
|
736
|
+
Errno::ENOENT, /No such file or directory/
|
737
|
+
)
|
738
|
+
end
|
739
|
+
|
740
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
741
|
+
expect do
|
742
|
+
VirtFS::VFile.identical?(@full_path, @slink_path)
|
743
|
+
end.to raise_error(
|
744
|
+
Errno::ENOENT, /No such file or directory/
|
745
|
+
)
|
746
|
+
end
|
747
|
+
end
|
748
|
+
|
749
|
+
context "with FS mounted on '/'" do
|
750
|
+
before(:each) do
|
751
|
+
@native_fs = nativefs_class.new
|
752
|
+
VirtFS.mount(@native_fs, @root)
|
753
|
+
end
|
754
|
+
|
755
|
+
it "should return false when given a nonexistent file" do
|
756
|
+
expect(VirtFS::VFile.identical?(@full_path, "nonexistent_file1")).to be false
|
757
|
+
end
|
758
|
+
|
759
|
+
it "should return true when given the same file" do
|
760
|
+
expect(VirtFS::VFile.identical?(@full_path, @full_path)).to be true
|
761
|
+
end
|
762
|
+
|
763
|
+
it "should return true when given a file and its symlink" do
|
764
|
+
expect(VirtFS::VFile.identical?(@full_path, @slink_path)).to be true
|
765
|
+
end
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
describe ".join" do
|
770
|
+
it "should return the same path as the standard File.join" do
|
771
|
+
dirs = %( dir1 dir2 dir3 dir4 dir5 )
|
772
|
+
expect(VirtFS::VFile.join(dirs)).to eq(VfsRealFile.join(dirs))
|
773
|
+
end
|
774
|
+
end
|
775
|
+
|
776
|
+
if VfsRealFile.respond_to?(:lchmod)
|
777
|
+
describe ".lchmod" do
|
778
|
+
context "with no filesystems mounted" do
|
779
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
780
|
+
expect do
|
781
|
+
VirtFS::VFile.lchmod(0755, "nonexistent_file")
|
782
|
+
end.to raise_error(
|
783
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
784
|
+
)
|
785
|
+
end
|
786
|
+
|
787
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
788
|
+
expect do
|
789
|
+
VirtFS::VFile.lchmod(0755, @full_path)
|
790
|
+
end.to raise_error(
|
791
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
792
|
+
)
|
793
|
+
end
|
794
|
+
end
|
795
|
+
|
796
|
+
context "with FS mounted on '/'" do
|
797
|
+
before(:each) do
|
798
|
+
@native_fs = nativefs_class.new
|
799
|
+
VirtFS.mount(@native_fs, @root)
|
800
|
+
end
|
801
|
+
|
802
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
803
|
+
expect do
|
804
|
+
VirtFS::VFile.lchmod(0755, "nonexistent_file")
|
805
|
+
end.to raise_error(
|
806
|
+
Errno::ENOENT, /No such file or directory/
|
807
|
+
)
|
808
|
+
end
|
809
|
+
|
810
|
+
it "should return the number of files processed" do
|
811
|
+
expect(VirtFS::VFile.lchmod(0777, @full_path)).to eq(1)
|
812
|
+
expect(VirtFS::VFile.lchmod(0777, @full_path, @full_path2)).to eq(2)
|
813
|
+
end
|
814
|
+
|
815
|
+
it "should change the permission bits on an existing file" do
|
816
|
+
target_mode = 0755
|
817
|
+
expect(VfsRealFile.stat(@full_path).mode & 0777).to_not eq(target_mode)
|
818
|
+
VirtFS::VFile.lchmod(target_mode, @full_path)
|
819
|
+
expect(VfsRealFile.stat(@full_path).mode & 0777).to eq(target_mode)
|
820
|
+
end
|
821
|
+
end
|
822
|
+
end
|
823
|
+
end
|
824
|
+
|
825
|
+
describe ".lchown" do
|
826
|
+
before(:each) do
|
827
|
+
stat = VfsRealFile.stat(@full_path)
|
828
|
+
@owner = stat.uid
|
829
|
+
@group = stat.gid
|
830
|
+
|
831
|
+
VfsRealFile.symlink(@full_path, @slink_path)
|
832
|
+
end
|
833
|
+
|
834
|
+
after(:each) do
|
835
|
+
VfsRealFile.delete(@slink_path)
|
836
|
+
end
|
837
|
+
|
838
|
+
context "with no filesystems mounted" do
|
839
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
840
|
+
expect do
|
841
|
+
VirtFS::VFile.lchown(@owner, @group, "nonexistent_file")
|
842
|
+
end.to raise_error(
|
843
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
844
|
+
)
|
845
|
+
end
|
846
|
+
|
847
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
848
|
+
expect do
|
849
|
+
VirtFS::VFile.lchown(@owner, @group, @full_path)
|
850
|
+
end.to raise_error(
|
851
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
852
|
+
)
|
853
|
+
end
|
854
|
+
end
|
855
|
+
|
856
|
+
context "with FS mounted on '/'" do
|
857
|
+
before(:each) do
|
858
|
+
@native_fs = nativefs_class.new
|
859
|
+
VirtFS.mount(@native_fs, @root)
|
860
|
+
end
|
861
|
+
|
862
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
863
|
+
expect do
|
864
|
+
VirtFS::VFile.lchown(@owner, @group, "nonexistent_file")
|
865
|
+
end.to raise_error(
|
866
|
+
Errno::ENOENT, /No such file or directory/
|
867
|
+
)
|
868
|
+
end
|
869
|
+
|
870
|
+
it "should return the number of files processed" do
|
871
|
+
expect(VirtFS::VFile.lchown(@owner, @group, @slink_path)).to eq(1)
|
872
|
+
expect(VirtFS::VFile.lchown(@owner, @group, @slink_path, @full_path2)).to eq(2)
|
873
|
+
end
|
874
|
+
end
|
875
|
+
end
|
876
|
+
|
877
|
+
describe ".link" do
|
878
|
+
before(:each) do
|
879
|
+
@link_path = temp_name(@temp_prefix, ".hardlink")
|
880
|
+
end
|
881
|
+
|
882
|
+
after(:each) do
|
883
|
+
VfsRealFile.delete(@link_path) if VfsRealFile.exist?(@link_path)
|
884
|
+
end
|
885
|
+
|
886
|
+
context "with no filesystems mounted" do
|
887
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
888
|
+
expect do
|
889
|
+
VirtFS::VFile.link("nonexistent_file1", "nonexistent_file2")
|
890
|
+
end.to raise_error(
|
891
|
+
Errno::ENOENT, /No such file or directory/
|
892
|
+
)
|
893
|
+
end
|
894
|
+
|
895
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
896
|
+
expect do
|
897
|
+
VirtFS::VFile.link(@full_path, @link_path)
|
898
|
+
end.to raise_error(
|
899
|
+
Errno::ENOENT, /No such file or directory/
|
900
|
+
)
|
901
|
+
end
|
902
|
+
end
|
903
|
+
|
904
|
+
context "with FS mounted on '/'" do
|
905
|
+
before(:each) do
|
906
|
+
@native_fs = nativefs_class.new
|
907
|
+
VirtFS.mount(@native_fs, @root)
|
908
|
+
end
|
909
|
+
|
910
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
911
|
+
expect do
|
912
|
+
VirtFS::VFile.link("nonexistent_file1", @link_path)
|
913
|
+
end.to raise_error(
|
914
|
+
Errno::ENOENT, /No such file or directory/
|
915
|
+
)
|
916
|
+
end
|
917
|
+
|
918
|
+
it "should return 0 on success" do
|
919
|
+
expect(VirtFS::VFile.link(@full_path, @link_path)).to eq(0)
|
920
|
+
end
|
921
|
+
|
922
|
+
it "the link should be identical to the original file" do
|
923
|
+
expect(VirtFS::VFile.link(@full_path, @link_path)).to eq(0)
|
924
|
+
expect(VirtFS::VFile.identical?(@full_path, @link_path)).to be true
|
925
|
+
end
|
926
|
+
end
|
927
|
+
end
|
928
|
+
|
929
|
+
describe ".lstat" do
|
930
|
+
context "with no filesystems mounted" do
|
931
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
932
|
+
expect do
|
933
|
+
VirtFS::VFile.lstat("nonexistent_file1")
|
934
|
+
end.to raise_error(
|
935
|
+
Errno::ENOENT, /No such file or directory/
|
936
|
+
)
|
937
|
+
end
|
938
|
+
|
939
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
940
|
+
expect do
|
941
|
+
VirtFS::VFile.lstat(@full_path)
|
942
|
+
end.to raise_error(
|
943
|
+
Errno::ENOENT, /No such file or directory/
|
944
|
+
)
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
context "with FS mounted on '/'" do
|
949
|
+
before(:each) do
|
950
|
+
@native_fs = nativefs_class.new
|
951
|
+
VirtFS.mount(@native_fs, @root)
|
952
|
+
|
953
|
+
VfsRealFile.symlink(@full_path, @slink_path)
|
954
|
+
end
|
955
|
+
|
956
|
+
after(:each) do
|
957
|
+
VfsRealFile.delete(@slink_path)
|
958
|
+
end
|
959
|
+
|
960
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
961
|
+
expect do
|
962
|
+
VirtFS::VFile.lstat("nonexistent_file1")
|
963
|
+
end.to raise_error(
|
964
|
+
Errno::ENOENT, /No such file or directory/
|
965
|
+
)
|
966
|
+
end
|
967
|
+
|
968
|
+
it "should return the stat information for the symlink" do
|
969
|
+
expect(VirtFS::VFile.lstat(@slink_path).symlink?).to be true
|
970
|
+
end
|
971
|
+
end
|
972
|
+
end
|
973
|
+
|
974
|
+
describe ".mtime" do
|
975
|
+
context "with no filesystems mounted" do
|
976
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
977
|
+
expect do
|
978
|
+
VirtFS::VFile.mtime("nonexistent_file")
|
979
|
+
end.to raise_error(
|
980
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
981
|
+
)
|
982
|
+
end
|
983
|
+
|
984
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
985
|
+
expect do
|
986
|
+
VirtFS::VFile.mtime(@full_path)
|
987
|
+
end.to raise_error(
|
988
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
989
|
+
)
|
990
|
+
end
|
991
|
+
end
|
992
|
+
|
993
|
+
context "with FS mounted on '/'" do
|
994
|
+
before(:each) do
|
995
|
+
@native_fs = nativefs_class.new
|
996
|
+
VirtFS.mount(@native_fs, @root)
|
997
|
+
end
|
998
|
+
|
999
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1000
|
+
expect do
|
1001
|
+
VirtFS::VFile.mtime("nonexistent_file")
|
1002
|
+
end.to raise_error(
|
1003
|
+
Errno::ENOENT, /No such file or directory/
|
1004
|
+
)
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
it "should return the same value as the standard File.mtime, when given a full path" do
|
1008
|
+
expect(VirtFS::VFile.mtime(@full_path)).to eq(VfsRealFile.mtime(@full_path))
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
it "should return the same value as the standard File.mtime, when given relative path" do
|
1012
|
+
VfsRealDir.chdir(@parent_dir) do
|
1013
|
+
VirtFS.dir_chdir(@parent_dir)
|
1014
|
+
expect(VirtFS::VFile.mtime(@rel_path)).to eq(VfsRealFile.mtime(@rel_path))
|
1015
|
+
end
|
1016
|
+
end
|
1017
|
+
end
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
describe ".owned?" do
|
1021
|
+
context "with no filesystems mounted" do
|
1022
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1023
|
+
expect do
|
1024
|
+
VirtFS::VFile.owned?("nonexistent_file")
|
1025
|
+
end.to raise_error(
|
1026
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1027
|
+
)
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1031
|
+
expect do
|
1032
|
+
VirtFS::VFile.owned?(@full_path)
|
1033
|
+
end.to raise_error(
|
1034
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1035
|
+
)
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
context "with FS mounted on '/'" do
|
1040
|
+
before(:each) do
|
1041
|
+
@native_fs = nativefs_class.new
|
1042
|
+
VirtFS.mount(@native_fs, @root)
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
it "should return false when given a nonexistent file" do
|
1046
|
+
expect(VirtFS::VFile.owned?("nonexistent_file")).to be false
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
it "should return true when given a file we created" do
|
1050
|
+
expect(VirtFS::VFile.owned?(@full_path)).to be true
|
1051
|
+
end
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
describe ".path" do
|
1056
|
+
before(:each) do
|
1057
|
+
@native_fs = nativefs_class.new
|
1058
|
+
VirtFS.mount(@native_fs, @root)
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
it "should work with a string" do
|
1062
|
+
expect(VirtFS::VFile.path(@full_path)).to eq(@full_path)
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
it "should work with an IO object" do
|
1066
|
+
VirtFS::VFile.open(@full_path) do |fobj|
|
1067
|
+
expect(VirtFS::VFile.path(fobj)).to eq(@full_path)
|
1068
|
+
end
|
1069
|
+
end
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
describe ".pipe?" do
|
1073
|
+
context "with no filesystems mounted" do
|
1074
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1075
|
+
expect do
|
1076
|
+
VirtFS::VFile.pipe?("nonexistent_file")
|
1077
|
+
end.to raise_error(
|
1078
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1079
|
+
)
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1083
|
+
expect do
|
1084
|
+
VirtFS::VFile.pipe?(@full_path)
|
1085
|
+
end.to raise_error(
|
1086
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1087
|
+
)
|
1088
|
+
end
|
1089
|
+
end
|
1090
|
+
|
1091
|
+
context "with FS mounted on '/'" do
|
1092
|
+
before(:each) do
|
1093
|
+
@native_fs = nativefs_class.new
|
1094
|
+
VirtFS.mount(@native_fs, @root)
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
it "should return false when given a nonexistent file" do
|
1098
|
+
expect(VirtFS::VFile.pipe?("nonexistent_file")).to be false
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
it "should return false when given a regular file" do
|
1102
|
+
expect(VirtFS::VFile.pipe?(@full_path)).to be false
|
1103
|
+
end
|
1104
|
+
end
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
describe ".readable?" do
|
1108
|
+
context "with no filesystems mounted" do
|
1109
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1110
|
+
expect do
|
1111
|
+
VirtFS::VFile.readable?("nonexistent_file")
|
1112
|
+
end.to raise_error(
|
1113
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1114
|
+
)
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1118
|
+
expect do
|
1119
|
+
VirtFS::VFile.readable?(@full_path)
|
1120
|
+
end.to raise_error(
|
1121
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1122
|
+
)
|
1123
|
+
end
|
1124
|
+
end
|
1125
|
+
|
1126
|
+
context "with FS mounted on '/'" do
|
1127
|
+
before(:each) do
|
1128
|
+
@native_fs = nativefs_class.new
|
1129
|
+
VirtFS.mount(@native_fs, @root)
|
1130
|
+
end
|
1131
|
+
|
1132
|
+
it "should return false when given a nonexistent file" do
|
1133
|
+
expect(VirtFS::VFile.readable?("nonexistent_file")).to be false
|
1134
|
+
end
|
1135
|
+
|
1136
|
+
#
|
1137
|
+
# NOTE: This test fails when run under Fusion shared folders.
|
1138
|
+
# Could be due to silent failure of chmod.
|
1139
|
+
#
|
1140
|
+
it "should return false when given a non-readable file" do
|
1141
|
+
VfsRealFile.chmod(0300, @full_path)
|
1142
|
+
expect(VirtFS::VFile.readable?(@full_path)).to be false
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
it "should return true when given a readable file" do
|
1146
|
+
VfsRealFile.chmod(0400, @full_path)
|
1147
|
+
expect(VirtFS::VFile.readable?(@full_path)).to be true
|
1148
|
+
end
|
1149
|
+
end
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
describe ".readable_real?" do
|
1153
|
+
context "with no filesystems mounted" do
|
1154
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1155
|
+
expect do
|
1156
|
+
VirtFS::VFile.readable_real?("nonexistent_file")
|
1157
|
+
end.to raise_error(
|
1158
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1159
|
+
)
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1163
|
+
expect do
|
1164
|
+
VirtFS::VFile.readable_real?(@full_path)
|
1165
|
+
end.to raise_error(
|
1166
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1167
|
+
)
|
1168
|
+
end
|
1169
|
+
end
|
1170
|
+
|
1171
|
+
context "with FS mounted on '/'" do
|
1172
|
+
before(:each) do
|
1173
|
+
@native_fs = nativefs_class.new
|
1174
|
+
VirtFS.mount(@native_fs, @root)
|
1175
|
+
end
|
1176
|
+
|
1177
|
+
it "should return false when given a nonexistent file" do
|
1178
|
+
expect(VirtFS::VFile.readable_real?("nonexistent_file")).to be false
|
1179
|
+
end
|
1180
|
+
|
1181
|
+
#
|
1182
|
+
# NOTE: This test fails when run under Fusion shared folders.
|
1183
|
+
# Could be due to silent failure of chmod.
|
1184
|
+
#
|
1185
|
+
it "should return false when given a non-readable file" do
|
1186
|
+
VfsRealFile.chmod(0300, @full_path)
|
1187
|
+
expect(VirtFS::VFile.readable_real?(@full_path)).to be false
|
1188
|
+
end
|
1189
|
+
|
1190
|
+
it "should return true when given a readable file" do
|
1191
|
+
VfsRealFile.chmod(0400, @full_path)
|
1192
|
+
expect(VirtFS::VFile.readable_real?(@full_path)).to be true
|
1193
|
+
end
|
1194
|
+
end
|
1195
|
+
end
|
1196
|
+
|
1197
|
+
describe ".readlink" do
|
1198
|
+
context "with no filesystems mounted" do
|
1199
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1200
|
+
expect do
|
1201
|
+
VirtFS::VFile.readlink("nonexistent_file1")
|
1202
|
+
end.to raise_error(
|
1203
|
+
Errno::ENOENT, /No such file or directory/
|
1204
|
+
)
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1208
|
+
expect do
|
1209
|
+
VirtFS::VFile.readlink(@full_path)
|
1210
|
+
end.to raise_error(
|
1211
|
+
Errno::ENOENT, /No such file or directory/
|
1212
|
+
)
|
1213
|
+
end
|
1214
|
+
end
|
1215
|
+
|
1216
|
+
context "with FS mounted on '/'" do
|
1217
|
+
before(:each) do
|
1218
|
+
@native_fs = nativefs_class.new
|
1219
|
+
VirtFS.mount(@native_fs, @root)
|
1220
|
+
|
1221
|
+
VfsRealFile.symlink(@full_path, @slink_path)
|
1222
|
+
end
|
1223
|
+
|
1224
|
+
after(:each) do
|
1225
|
+
VfsRealFile.delete(@slink_path)
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1229
|
+
expect do
|
1230
|
+
VirtFS::VFile.readlink("nonexistent_file1")
|
1231
|
+
end.to raise_error(
|
1232
|
+
Errno::ENOENT, /No such file or directory/
|
1233
|
+
)
|
1234
|
+
end
|
1235
|
+
|
1236
|
+
it "should return the stat information for the symlink" do
|
1237
|
+
expect(VirtFS::VFile.readlink(@slink_path)).to eq(@full_path)
|
1238
|
+
end
|
1239
|
+
end
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
describe ".realdirpath" do
|
1243
|
+
before(:each) do
|
1244
|
+
@native_fs = nativefs_class.new
|
1245
|
+
VirtFS.mount(@native_fs, @root)
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
it "should return the same path as the standard realdirpath" do
|
1249
|
+
expect(VirtFS::VFile.realdirpath(@full_path)).to eq(VfsRealFile.realdirpath(@full_path))
|
1250
|
+
end
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
describe ".realpath" do
|
1254
|
+
before(:each) do
|
1255
|
+
@native_fs = nativefs_class.new
|
1256
|
+
VirtFS.mount(@native_fs, @root)
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it "should return the same path as the standard realdirpath" do
|
1260
|
+
expect(VirtFS::VFile.realpath(@full_path)).to eq(VfsRealFile.realpath(@full_path))
|
1261
|
+
end
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
describe ".rename" do
|
1265
|
+
before(:each) do
|
1266
|
+
@to_path = temp_name(@temp_prefix, ".renamed")
|
1267
|
+
end
|
1268
|
+
|
1269
|
+
after(:each) do
|
1270
|
+
VfsRealFile.delete(@to_path) if VfsRealFile.exist?(@to_path)
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
context "with no filesystems mounted" do
|
1274
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1275
|
+
expect do
|
1276
|
+
VirtFS::VFile.rename("nonexistent_file1", "nonexistent_file2")
|
1277
|
+
end.to raise_error(
|
1278
|
+
Errno::ENOENT, /No such file or directory/
|
1279
|
+
)
|
1280
|
+
end
|
1281
|
+
|
1282
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1283
|
+
expect do
|
1284
|
+
VirtFS::VFile.rename(@full_path, @to_path)
|
1285
|
+
end.to raise_error(
|
1286
|
+
Errno::ENOENT, /No such file or directory/
|
1287
|
+
)
|
1288
|
+
end
|
1289
|
+
end
|
1290
|
+
|
1291
|
+
context "with FS mounted on '/'" do
|
1292
|
+
before(:each) do
|
1293
|
+
@native_fs = nativefs_class.new
|
1294
|
+
VirtFS.mount(@native_fs, @root)
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1298
|
+
expect do
|
1299
|
+
VirtFS::VFile.rename("nonexistent_file1", @to_path)
|
1300
|
+
end.to raise_error(
|
1301
|
+
Errno::ENOENT, /No such file or directory/
|
1302
|
+
)
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
it "should return 0 on success" do
|
1306
|
+
expect(VirtFS::VFile.rename(@full_path, @to_path)).to eq(0)
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
it "the link should rename the file" do
|
1310
|
+
expect(VirtFS::VFile.rename(@full_path, @to_path)).to eq(0)
|
1311
|
+
expect(VirtFS::VFile.exist?(@to_path)).to be true
|
1312
|
+
expect(VirtFS::VFile.exist?(@full_path)).to be false
|
1313
|
+
end
|
1314
|
+
end
|
1315
|
+
end
|
1316
|
+
|
1317
|
+
describe ".setgid?" do
|
1318
|
+
context "with no filesystems mounted" do
|
1319
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1320
|
+
expect do
|
1321
|
+
VirtFS::VFile.setgid?("nonexistent_file")
|
1322
|
+
end.to raise_error(
|
1323
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1324
|
+
)
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1328
|
+
expect do
|
1329
|
+
VirtFS::VFile.setgid?(@full_path)
|
1330
|
+
end.to raise_error(
|
1331
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1332
|
+
)
|
1333
|
+
end
|
1334
|
+
end
|
1335
|
+
|
1336
|
+
context "with FS mounted on '/'" do
|
1337
|
+
before(:each) do
|
1338
|
+
@native_fs = nativefs_class.new
|
1339
|
+
VirtFS.mount(@native_fs, @root)
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
it "should return false when given a nonexistent file" do
|
1343
|
+
expect(VirtFS::VFile.setgid?("nonexistent_file")).to be false
|
1344
|
+
end
|
1345
|
+
|
1346
|
+
it "should return false when given a non-setgid file" do
|
1347
|
+
VfsRealFile.chmod(0644, @full_path)
|
1348
|
+
expect(VirtFS::VFile.setgid?(@full_path)).to be false
|
1349
|
+
end
|
1350
|
+
|
1351
|
+
it "should return true when given a setgid file" do
|
1352
|
+
VfsRealFile.chmod(02644, @full_path)
|
1353
|
+
expect(VirtFS::VFile.setgid?(@full_path)).to be true
|
1354
|
+
end
|
1355
|
+
end
|
1356
|
+
end
|
1357
|
+
|
1358
|
+
describe ".setuid?" do
|
1359
|
+
context "with no filesystems mounted" do
|
1360
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1361
|
+
expect do
|
1362
|
+
VirtFS::VFile.setuid?("nonexistent_file")
|
1363
|
+
end.to raise_error(
|
1364
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1365
|
+
)
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1369
|
+
expect do
|
1370
|
+
VirtFS::VFile.setuid?(@full_path)
|
1371
|
+
end.to raise_error(
|
1372
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1373
|
+
)
|
1374
|
+
end
|
1375
|
+
end
|
1376
|
+
|
1377
|
+
context "with FS mounted on '/'" do
|
1378
|
+
before(:each) do
|
1379
|
+
@native_fs = nativefs_class.new
|
1380
|
+
VirtFS.mount(@native_fs, @root)
|
1381
|
+
end
|
1382
|
+
|
1383
|
+
it "should return false when given a nonexistent file" do
|
1384
|
+
expect(VirtFS::VFile.setuid?("nonexistent_file")).to be false
|
1385
|
+
end
|
1386
|
+
|
1387
|
+
it "should return false when given a non-setuid file" do
|
1388
|
+
VfsRealFile.chmod(0644, @full_path)
|
1389
|
+
expect(VirtFS::VFile.setuid?(@full_path)).to be false
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
it "should return true when given a setuid file" do
|
1393
|
+
VfsRealFile.chmod(04644, @full_path)
|
1394
|
+
expect(VirtFS::VFile.setuid?(@full_path)).to be true
|
1395
|
+
end
|
1396
|
+
end
|
1397
|
+
end
|
1398
|
+
|
1399
|
+
describe ".size" do
|
1400
|
+
context "with no filesystems mounted" do
|
1401
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1402
|
+
expect do
|
1403
|
+
VirtFS::VFile.size("nonexistent_file")
|
1404
|
+
end.to raise_error(
|
1405
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1406
|
+
)
|
1407
|
+
end
|
1408
|
+
|
1409
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1410
|
+
expect do
|
1411
|
+
VirtFS::VFile.size(@full_path)
|
1412
|
+
end.to raise_error(
|
1413
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1414
|
+
)
|
1415
|
+
end
|
1416
|
+
end
|
1417
|
+
|
1418
|
+
context "with FS mounted on '/'" do
|
1419
|
+
before(:each) do
|
1420
|
+
@native_fs = nativefs_class.new
|
1421
|
+
VirtFS.mount(@native_fs, @root)
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1425
|
+
expect do
|
1426
|
+
VirtFS::VFile.size("nonexistent_file")
|
1427
|
+
end.to raise_error(
|
1428
|
+
Errno::ENOENT, /No such file or directory/
|
1429
|
+
)
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
it "should return the known size of the file" do
|
1433
|
+
expect(VirtFS::VFile.size(@full_path)).to eq(@data1.bytesize)
|
1434
|
+
end
|
1435
|
+
|
1436
|
+
it "should return the same value as the standard File#size" do
|
1437
|
+
expect(VirtFS::VFile.size(@full_path)).to eq(VfsRealFile.size(@full_path))
|
1438
|
+
end
|
1439
|
+
|
1440
|
+
it "should return 0 for empty file" do
|
1441
|
+
expect(VirtFS::VFile.size(@full_path2)).to eq(0)
|
1442
|
+
end
|
1443
|
+
end
|
1444
|
+
end
|
1445
|
+
|
1446
|
+
describe ".size?" do
|
1447
|
+
context "with no filesystems mounted" do
|
1448
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1449
|
+
expect do
|
1450
|
+
VirtFS::VFile.size?("nonexistent_file")
|
1451
|
+
end.to raise_error(
|
1452
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1453
|
+
)
|
1454
|
+
end
|
1455
|
+
|
1456
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1457
|
+
expect do
|
1458
|
+
VirtFS::VFile.size?(@full_path)
|
1459
|
+
end.to raise_error(
|
1460
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1461
|
+
)
|
1462
|
+
end
|
1463
|
+
end
|
1464
|
+
|
1465
|
+
context "with FS mounted on '/'" do
|
1466
|
+
before(:each) do
|
1467
|
+
@native_fs = nativefs_class.new
|
1468
|
+
VirtFS.mount(@native_fs, @root)
|
1469
|
+
end
|
1470
|
+
|
1471
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1472
|
+
expect do
|
1473
|
+
VirtFS::VFile.size?("nonexistent_file")
|
1474
|
+
end.to raise_error(
|
1475
|
+
Errno::ENOENT, /No such file or directory/
|
1476
|
+
)
|
1477
|
+
end
|
1478
|
+
|
1479
|
+
it "should return the known size of the file" do
|
1480
|
+
expect(VirtFS::VFile.size?(@full_path)).to eq(@data1.bytesize)
|
1481
|
+
end
|
1482
|
+
|
1483
|
+
it "should return the same value as the standard File#size" do
|
1484
|
+
expect(VirtFS::VFile.size?(@full_path)).to eq(VfsRealFile.size?(@full_path))
|
1485
|
+
end
|
1486
|
+
|
1487
|
+
it "should return nil for empty file" do
|
1488
|
+
expect(VirtFS::VFile.size?(@full_path2)).to eq(nil)
|
1489
|
+
end
|
1490
|
+
end
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
describe ".socket?" do
|
1494
|
+
context "with no filesystems mounted" do
|
1495
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1496
|
+
expect do
|
1497
|
+
VirtFS::VFile.socket?("nonexistent_file")
|
1498
|
+
end.to raise_error(
|
1499
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1500
|
+
)
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1504
|
+
expect do
|
1505
|
+
VirtFS::VFile.socket?(@full_path)
|
1506
|
+
end.to raise_error(
|
1507
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1508
|
+
)
|
1509
|
+
end
|
1510
|
+
end
|
1511
|
+
|
1512
|
+
context "with FS mounted on '/'" do
|
1513
|
+
before(:each) do
|
1514
|
+
@native_fs = nativefs_class.new
|
1515
|
+
VirtFS.mount(@native_fs, @root)
|
1516
|
+
end
|
1517
|
+
|
1518
|
+
it "should return false when given a nonexistent file" do
|
1519
|
+
expect(VirtFS::VFile.socket?("nonexistent_file")).to be false
|
1520
|
+
end
|
1521
|
+
|
1522
|
+
it "should return false when given a regular file" do
|
1523
|
+
expect(VirtFS::VFile.socket?(@full_path)).to be false
|
1524
|
+
end
|
1525
|
+
end
|
1526
|
+
end
|
1527
|
+
|
1528
|
+
describe ".split" do
|
1529
|
+
it "should return the same values as the standard File.split" do
|
1530
|
+
expect(VirtFS::VFile.split(@full_path)).to match_array(VfsRealFile.split(@full_path))
|
1531
|
+
end
|
1532
|
+
end
|
1533
|
+
|
1534
|
+
describe ".stat" do
|
1535
|
+
context "with no filesystems mounted" do
|
1536
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1537
|
+
expect do
|
1538
|
+
VirtFS::VFile.stat("nonexistent_file1")
|
1539
|
+
end.to raise_error(
|
1540
|
+
Errno::ENOENT, /No such file or directory/
|
1541
|
+
)
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1545
|
+
expect do
|
1546
|
+
VirtFS::VFile.stat(@full_path)
|
1547
|
+
end.to raise_error(
|
1548
|
+
Errno::ENOENT, /No such file or directory/
|
1549
|
+
)
|
1550
|
+
end
|
1551
|
+
end
|
1552
|
+
|
1553
|
+
context "with FS mounted on '/'" do
|
1554
|
+
before(:each) do
|
1555
|
+
@native_fs = nativefs_class.new
|
1556
|
+
VirtFS.mount(@native_fs, @root)
|
1557
|
+
|
1558
|
+
VfsRealFile.symlink(@full_path, @slink_path)
|
1559
|
+
end
|
1560
|
+
|
1561
|
+
after(:each) do
|
1562
|
+
VfsRealFile.delete(@slink_path)
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1566
|
+
expect do
|
1567
|
+
VirtFS::VFile.stat("nonexistent_file1")
|
1568
|
+
end.to raise_error(
|
1569
|
+
Errno::ENOENT, /No such file or directory/
|
1570
|
+
)
|
1571
|
+
end
|
1572
|
+
|
1573
|
+
it "should return the stat information for the file" do
|
1574
|
+
expect(VirtFS::VFile.stat(@full_path).symlink?).to be false
|
1575
|
+
end
|
1576
|
+
|
1577
|
+
it "given a symlink, should return the stat information for the regular file" do
|
1578
|
+
expect(VirtFS::VFile.stat(@slink_path).symlink?).to be false
|
1579
|
+
end
|
1580
|
+
end
|
1581
|
+
end
|
1582
|
+
|
1583
|
+
describe ".sticky?" do
|
1584
|
+
context "with no filesystems mounted" do
|
1585
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1586
|
+
expect do
|
1587
|
+
VirtFS::VFile.sticky?("nonexistent_file")
|
1588
|
+
end.to raise_error(
|
1589
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1590
|
+
)
|
1591
|
+
end
|
1592
|
+
|
1593
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1594
|
+
expect do
|
1595
|
+
VirtFS::VFile.sticky?(@full_path)
|
1596
|
+
end.to raise_error(
|
1597
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1598
|
+
)
|
1599
|
+
end
|
1600
|
+
end
|
1601
|
+
|
1602
|
+
context "with FS mounted on '/'" do
|
1603
|
+
before(:each) do
|
1604
|
+
@native_fs = nativefs_class.new
|
1605
|
+
VirtFS.mount(@native_fs, @root)
|
1606
|
+
end
|
1607
|
+
|
1608
|
+
it "should return false when given a nonexistent file" do
|
1609
|
+
expect(VirtFS::VFile.sticky?("nonexistent_file")).to be false
|
1610
|
+
end
|
1611
|
+
|
1612
|
+
it "should return false when given a non-sticky file" do
|
1613
|
+
VfsRealFile.chmod(0644, @full_path)
|
1614
|
+
expect(VirtFS::VFile.sticky?(@full_path)).to be false
|
1615
|
+
end
|
1616
|
+
|
1617
|
+
it "should return true when given a sticky file" do
|
1618
|
+
VfsRealFile.chmod(01644, @full_path)
|
1619
|
+
expect(VirtFS::VFile.sticky?(@full_path)).to be true
|
1620
|
+
end
|
1621
|
+
end
|
1622
|
+
end
|
1623
|
+
|
1624
|
+
describe ".symlink" do
|
1625
|
+
after(:each) do
|
1626
|
+
VfsRealFile.delete(@slink_path) if VfsRealFile.exist?(@slink_path)
|
1627
|
+
end
|
1628
|
+
|
1629
|
+
context "with no filesystems mounted" do
|
1630
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1631
|
+
expect do
|
1632
|
+
VirtFS::VFile.symlink("nonexistent_file1", "nonexistent_file2")
|
1633
|
+
end.to raise_error(
|
1634
|
+
Errno::ENOENT, /No such file or directory/
|
1635
|
+
)
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1639
|
+
expect do
|
1640
|
+
VirtFS::VFile.symlink(@full_path, @slink_path)
|
1641
|
+
end.to raise_error(
|
1642
|
+
Errno::ENOENT, /No such file or directory/
|
1643
|
+
)
|
1644
|
+
end
|
1645
|
+
end
|
1646
|
+
|
1647
|
+
context "with FS mounted on '/'" do
|
1648
|
+
before(:each) do
|
1649
|
+
@native_fs = nativefs_class.new
|
1650
|
+
VirtFS.mount(@native_fs, @root)
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
it "should return 0 on success" do
|
1654
|
+
expect(VirtFS::VFile.symlink(@full_path, @slink_path)).to eq(0)
|
1655
|
+
end
|
1656
|
+
|
1657
|
+
it "the symlink should be identical to the original file" do
|
1658
|
+
expect(VirtFS::VFile.symlink(@full_path, @slink_path)).to eq(0)
|
1659
|
+
expect(VirtFS::VFile.identical?(@full_path, @slink_path)).to be true
|
1660
|
+
end
|
1661
|
+
end
|
1662
|
+
end
|
1663
|
+
|
1664
|
+
describe ".symlink?" do
|
1665
|
+
context "with no filesystems mounted" do
|
1666
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1667
|
+
expect do
|
1668
|
+
VirtFS::VFile.symlink?("nonexistent_file1")
|
1669
|
+
end.to raise_error(
|
1670
|
+
Errno::ENOENT, /No such file or directory/
|
1671
|
+
)
|
1672
|
+
end
|
1673
|
+
|
1674
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1675
|
+
expect do
|
1676
|
+
VirtFS::VFile.symlink?(@full_path)
|
1677
|
+
end.to raise_error(
|
1678
|
+
Errno::ENOENT, /No such file or directory/
|
1679
|
+
)
|
1680
|
+
end
|
1681
|
+
end
|
1682
|
+
|
1683
|
+
context "with FS mounted on '/'" do
|
1684
|
+
before(:each) do
|
1685
|
+
@native_fs = nativefs_class.new
|
1686
|
+
VirtFS.mount(@native_fs, @root)
|
1687
|
+
|
1688
|
+
VfsRealFile.symlink(@full_path, @slink_path)
|
1689
|
+
end
|
1690
|
+
|
1691
|
+
after(:each) do
|
1692
|
+
VfsRealFile.delete(@slink_path)
|
1693
|
+
end
|
1694
|
+
|
1695
|
+
it "should return false when given a nonexistent file" do
|
1696
|
+
expect(VirtFS::VFile.symlink?("nonexistent_file")).to be false
|
1697
|
+
end
|
1698
|
+
|
1699
|
+
it "should return true given a symlink" do
|
1700
|
+
expect(VirtFS::VFile.symlink?(@slink_path)).to be true
|
1701
|
+
end
|
1702
|
+
end
|
1703
|
+
end
|
1704
|
+
|
1705
|
+
describe ".truncate" do
|
1706
|
+
context "with no filesystems mounted" do
|
1707
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1708
|
+
expect do
|
1709
|
+
VirtFS::VFile.truncate("nonexistent_file", 0)
|
1710
|
+
end.to raise_error(
|
1711
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1712
|
+
)
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1716
|
+
expect do
|
1717
|
+
VirtFS::VFile.truncate(@full_path, 0)
|
1718
|
+
end.to raise_error(
|
1719
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1720
|
+
)
|
1721
|
+
end
|
1722
|
+
end
|
1723
|
+
|
1724
|
+
context "with FS mounted on '/'" do
|
1725
|
+
before(:each) do
|
1726
|
+
@native_fs = nativefs_class.new
|
1727
|
+
VirtFS.mount(@native_fs, @root)
|
1728
|
+
end
|
1729
|
+
|
1730
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1731
|
+
expect do
|
1732
|
+
VirtFS::VFile.truncate("nonexistent_file", 0)
|
1733
|
+
end.to raise_error(
|
1734
|
+
Errno::ENOENT, /No such file or directory/
|
1735
|
+
)
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
it "should return 0" do
|
1739
|
+
expect(VirtFS::VFile.truncate(@full_path, 5)).to eq(0)
|
1740
|
+
end
|
1741
|
+
|
1742
|
+
it "should raise truncate the file to the specified size" do
|
1743
|
+
tsize = @data1.bytesize/2
|
1744
|
+
expect(VfsRealFile.size(@full_path)).to_not eq(tsize)
|
1745
|
+
VirtFS::VFile.truncate(@full_path, tsize)
|
1746
|
+
expect(VfsRealFile.size(@full_path)).to eq(tsize)
|
1747
|
+
end
|
1748
|
+
end
|
1749
|
+
end
|
1750
|
+
|
1751
|
+
describe ".utime" do
|
1752
|
+
before(:each) do
|
1753
|
+
@time = Time.new(2015, 9, 12, 9, 50)
|
1754
|
+
end
|
1755
|
+
|
1756
|
+
context "with no filesystems mounted" do
|
1757
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1758
|
+
expect do
|
1759
|
+
VirtFS::VFile.utime(@time, @time, "nonexistent_file")
|
1760
|
+
end.to raise_error(
|
1761
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1762
|
+
)
|
1763
|
+
end
|
1764
|
+
|
1765
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1766
|
+
expect do
|
1767
|
+
VirtFS::VFile.utime(@time, @time, @full_path)
|
1768
|
+
end.to raise_error(
|
1769
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1770
|
+
)
|
1771
|
+
end
|
1772
|
+
end
|
1773
|
+
|
1774
|
+
context "with FS mounted on '/'" do
|
1775
|
+
before(:each) do
|
1776
|
+
@native_fs = nativefs_class.new
|
1777
|
+
VirtFS.mount(@native_fs, @root)
|
1778
|
+
end
|
1779
|
+
|
1780
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1781
|
+
expect do
|
1782
|
+
VirtFS::VFile.utime(@time, @time, "nonexistent_file")
|
1783
|
+
end.to raise_error(
|
1784
|
+
Errno::ENOENT, /No such file or directory/
|
1785
|
+
)
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
it "should set the atime and mtime of the file, given a full path" do
|
1789
|
+
expect(VirtFS::VFile.utime(@time, @time, @full_path)).to eq(1)
|
1790
|
+
expect(VirtFS::VFile.atime(@full_path)).to eq(@time)
|
1791
|
+
expect(VirtFS::VFile.mtime(@full_path)).to eq(@time)
|
1792
|
+
end
|
1793
|
+
|
1794
|
+
it "should set the atime and mtime of the file, given relative path" do
|
1795
|
+
VfsRealDir.chdir(@parent_dir) do
|
1796
|
+
VirtFS.dir_chdir(@parent_dir)
|
1797
|
+
expect(VirtFS::VFile.utime(@time, @time, @rel_path)).to eq(1)
|
1798
|
+
expect(VirtFS::VFile.atime(@full_path)).to eq(@time)
|
1799
|
+
expect(VirtFS::VFile.mtime(@full_path)).to eq(@time)
|
1800
|
+
end
|
1801
|
+
end
|
1802
|
+
end
|
1803
|
+
end
|
1804
|
+
|
1805
|
+
describe ".world_readable?" do
|
1806
|
+
context "with no filesystems mounted" do
|
1807
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1808
|
+
expect do
|
1809
|
+
VirtFS::VFile.world_readable?("nonexistent_file")
|
1810
|
+
end.to raise_error(
|
1811
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1812
|
+
)
|
1813
|
+
end
|
1814
|
+
|
1815
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1816
|
+
expect do
|
1817
|
+
VirtFS::VFile.world_readable?(@full_path)
|
1818
|
+
end.to raise_error(
|
1819
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1820
|
+
)
|
1821
|
+
end
|
1822
|
+
end
|
1823
|
+
|
1824
|
+
context "with FS mounted on '/'" do
|
1825
|
+
before(:each) do
|
1826
|
+
@native_fs = nativefs_class.new
|
1827
|
+
VirtFS.mount(@native_fs, @root)
|
1828
|
+
end
|
1829
|
+
|
1830
|
+
it "should return nil when given a nonexistent file" do
|
1831
|
+
expect(VirtFS::VFile.world_readable?("nonexistent_file")).to eq(nil)
|
1832
|
+
end
|
1833
|
+
|
1834
|
+
it "should return nil when given a non-world-readable file" do
|
1835
|
+
VfsRealFile.chmod(0773, @full_path)
|
1836
|
+
expect(VirtFS::VFile.world_readable?(@full_path)).to eq(nil)
|
1837
|
+
end
|
1838
|
+
|
1839
|
+
it "should return permission bits when given a world-readable file" do
|
1840
|
+
VfsRealFile.chmod(0004, @full_path)
|
1841
|
+
expect(VirtFS::VFile.world_readable?(@full_path)).to eq(0004)
|
1842
|
+
end
|
1843
|
+
end
|
1844
|
+
end
|
1845
|
+
|
1846
|
+
describe ".world_writable?" do
|
1847
|
+
context "with no filesystems mounted" do
|
1848
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1849
|
+
expect do
|
1850
|
+
VirtFS::VFile.world_writable?("nonexistent_file")
|
1851
|
+
end.to raise_error(
|
1852
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1853
|
+
)
|
1854
|
+
end
|
1855
|
+
|
1856
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1857
|
+
expect do
|
1858
|
+
VirtFS::VFile.world_writable?(@full_path)
|
1859
|
+
end.to raise_error(
|
1860
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1861
|
+
)
|
1862
|
+
end
|
1863
|
+
end
|
1864
|
+
|
1865
|
+
context "with FS mounted on '/'" do
|
1866
|
+
before(:each) do
|
1867
|
+
@native_fs = nativefs_class.new
|
1868
|
+
VirtFS.mount(@native_fs, @root)
|
1869
|
+
end
|
1870
|
+
|
1871
|
+
it "should return nil when given a nonexistent file" do
|
1872
|
+
expect(VirtFS::VFile.world_writable?("nonexistent_file")).to eq(nil)
|
1873
|
+
end
|
1874
|
+
|
1875
|
+
it "should return nil when given a non-world_writable file" do
|
1876
|
+
VfsRealFile.chmod(0775, @full_path)
|
1877
|
+
expect(VirtFS::VFile.world_writable?(@full_path)).to eq(nil)
|
1878
|
+
end
|
1879
|
+
|
1880
|
+
it "should return permission bits when given a world_writable file" do
|
1881
|
+
VfsRealFile.chmod(0002, @full_path)
|
1882
|
+
expect(VirtFS::VFile.world_writable?(@full_path)).to eq(0002)
|
1883
|
+
end
|
1884
|
+
end
|
1885
|
+
end
|
1886
|
+
|
1887
|
+
describe ".writable?" do
|
1888
|
+
context "with no filesystems mounted" do
|
1889
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1890
|
+
expect do
|
1891
|
+
VirtFS::VFile.writable?("nonexistent_file")
|
1892
|
+
end.to raise_error(
|
1893
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1894
|
+
)
|
1895
|
+
end
|
1896
|
+
|
1897
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1898
|
+
expect do
|
1899
|
+
VirtFS::VFile.writable?(@full_path)
|
1900
|
+
end.to raise_error(
|
1901
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1902
|
+
)
|
1903
|
+
end
|
1904
|
+
end
|
1905
|
+
|
1906
|
+
context "with FS mounted on '/'" do
|
1907
|
+
before(:each) do
|
1908
|
+
@native_fs = nativefs_class.new
|
1909
|
+
VirtFS.mount(@native_fs, @root)
|
1910
|
+
end
|
1911
|
+
|
1912
|
+
it "should return false when given a nonexistent file" do
|
1913
|
+
expect(VirtFS::VFile.writable?("nonexistent_file")).to be false
|
1914
|
+
end
|
1915
|
+
|
1916
|
+
#
|
1917
|
+
# NOTE: This test fails when run under Fusion shared folders.
|
1918
|
+
# Could be due to silent failure of chmod.
|
1919
|
+
#
|
1920
|
+
it "should return false when given a non-writable file" do
|
1921
|
+
VfsRealFile.chmod(0500, @full_path)
|
1922
|
+
expect(VirtFS::VFile.writable?(@full_path)).to be false
|
1923
|
+
end
|
1924
|
+
|
1925
|
+
it "should return true when given a writable file" do
|
1926
|
+
VfsRealFile.chmod(0200, @full_path)
|
1927
|
+
expect(VirtFS::VFile.writable?(@full_path)).to be true
|
1928
|
+
end
|
1929
|
+
end
|
1930
|
+
end
|
1931
|
+
|
1932
|
+
describe ".writable_real?" do
|
1933
|
+
context "with no filesystems mounted" do
|
1934
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1935
|
+
expect do
|
1936
|
+
VirtFS::VFile.writable_real?("nonexistent_file")
|
1937
|
+
end.to raise_error(
|
1938
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1939
|
+
)
|
1940
|
+
end
|
1941
|
+
|
1942
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1943
|
+
expect do
|
1944
|
+
VirtFS::VFile.writable_real?(@full_path)
|
1945
|
+
end.to raise_error(
|
1946
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1947
|
+
)
|
1948
|
+
end
|
1949
|
+
end
|
1950
|
+
|
1951
|
+
context "with FS mounted on '/'" do
|
1952
|
+
before(:each) do
|
1953
|
+
@native_fs = nativefs_class.new
|
1954
|
+
VirtFS.mount(@native_fs, @root)
|
1955
|
+
end
|
1956
|
+
|
1957
|
+
it "should return false when given a nonexistent file" do
|
1958
|
+
expect(VirtFS::VFile.writable_real?("nonexistent_file")).to be false
|
1959
|
+
end
|
1960
|
+
|
1961
|
+
#
|
1962
|
+
# NOTE: This test fails when run under Fusion shared folders.
|
1963
|
+
# Could be due to silent failure of chmod.
|
1964
|
+
#
|
1965
|
+
it "should return false when given a non-writable file" do
|
1966
|
+
VfsRealFile.chmod(0500, @full_path)
|
1967
|
+
expect(VirtFS::VFile.writable_real?(@full_path)).to be false
|
1968
|
+
end
|
1969
|
+
|
1970
|
+
it "should return true when given a writable file" do
|
1971
|
+
VfsRealFile.chmod(0200, @full_path)
|
1972
|
+
expect(VirtFS::VFile.writable_real?(@full_path)).to be true
|
1973
|
+
end
|
1974
|
+
end
|
1975
|
+
end
|
1976
|
+
|
1977
|
+
describe ".zero?" do
|
1978
|
+
context "with no filesystems mounted" do
|
1979
|
+
it "should raise Errno::ENOENT when given a nonexistent file" do
|
1980
|
+
expect do
|
1981
|
+
VirtFS::VFile.zero?("nonexistent_file")
|
1982
|
+
end.to raise_error(
|
1983
|
+
Errno::ENOENT, "No such file or directory - nonexistent_file"
|
1984
|
+
)
|
1985
|
+
end
|
1986
|
+
|
1987
|
+
it "should raise Errno::ENOENT when given a file that exists in the native FS" do
|
1988
|
+
expect do
|
1989
|
+
VirtFS::VFile.zero?(@full_path)
|
1990
|
+
end.to raise_error(
|
1991
|
+
Errno::ENOENT, "No such file or directory - #{@full_path}"
|
1992
|
+
)
|
1993
|
+
end
|
1994
|
+
end
|
1995
|
+
|
1996
|
+
context "with FS mounted on '/'" do
|
1997
|
+
before(:each) do
|
1998
|
+
@native_fs = nativefs_class.new
|
1999
|
+
VirtFS.mount(@native_fs, @root)
|
2000
|
+
end
|
2001
|
+
|
2002
|
+
it "should return false when given a nonexistent file" do
|
2003
|
+
expect(VirtFS::VFile.zero?("nonexistent_file")).to be false
|
2004
|
+
end
|
2005
|
+
|
2006
|
+
it "should return false when given a non-zero length file" do
|
2007
|
+
expect(VirtFS::VFile.zero?(@full_path)).to be false
|
2008
|
+
end
|
2009
|
+
|
2010
|
+
it "should return true when given a zero length file" do
|
2011
|
+
expect(VirtFS::VFile.zero?(@full_path2)).to be true
|
2012
|
+
end
|
2013
|
+
end
|
2014
|
+
end
|
2015
|
+
|
2016
|
+
describe ".new" do
|
2017
|
+
context "with no filesystems mounted" do
|
2018
|
+
it "should raise Errno::ENOENT when the file doesn't exist" do
|
2019
|
+
expect do
|
2020
|
+
VirtFS::VFile.new("not_a_file")
|
2021
|
+
end.to raise_error(
|
2022
|
+
Errno::ENOENT, "No such file or directory - not_a_file"
|
2023
|
+
)
|
2024
|
+
end
|
2025
|
+
|
2026
|
+
it "should raise Errno::ENOENT the file does exist in the native FS" do
|
2027
|
+
expect do
|
2028
|
+
VirtFS::VFile.new(@full_path)
|
2029
|
+
end.to raise_error(
|
2030
|
+
Errno::ENOENT, /No such file or directory -/
|
2031
|
+
)
|
2032
|
+
end
|
2033
|
+
end
|
2034
|
+
|
2035
|
+
context "with FS mounted on '/'" do
|
2036
|
+
before(:each) do
|
2037
|
+
@native_fs = nativefs_class.new
|
2038
|
+
VirtFS.mount(@native_fs, @root)
|
2039
|
+
end
|
2040
|
+
|
2041
|
+
it "should raise Errno::ENOENT when the file doesn't exist" do
|
2042
|
+
expect do
|
2043
|
+
VirtFS::VFile.new("not_a_file")
|
2044
|
+
end.to raise_error(
|
2045
|
+
Errno::ENOENT, /No such file or directory/
|
2046
|
+
)
|
2047
|
+
end
|
2048
|
+
|
2049
|
+
it "should return a File object - given full path" do
|
2050
|
+
expect(VirtFS::VFile.new(@full_path)).to be_kind_of(VirtFS::VFile)
|
2051
|
+
end
|
2052
|
+
|
2053
|
+
it "should return a directory object - given relative path" do
|
2054
|
+
VirtFS::VDir.chdir(@parent_dir)
|
2055
|
+
expect(VirtFS::VFile.new(@rel_path)).to be_kind_of(VirtFS::VFile)
|
2056
|
+
end
|
2057
|
+
end
|
2058
|
+
end
|
2059
|
+
|
2060
|
+
describe ".open" do
|
2061
|
+
context "with no filesystems mounted" do
|
2062
|
+
it "should raise Errno::ENOENT when file doesn't exist" do
|
2063
|
+
expect do
|
2064
|
+
VirtFS::VFile.open("not_a_file")
|
2065
|
+
end.to raise_error(
|
2066
|
+
Errno::ENOENT, "No such file or directory - not_a_file"
|
2067
|
+
)
|
2068
|
+
end
|
2069
|
+
|
2070
|
+
it "should raise Errno::ENOENT file does exist in the native FS" do
|
2071
|
+
expect do
|
2072
|
+
VirtFS::VFile.open(@full_path)
|
2073
|
+
end.to raise_error(
|
2074
|
+
Errno::ENOENT, /No such file or directory -/
|
2075
|
+
)
|
2076
|
+
end
|
2077
|
+
end
|
2078
|
+
|
2079
|
+
context "with FS mounted on '/'" do
|
2080
|
+
before(:each) do
|
2081
|
+
@native_fs = nativefs_class.new
|
2082
|
+
VirtFS.mount(@native_fs, @root)
|
2083
|
+
end
|
2084
|
+
|
2085
|
+
it "should raise Errno::ENOENT when file doesn't exist" do
|
2086
|
+
expect do
|
2087
|
+
VirtFS::VFile.new("not_a_file")
|
2088
|
+
end.to raise_error(
|
2089
|
+
Errno::ENOENT, /No such file or directory/
|
2090
|
+
)
|
2091
|
+
end
|
2092
|
+
|
2093
|
+
it "should return a File object - when no block given" do
|
2094
|
+
expect(VirtFS::VFile.open(@full_path)).to be_kind_of(VirtFS::VFile)
|
2095
|
+
end
|
2096
|
+
|
2097
|
+
it "should yield a file object to the block - when block given" do
|
2098
|
+
VirtFS::VFile.open(@full_path) { |file_obj| expect(file_obj).to be_kind_of(VirtFS::VFile) }
|
2099
|
+
end
|
2100
|
+
|
2101
|
+
it "should return the value of the block - when block given" do
|
2102
|
+
expect(VirtFS::VFile.open(@full_path) { true }).to be true
|
2103
|
+
end
|
2104
|
+
end
|
2105
|
+
end
|
2106
|
+
end
|