rfusefs 1.0.1 → 1.0.2.RC0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/fusefs/sqlitemapper.rb +20 -30
- data/lib/rfusefs.rb +29 -10
- data/lib/rfusefs/version.rb +1 -1
- data/rfusefs.gemspec +0 -1
- data/spec/sqlitemapper_spec.rb +2 -2
- metadata +6 -22
data/lib/fusefs/sqlitemapper.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'fusefs/pathmapper'
|
2
2
|
require 'sqlite3'
|
3
|
-
require 'rb-inotify'
|
4
3
|
require 'thread'
|
5
4
|
|
6
5
|
module FuseFS
|
7
6
|
|
8
7
|
class SqliteMapperFS < PathMapperFS
|
9
8
|
|
9
|
+
# The database file
|
10
|
+
attr_reader :db_path
|
11
|
+
|
10
12
|
# The database connection
|
11
13
|
attr_reader :db
|
12
14
|
|
@@ -43,19 +45,13 @@ module FuseFS
|
|
43
45
|
end
|
44
46
|
|
45
47
|
# FuseFS callback when the filesystem is mounted
|
46
|
-
#
|
48
|
+
# Starts the scanning loop and performs the initial scan
|
47
49
|
# @api FuseFS
|
48
50
|
def mounted()
|
51
|
+
@mounted = true
|
49
52
|
@mutex = Mutex.new
|
50
53
|
@cv = ConditionVariable.new
|
51
|
-
@
|
52
|
-
|
53
|
-
notifier = start_notifier
|
54
|
-
|
55
|
-
|
56
|
-
@scan_thread = Thread.new() do
|
57
|
-
scan_loop(notifier)
|
58
|
-
end
|
54
|
+
@scan_thread = Thread.new() { scan_loop() }
|
59
55
|
end
|
60
56
|
|
61
57
|
# FuseFS callback when filesystem is unmounted
|
@@ -64,10 +60,16 @@ module FuseFS
|
|
64
60
|
# @api FuseFS
|
65
61
|
def unmounted()
|
66
62
|
@mounted = false
|
67
|
-
@mutex.synchronize { @cv.signal }
|
63
|
+
@mutex.synchronize { @cv.signal() }
|
68
64
|
@scan_thread.join
|
69
65
|
end
|
70
66
|
|
67
|
+
|
68
|
+
# Trigger a rescan of the database
|
69
|
+
def rescan()
|
70
|
+
@mutex.synchronize { @cv.signal() }
|
71
|
+
end
|
72
|
+
|
71
73
|
# Executes the sql query and passes each row to map_row (or the block passed in {#initialize})
|
72
74
|
#
|
73
75
|
# Subclasses can override this method for pre/post scan processing, calling super as required
|
@@ -76,30 +78,19 @@ module FuseFS
|
|
76
78
|
new_path, real_path, options = map_row(row)
|
77
79
|
options ||= {}
|
78
80
|
options[:sqlite_scan_id] = @scan_id
|
79
|
-
|
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
|
80
87
|
end
|
81
88
|
cleanup() { |file_node| file_node.options[:sqlite_scan_id] != @scan_id }
|
82
89
|
end
|
83
90
|
|
84
91
|
private
|
85
92
|
|
86
|
-
def
|
87
|
-
notifier = INotify::Notifier.new()
|
88
|
-
modified = false
|
89
|
-
notifier.watch(@db_path,:modify, :close_write) do |event|
|
90
|
-
modified = true if event.flags.include?(:modify)
|
91
|
-
if event.flags.include?(:close_write) && modified
|
92
|
-
@mutex.synchronize {@cv.signal}
|
93
|
-
modified = false
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
Thread.new { notifier.run }
|
98
|
-
|
99
|
-
notifier
|
100
|
-
end
|
101
|
-
|
102
|
-
def scan_loop(notifier)
|
93
|
+
def scan_loop()
|
103
94
|
@mutex.synchronize() do
|
104
95
|
@scan_id = 0
|
105
96
|
while @mounted
|
@@ -118,7 +109,6 @@ module FuseFS
|
|
118
109
|
end
|
119
110
|
@cv.wait(@mutex)
|
120
111
|
end
|
121
|
-
notifier.stop
|
122
112
|
end
|
123
113
|
end
|
124
114
|
end
|
data/lib/rfusefs.rb
CHANGED
@@ -48,7 +48,12 @@ module FuseFS
|
|
48
48
|
options = RFuse.parse_options(argv,*options)
|
49
49
|
|
50
50
|
if options[:mountpoint]
|
51
|
-
|
51
|
+
begin
|
52
|
+
fs = yield options
|
53
|
+
rescue StandardError => ex
|
54
|
+
puts ex.message
|
55
|
+
puts ex.backtrace.join("\n")
|
56
|
+
end
|
52
57
|
|
53
58
|
puts RFuse.usage(device,exec) if options[:help] || !fs
|
54
59
|
puts "Options:\n" if options[:help]
|
@@ -62,18 +67,24 @@ module FuseFS
|
|
62
67
|
end
|
63
68
|
|
64
69
|
# Start the FuseFS root at mountpoint with opts.
|
70
|
+
#
|
71
|
+
# If not previously set, Signal traps for "TERM" and "INT" are added
|
72
|
+
# to exit the filesystem
|
73
|
+
#
|
65
74
|
# @param [Object] root see {set_root}
|
66
75
|
# @param mountpoint [String] {mount_under}
|
67
76
|
# @param [String...] opts FUSE mount options see {mount_under}
|
68
77
|
# @note RFuseFS extension
|
69
78
|
# @return [void]
|
70
79
|
def FuseFS.start(root,mountpoint,*opts)
|
71
|
-
|
72
|
-
Signal.trap("INT") { FuseFS.exit() }
|
80
|
+
set_default_traps("TERM","INT") { FuseFS.exit }
|
73
81
|
FuseFS.set_root(root)
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
begin
|
83
|
+
FuseFS.mount_under(mountpoint,*opts)
|
84
|
+
FuseFS.run
|
85
|
+
ensure
|
86
|
+
FuseFS.unmount()
|
87
|
+
end
|
77
88
|
end
|
78
89
|
|
79
90
|
# Forks {FuseFS.start} so you can access your filesystem with ruby File
|
@@ -100,7 +111,6 @@ module FuseFS
|
|
100
111
|
if (mountpoint)
|
101
112
|
if @mounts.has_key?(mountpoint)
|
102
113
|
pid = @mounts[mountpoint]
|
103
|
-
print "Sending TERM to forked FuseFS (#{pid})\n"
|
104
114
|
Process.kill("TERM",pid)
|
105
115
|
Process.waitpid(pid)
|
106
116
|
else
|
@@ -143,16 +153,14 @@ module FuseFS
|
|
143
153
|
def FuseFS.run
|
144
154
|
@fs.mounted()
|
145
155
|
@fuse.loop if @fuse.mounted?
|
156
|
+
ensure
|
146
157
|
@fs.unmounted()
|
147
158
|
end
|
148
159
|
|
149
160
|
# Exit the run loop and teardown FUSE
|
150
161
|
# Most useful from Signal.trap() or Kernel.at_exit()
|
151
162
|
def FuseFS.exit
|
152
|
-
@running = false
|
153
|
-
|
154
163
|
if @fuse
|
155
|
-
print "Exitting FUSE #{@fuse.mountname}\n"
|
156
164
|
@fuse.exit
|
157
165
|
end
|
158
166
|
end
|
@@ -176,5 +184,16 @@ module FuseFS
|
|
176
184
|
def self.handle_editor(bool)
|
177
185
|
#do nothing
|
178
186
|
end
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
def self.set_default_traps(*signals,&block)
|
191
|
+
signals.each do |sig|
|
192
|
+
old_proc = Signal.trap(sig,block)
|
193
|
+
unless "DEFAULT".eql?(old_proc)
|
194
|
+
Signal.trap(sig,old_proc)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
179
198
|
end
|
180
199
|
|
data/lib/rfusefs/version.rb
CHANGED
data/rfusefs.gemspec
CHANGED
data/spec/sqlitemapper_spec.rb
CHANGED
@@ -102,14 +102,14 @@ describe "SqliteMapper" do
|
|
102
102
|
it "should add new files" do
|
103
103
|
fixture.pathmap("added.txt","/textfiles/added.txt")
|
104
104
|
fixture.db_force_write()
|
105
|
-
sleep(0.3)
|
105
|
+
fs.rescan; sleep(0.3)
|
106
106
|
fs.file?("/textfiles/added.txt").should be_true
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should remove files and directories no longer mapped" do
|
110
110
|
fixture.unpathmap("/textfiles/hello")
|
111
111
|
fixture.db_force_write()
|
112
|
-
sleep(0.3)
|
112
|
+
fs.rescan; sleep(0.3)
|
113
113
|
fs.file?("/textfiles/hello").should be_false
|
114
114
|
fs.directory?("/textfiles").should be_false
|
115
115
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfusefs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.2.RC0
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Grant Gardner
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rfuse
|
@@ -107,22 +107,6 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: rb-inotify
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
110
|
description: A more Ruby like way to write FUSE filesystems - inspired by (compatible
|
127
111
|
with) FuseFS, implemented over RFuse
|
128
112
|
email:
|
@@ -178,12 +162,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
163
|
none: false
|
180
164
|
requirements:
|
181
|
-
- - ! '
|
165
|
+
- - ! '>'
|
182
166
|
- !ruby/object:Gem::Version
|
183
|
-
version:
|
167
|
+
version: 1.3.1
|
184
168
|
requirements: []
|
185
169
|
rubyforge_project:
|
186
|
-
rubygems_version: 1.8.
|
170
|
+
rubygems_version: 1.8.23
|
187
171
|
signing_key:
|
188
172
|
specification_version: 3
|
189
173
|
summary: Filesystem in Ruby Userspace
|