Class: FuseFS::MetaDir
Instance Method Summary collapse
-
#can_delete?(path) ⇒ Boolean
Delete a file.
-
#can_mkdir?(path) ⇒ Boolean
Make a new directory.
-
#can_rmdir?(path) ⇒ Boolean
Delete an existing directory.
-
#can_write?(path) ⇒ Boolean
Write to a file.
-
#contents(path) ⇒ Object
Contents of directory.
- #delete(path) ⇒ Object
-
#directory?(path) ⇒ Boolean
File types.
- #file?(path) ⇒ Boolean
-
#initialize ⇒ MetaDir
constructor
A new instance of MetaDir.
- #mkdir(path, dir = nil) ⇒ Object
-
#read_file(path) ⇒ Object
File Reading.
- #rmdir(path) ⇒ Object
-
#size(path) ⇒ Object
File sizing.
- #write_to(path, file) ⇒ Object
Methods inherited from FuseDir
Constructor Details
#initialize ⇒ MetaDir
Returns a new instance of MetaDir.
43 44 45 46 |
# File 'lib/fusefs.rb', line 43 def initialize @subdirs = Hash.new(nil) @files = Hash.new(nil) end |
Instance Method Details
#can_delete?(path) ⇒ Boolean
Delete a file
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fusefs.rb', line 153 def can_delete?(path) return false unless Process.uid == FuseFS.reader_uid base, rest = split_path(path) case when base.nil? false when rest.nil? @files.has_key?(base) when ! @subdirs.has_key?(base) false else @subdirs[base].can_delete?(rest) end end |
#can_mkdir?(path) ⇒ Boolean
Make a new directory
183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/fusefs.rb', line 183 def can_mkdir?(path) return false unless Process.uid == FuseFS.reader_uid base, rest = split_path(path) case when base.nil? false when rest.nil? ! (@subdirs.has_key?(base) || @files.has_key?(base)) when ! @subdirs.has_key?(base) false else @subdirs[base].can_mkdir?(rest) end end |
#can_rmdir?(path) ⇒ Boolean
Delete an existing directory.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/fusefs.rb', line 214 def can_rmdir?(path) return false unless Process.uid == FuseFS.reader_uid base, rest = split_path(path) case when base.nil? false when rest.nil? @subdirs.has_key?(base) when ! @subdirs.has_key?(base) false else @subdirs[base].can_rmdir?(rest) end end |
#can_write?(path) ⇒ Boolean
Write to a file
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/fusefs.rb', line 124 def can_write?(path) return false unless Process.uid == FuseFS.reader_uid base, rest = split_path(path) case when base.nil? true when rest.nil? true when ! @subdirs.has_key?(base) false else @subdirs[base].can_write?(rest) end end |
#contents(path) ⇒ Object
Contents of directory.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fusefs.rb', line 49 def contents(path) base, rest = split_path(path) case when base.nil? (@files.keys + @subdirs.keys).sort.uniq when ! @subdirs.has_key?(base) nil when rest.nil? @subdirs[base].contents('/') else @subdirs[base].contents(rest) end end |
#delete(path) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/fusefs.rb', line 167 def delete(path) base, rest = split_path(path) case when base.nil? nil when rest.nil? # Delete it. @files.delete(base) when ! @subdirs.has_key?(base) nil else @subdirs[base].delete(rest) end end |
#directory?(path) ⇒ Boolean
File types
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fusefs.rb', line 64 def directory?(path) base, rest = split_path(path) case when base.nil? true when ! @subdirs.has_key?(base) false when rest.nil? true else @subdirs[base].directory?(rest) end end |
#file?(path) ⇒ Boolean
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fusefs.rb', line 77 def file?(path) base, rest = split_path(path) case when base.nil? false when rest.nil? @files.has_key?(base) when ! @subdirs.has_key?(base) false else @subdirs[base].file?(rest) end end |
#mkdir(path, dir = nil) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/fusefs.rb', line 197 def mkdir(path,dir=nil) base, rest = split_path(path) case when base.nil? false when rest.nil? dir ||= MetaDir.new @subdirs[base] = dir true when ! @subdirs.has_key?(base) false else @subdirs[base].mkdir(rest,dir) end end |
#read_file(path) ⇒ Object
File Reading
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/fusefs.rb', line 92 def read_file(path) base, rest = split_path(path) case when base.nil? nil when rest.nil? @files[base].to_s when ! @subdirs.has_key?(base) nil else @subdirs[base].read_file(rest) end end |
#rmdir(path) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/fusefs.rb', line 228 def rmdir(path) base, rest = split_path(path) dir ||= MetaDir.new case when base.nil? false when rest.nil? @subdirs.delete(base) true when ! @subdirs.has_key?(base) false else @subdirs[base].rmdir(rest,dir) end end |
#size(path) ⇒ Object
File sizing
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fusefs.rb', line 107 def size(path) base, rest = split_path(path) case when base.nil? 0 when rest.nil? obj = @files[base] obj.respond_to?(:size) ? obj.size : 0 when ! @subdirs.has_key?(base) 0 else dir = @subdirs[base] dir.respond_to?(:size) ? dir.size(rest) : 0 end end |
#write_to(path, file) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/fusefs.rb', line 138 def write_to(path,file) base, rest = split_path(path) case when base.nil? false when rest.nil? @files[base] = file when ! @subdirs.has_key?(base) false else @subdirs[base].write_to(rest,file) end end |