-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunionfs.rb
64 lines (50 loc) · 1.06 KB
/
unionfs.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
61
62
63
64
#!ruby
require_relative "../invfs"
module InVFS
class UnionFS
attr_reader :dirs
def initialize(*dirs)
@dirs = dirs
end
def file?(lib)
dirs.each do |dir|
path = File.join(dir, lib)
return true if File.file?(path)
end
false
end
def size(lib)
dirs.each do |dir|
path = File.join(dir, lib)
return File.size(path) if File.file?(path)
end
raise Errno::ENOENT, lib
end
def read(lib)
dirs.each do |dir|
path = File.join(dir, lib)
return File.binread(path) if File.file?(path)
end
raise Errno::ENOENT, lib
end
def to_path
%(#<#{self.class} #{dirs.map { |d| "<#{d}>" }.join(", ")}>)
end
def to_s
to_path
end
def inspect
to_s
end
def pretty_print(q)
q.group(2, "#<#{self.class}", ">") do
dirs.each_with_index do |d, i|
q.text "," if i > 0
q.breakable " "
d.pretty_print q
end
end
end
end
MultipleDirectory = UnionFS
end