Class: FuseFS::PathMapperFS
Overview
A FuseFS that maps files from their original location into a new path eg tagged audio files can be mapped by title etc…
Direct Known Subclasses
Defined Under Namespace
Classes: MNode
Constant Summary
Constants inherited from FuseDir
Instance Attribute Summary collapse
-
#allow_write ⇒ Boolean
should filesystem support writing through to the real files.
-
#stats ⇒ StatsHelper
readonly
Accumulated filesystem statistics.
-
#use_raw_file_access ⇒ Boolean
should raw file access should be used - useful for binary files.
Class Method Summary collapse
-
.create(dir, options = { }) {|file| ... } ⇒ Object
Creates a new Path Mapper filesystem over an existing directory.
-
.open_mode(raw_mode) ⇒ Object
Convert FuseFS raw_mode strings back to IO open mode strings.
Instance Method Summary collapse
-
#cleanup {|filesystem| ... } ⇒ Object
Deletes files and directories.
-
#initialize(options = { }) ⇒ PathMapperFS
constructor
Create a new Path Mapper filesystem.
-
#map_directory(*dirs) {|file| ... } ⇒ Object
(also: #mapDirectory)
Recursively find all files and map according to the given block.
-
#map_file(real_path, new_path, options = {}) ⇒ MNode
(also: #mapFile)
Add (or replace) a mapped file.
-
#mkdir(path, options = {}) ⇒ Object
Note we don’t impleemnt can_mkdir? so this can only be called by code.
-
#node(path) ⇒ MNode
Retrieve in memory node for a mapped path.
-
#unmap(path) ⇒ Object
Takes a mapped file name and returns the original real_path.
Methods inherited from FuseDir
#can_delete?, #can_mkdir?, #can_rmdir?, #delete, #executable?, #mounted, #raw_truncate, #rename, #rmdir, #scan_path, #sigint, #sigterm, #split_path, #touch, #unmounted
Constructor Details
#initialize(options = { }) ⇒ PathMapperFS
Create a new Path Mapper filesystem
202 203 204 205 206 207 208 209 |
# File 'lib/fusefs/pathmapper.rb', line 202 def initialize( = { }) @stats = StatsHelper.new() @stats.max_space = [:max_space] @stats.max_nodes = [:max_nodes] @root = MNode.new(nil,@stats) @use_raw_file_access = [:use_raw_file_access] @allow_write = [:allow_write] end |
Instance Attribute Details
#allow_write ⇒ Boolean
should filesystem support writing through to the real files
177 178 179 |
# File 'lib/fusefs/pathmapper.rb', line 177 def allow_write @allow_write end |
#stats ⇒ StatsHelper (readonly)
Returns accumulated filesystem statistics.
181 182 183 |
# File 'lib/fusefs/pathmapper.rb', line 181 def stats @stats end |
#use_raw_file_access ⇒ Boolean
should raw file access should be used - useful for binary files
172 173 174 |
# File 'lib/fusefs/pathmapper.rb', line 172 def use_raw_file_access @use_raw_file_access end |
Class Method Details
.create(dir, options = { }) {|file| ... } ⇒ Object
Creates a new Path Mapper filesystem over an existing directory
190 191 192 193 194 |
# File 'lib/fusefs/pathmapper.rb', line 190 def PathMapperFS.create(dir,={ },&block) pm_fs = self.new() pm_fs.map_directory(dir,&block) return pm_fs end |
.open_mode(raw_mode) ⇒ Object
Convert FuseFS raw_mode strings back to IO open mode strings
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/fusefs/pathmapper.rb', line 152 def self.open_mode(raw_mode) case raw_mode when "r" "r" when "ra" "r" #not really sensible.. when "rw" "r+" when "rwa" "a+" when "w" "w" when "wa" "a" end end |
Instance Method Details
#cleanup {|filesystem| ... } ⇒ Object
Deletes files and directories. Yields each #node in the filesystem and deletes it if the block returns true
Useful if your filesystem is periodically remapping the entire contents and you need to delete entries that have not been touched in the latest scan
268 269 270 |
# File 'lib/fusefs/pathmapper.rb', line 268 def cleanup(&block) recursive_cleanup(@root,&block) end |
#map_directory(*dirs) {|file| ... } ⇒ Object Also known as: mapDirectory
Recursively find all files and map according to the given block
216 217 218 219 220 221 222 |
# File 'lib/fusefs/pathmapper.rb', line 216 def map_directory(*dirs) require 'find' Find.find(*dirs) do |file| new_path = yield file map_file(file,new_path) if new_path end end |
#map_file(real_path, new_path, options = {}) ⇒ MNode Also known as: mapFile
Add (or replace) a mapped file
234 235 236 |
# File 'lib/fusefs/pathmapper.rb', line 234 def map_file(real_path,new_path, = {}) make_node(new_path).init_file(real_path,) end |
#mkdir(path, options = {}) ⇒ Object
Note we don’t impleemnt can_mkdir? so this can only be called by code. Really only useful to create empty directories
306 307 308 |
# File 'lib/fusefs/pathmapper.rb', line 306 def mkdir(path, = {}) make_node(path).init_dir() end |
#node(path) ⇒ MNode
Retrieve in memory node for a mapped path
244 245 246 247 248 249 250 251 252 |
# File 'lib/fusefs/pathmapper.rb', line 244 def node(path) path_components = scan_path(path) #not actually injecting anything here, we're just following the hash of hashes... path_components.inject(@root) { |dir,file| break unless dir.files[file] dir.files[file] } end |
#unmap(path) ⇒ Object
Takes a mapped file name and returns the original real_path
255 256 257 258 |
# File 'lib/fusefs/pathmapper.rb', line 255 def unmap(path) node = node(path) (node && node.file?) ? node.real_path : nil end |