Class: FuseFS::SqliteMapperFS
- Inherits:
-
PathMapperFS
- Object
- FuseDir
- PathMapperFS
- FuseFS::SqliteMapperFS
- Defined in:
- lib/fusefs/sqlitemapper.rb
Constant Summary
Constants inherited from FuseDir
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
The database connection.
-
#db_path ⇒ Object
readonly
The database file.
-
#scan_id ⇒ Object
readonly
Maintains a count of the number of times through the scan loop.
Attributes inherited from PathMapperFS
#allow_write, #stats, #use_raw_file_access
Instance Method Summary collapse
-
#initialize(db_path, sql, options = { }) {|row| ... } ⇒ SqliteMapperFS
constructor
A new instance of SqliteMapperFS.
-
#map_row(row) ⇒ String, Hash<Symbol,Object>
abstract
Maps a row into a new filepath.
-
#mounted ⇒ Object
FuseFS callback when the filesystem is mounted Starts the scanning loop and performs the initial scan.
-
#rescan ⇒ Object
Trigger a rescan of the database.
-
#scan ⇒ Object
Executes the sql query and passes each row to map_row (or the block passed in #initialize).
-
#sighup ⇒ Object
Rescan on HUP signal.
-
#unmounted ⇒ Object
FuseFS callback when filesystem is unmounted.
Methods inherited from PathMapperFS
#cleanup, create, #map_directory, #map_file, #mkdir, #node, open_mode, #unmap
Methods inherited from FuseDir
#can_delete?, #can_mkdir?, #can_rmdir?, #can_write?, #contents, #delete, #directory?, #executable?, #file?, #mkdir, #raw_close, #raw_open, #raw_read, #raw_sync, #raw_truncate, #raw_write, #read_file, #rename, #rmdir, #scan_path, #sigint, #sigterm, #size, #split_path, #statistics, #times, #touch, #write_to, #xattr
Constructor Details
#initialize(db_path, sql, options = { }) {|row| ... } ⇒ SqliteMapperFS
Returns a new instance of SqliteMapperFS.
28 29 30 31 32 33 |
# File 'lib/fusefs/sqlitemapper.rb', line 28 def initialize(db_path,sql, = { },&row_mapper) @db_path = db_path.to_s @sql = sql.to_s define_singleton_method(:map_row,row_mapper) if block_given? super() end |
Instance Attribute Details
#db ⇒ Object (readonly)
The database connection
13 14 15 |
# File 'lib/fusefs/sqlitemapper.rb', line 13 def db @db end |
#db_path ⇒ Object (readonly)
The database file
10 11 12 |
# File 'lib/fusefs/sqlitemapper.rb', line 10 def db_path @db_path end |
#scan_id ⇒ Object (readonly)
Maintains a count of the number of times through the scan loop
16 17 18 |
# File 'lib/fusefs/sqlitemapper.rb', line 16 def scan_id @scan_id end |
Instance Method Details
#map_row(row) ⇒ String, Hash<Symbol,Object>
Maps a row into a new filepath
43 44 45 |
# File 'lib/fusefs/sqlitemapper.rb', line 43 def map_row(row) raise NotImplementedError, "abstract method #{__method__} not implemented" end |
#mounted ⇒ Object
FuseFS callback when the filesystem is mounted Starts the scanning loop and performs the initial scan
50 51 52 53 54 55 |
# File 'lib/fusefs/sqlitemapper.rb', line 50 def mounted() @mounted = true @mutex = Mutex.new @cv = ConditionVariable.new @scan_thread = Thread.new() { scan_loop() } end |
#rescan ⇒ Object
Trigger a rescan of the database
69 70 71 |
# File 'lib/fusefs/sqlitemapper.rb', line 69 def rescan() @mutex.synchronize { @cv.signal() } end |
#scan ⇒ Object
Executes the sql query and passes each row to map_row (or the block passed in #initialize)
Subclasses can override this method for pre/post scan processing, calling super as required
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fusefs/sqlitemapper.rb', line 76 def scan() db.execute(@sql) do |row| new_path, real_path, = map_row(row) ||= {} [:sqlite_scan_id] = @scan_id begin map_file(new_path, real_path, ) rescue StandardError => e puts e puts e.backtrace.join("\n") end end cleanup() { |file_node| file_node.[:sqlite_scan_id] != @scan_id } end |
#sighup ⇒ Object
Rescan on HUP signal
92 93 94 |
# File 'lib/fusefs/sqlitemapper.rb', line 92 def sighup rescan() end |
#unmounted ⇒ Object
FuseFS callback when filesystem is unmounted
Stops the database watching threads
61 62 63 64 65 |
# File 'lib/fusefs/sqlitemapper.rb', line 61 def unmounted() @mounted = false @mutex.synchronize { @cv.signal() } @scan_thread.join end |