Class: FuseFS::PathMapperFS

Inherits:
FuseDir
  • Object
show all
Defined in:
lib/fusefs/pathmapper.rb

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

SqliteMapperFS

Defined Under Namespace

Classes: MNode

Constant Summary

Constants inherited from FuseDir

FuseDir::INIT_TIMES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • options (Hash) (defaults to: { })

Options Hash (options):

  • :use_raw_file_access (Boolean)
  • :allow_write (Boolean)
  • :max_space (Integer)

    available space for writes (for df)

  • :max_nodes (Integer)

    available nodes for writes (for df)



202
203
204
205
206
207
208
209
# File 'lib/fusefs/pathmapper.rb', line 202

def initialize(options = { })
    @stats = StatsHelper.new()
    @stats.max_space = options[:max_space]
    @stats.max_nodes = options[:max_nodes]
    @root = MNode.new(nil,@stats)
    @use_raw_file_access = options[:use_raw_file_access]
    @allow_write = options[:allow_write]
end

Instance Attribute Details

#allow_writeBoolean

should filesystem support writing through to the real files

Returns:

  • (Boolean)

    default is false



177
178
179
# File 'lib/fusefs/pathmapper.rb', line 177

def allow_write
  @allow_write
end

#statsStatsHelper (readonly)

Returns accumulated filesystem statistics.

Returns:



181
182
183
# File 'lib/fusefs/pathmapper.rb', line 181

def stats
  @stats
end

#use_raw_file_accessBoolean

should raw file access should be used - useful for binary files

Returns:

  • (Boolean)

    default is false



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

Parameters:

  • dir (String)
  • options (Hash) (defaults to: { })

Yield Parameters:

  • file (String)

    path to map

Yield Returns:

  • (String)

See Also:



190
191
192
193
194
# File 'lib/fusefs/pathmapper.rb', line 190

def PathMapperFS.create(dir,options={ },&block)
    pm_fs = self.new(options)
    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

Yield Parameters:

  • filesystem (Hash)

    node

Yield Returns:

  • (true, false)

    should this node be deleted



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

Parameters:

  • dirs (String...)

    directories to list

Yield Parameters:

  • file (String)

    path to map

Yield Returns:

  • (String)

    the mapped path

  • nil to skip mapping this file



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

Parameters:

  • real_path (String)

    pointing at the real file location

  • new_path (String)

    the mapped path

  • options (Hash<Symbol,Object>) (defaults to: {})

    metadata for this path

Options Hash (options):

  • :xattr (Hash<String,String>)

    hash to be used as extended attributes

Returns:

  • (MNode)

    a node representing the mapped path. See #node



234
235
236
# File 'lib/fusefs/pathmapper.rb', line 234

def map_file(real_path,new_path,options = {})
    make_node(new_path).init_file(real_path,options)
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,options = {})
    make_node(path).init_dir(options)
end

#node(path) ⇒ MNode

Retrieve in memory node for a mapped path

Parameters:

  • path (String)

Returns:

  • (MNode)

    in memory node at path

  • nil if path does not exist in the filesystem



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