rfusefs 1.1.0 → 1.1.1.rc20201114.37

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ require 'fusefs/pathmapper'
2
+ require 'sqlite3'
3
+ require 'thread'
4
+
5
+ module FuseFS
6
+
7
+ class SqliteMapperFS < PathMapperFS
8
+
9
+ # The database file
10
+ attr_reader :db_path
11
+
12
+ # The database connection
13
+ attr_reader :db
14
+
15
+ # Maintains a count of the number of times through the scan loop
16
+ attr_reader :scan_id
17
+
18
+ #
19
+ #
20
+ # @param [String] db_path Path to Sqlite database
21
+ # @param [String] sql query
22
+ # @param [Hash] options see {PathMapperFS#initialize}
23
+ # @yieldparam [Row] row to map
24
+ # @yieldreturn [String,String,Hash<Symbol,Object>] newpath, realpath, options
25
+ # * newpath - the mapped path
26
+ # * realpath - path to the real file
27
+ # * options - additional information to store with this path
28
+ def initialize(db_path,sql,options = { },&row_mapper)
29
+ @db_path = db_path.to_s
30
+ @sql = sql.to_s
31
+ define_singleton_method(:map_row,row_mapper) if block_given?
32
+ super(options)
33
+ end
34
+
35
+ # Maps a row into a new filepath
36
+ #
37
+ # @param [Hash] row sqlite result hash for a row
38
+ # @return [String,String,Hash<Symbol,Object>] newpath, realpath, options
39
+ # * newpath - the mapped path
40
+ # * realpath - path to the real file
41
+ # * options - additional information to store with this path
42
+ # @abstract
43
+ def map_row(row)
44
+ raise NotImplementedError, "abstract method #{__method__} not implemented"
45
+ end
46
+
47
+ # FuseFS callback when the filesystem is mounted
48
+ # Starts the scanning loop and performs the initial scan
49
+ # @api FuseFS
50
+ def mounted()
51
+ @mounted = true
52
+ @mutex = Mutex.new
53
+ @cv = ConditionVariable.new
54
+ @scan_thread = Thread.new() { scan_loop() }
55
+ end
56
+
57
+ # FuseFS callback when filesystem is unmounted
58
+ #
59
+ # Stops the database watching threads
60
+ # @api FuseFS
61
+ def unmounted()
62
+ @mounted = false
63
+ @mutex.synchronize { @cv.signal() }
64
+ @scan_thread.join
65
+ end
66
+
67
+
68
+ # Trigger a rescan of the database
69
+ def rescan()
70
+ @mutex.synchronize { @cv.signal() }
71
+ end
72
+
73
+ # Executes the sql query and passes each row to map_row (or the block passed in {#initialize})
74
+ #
75
+ # Subclasses can override this method for pre/post scan processing, calling super as required
76
+ def scan()
77
+ db.execute(@sql) do |row|
78
+ new_path, real_path, options = map_row(row)
79
+ options ||= {}
80
+ options[:sqlite_scan_id] = @scan_id
81
+ begin
82
+ map_file(new_path, real_path, options)
83
+ rescue StandardError => e
84
+ puts e
85
+ puts e.backtrace.join("\n")
86
+ end
87
+ end
88
+ cleanup() { |file_node| file_node.options[:sqlite_scan_id] != @scan_id }
89
+ end
90
+
91
+ # Rescan on HUP signal
92
+ def sighup
93
+ rescan()
94
+ end
95
+
96
+ private
97
+
98
+ def scan_loop()
99
+ @mutex.synchronize() do
100
+ @scan_id = 0
101
+ while @mounted
102
+ begin
103
+ @db = SQLite3::Database.new(@db_path,:readonly => true)
104
+ @db.results_as_hash = true
105
+ @db.busy_timeout(10000)
106
+ @scan_id = @scan_id + 1
107
+ scan()
108
+ rescue StandardError => e
109
+ puts e
110
+ puts e.backtrace.join("\n")
111
+ ensure
112
+ @db.close unless @db.closed?
113
+ @db = nil
114
+ end
115
+ @cv.wait(@mutex)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ module RFuseFS
2
+ VERSION="1.1.1"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfusefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1.rc20201114.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Gardner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-10 00:00:00.000000000 Z
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rfuse
@@ -136,8 +136,15 @@ files:
136
136
  - LICENSE
137
137
  - README.md
138
138
  - TODO.md
139
+ - lib/fuse/fusedir.rb
140
+ - lib/fuse/rfusefs-fuse.rb
139
141
  - lib/fusefs.rb
142
+ - lib/fusefs/dirlink.rb
143
+ - lib/fusefs/metadir.rb
144
+ - lib/fusefs/pathmapper.rb
145
+ - lib/fusefs/sqlitemapper.rb
140
146
  - lib/rfusefs.rb
147
+ - lib/rfusefs/version.rb
141
148
  homepage: http://rubygems.org/gems/rfusefs
142
149
  licenses:
143
150
  - MIT
@@ -153,9 +160,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
160
  version: '2.5'
154
161
  required_rubygems_version: !ruby/object:Gem::Requirement
155
162
  requirements:
156
- - - ">="
163
+ - - ">"
157
164
  - !ruby/object:Gem::Version
158
- version: '0'
165
+ version: 1.3.1
159
166
  requirements: []
160
167
  rubygems_version: 3.0.8
161
168
  signing_key: