-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepro.rb
60 lines (50 loc) · 1.3 KB
/
repro.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
require 'tempfile'
FN = '/tmp/test.png'
def test(name, &block)
file_write_test name, &block
io_copy_stream_test name, &block
puts
end
def file_write_test(name)
io = yield
File.write(FN, io.read)
puts "#{name}, File.write: #{File.new(FN).size}"
end
def io_copy_stream_test(name)
io = yield
IO.copy_stream(io, FN)
puts "#{name}, IO.copy_stream: #{File.new(FN).size}"
end
test 'open, local' do
File.open('./example.png')
end
test 'open, mounted' do
File.open('/mnt/example.png')
end
test 'tempfile + copy_file, local' do
tf = Tempfile.new(['example', '.png'])
tf.set_encoding(Encoding::BINARY)
FileUtils.copy_file('./example.png', tf.path)
tf
end
test 'tempfile + copy_file, mounted' do
tf = Tempfile.new(['example', '.png'])
tf.set_encoding(Encoding::BINARY)
FileUtils.copy_file('/mnt/example.png', tf.path)
tf
end
test 'tempfile + copy_file + noop utime, mounted' do
tf = Tempfile.new(['example', '.png'])
tf.set_encoding(Encoding::BINARY)
FileUtils.copy_file('/mnt/example.png', tf.path)
File.utime tf.atime, tf.mtime, tf.path
tf
end
test 'tempfile + copy_file + noop chmod, mounted' do
tf = Tempfile.new(['example', '.png'])
tf.set_encoding(Encoding::BINARY)
FileUtils.copy_file('/mnt/example.png', tf.path)
tf.chmod tf.lstat.mode
tf
end