rfusefs 1.0.0 → 1.0.1.RC0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+ require 'tmpdir'
3
+ require 'sqlite3'
4
+ require 'pathname'
5
+ require "fusefs/sqlitemapper"
6
+
7
+ class SQLFixture
8
+
9
+ SQL = "select * from files"
10
+
11
+ attr_reader :tmpdir
12
+ attr_reader :db
13
+ def initialize()
14
+ @tmpdir = Pathname.new(Dir.mktmpdir("rfusefs_sqlitemapper"))
15
+ @db_path = @tmpdir + "test.db"
16
+ @db = SQLite3::Database.new(@db_path.to_s)
17
+ @db.execute <<-SQL
18
+ create table files (
19
+ real_path varchar(120),
20
+ mapped_path varchar(120)
21
+ );
22
+ SQL
23
+
24
+ pathmap("hello.txt","/textfiles/hello")
25
+ pathmap("mysong.mp3","/artist/album/mysong.mp3")
26
+ pathmap("apicture.jpeg","/pictures/201103/apicture.jpg")
27
+
28
+ end
29
+
30
+ def pathmap(real_file,mapped_path)
31
+ real_path = (@tmpdir + real_file).to_s
32
+ File.open(real_path,"w") do |f|
33
+ f << mapped_path
34
+ end
35
+ @db.execute "insert into files values ( ?, ? )", real_path,mapped_path
36
+ end
37
+
38
+ def unpathmap(mapped_path)
39
+ @db.execute("delete from files where mapped_path = ?", mapped_path)
40
+ end
41
+
42
+ def db_force_write
43
+ @db.close unless @db.closed?
44
+ @db = SQLite3::Database.new(@db_path.to_s)
45
+ end
46
+
47
+ def fs
48
+ @fs ||= FuseFS::SqliteMapperFS.new(@db_path,SQL) do |row|
49
+ [ row['real_path'], row['mapped_path'] ]
50
+ end
51
+ end
52
+
53
+ def mount()
54
+ return @mountpoint if @mountpoint
55
+ @mountpoint = Pathname.new(Dir.mktmpdir("rfusefs_sqlitmapper_mnt"))
56
+ FuseFS.mount(fs,@mountpoint)
57
+ sleep 0.5
58
+ @mountpoint
59
+ end
60
+
61
+ def cleanup
62
+ @db.close
63
+ if @mountpoint
64
+ FuseFS.unmount(@mountpoint)
65
+ FileUtils.rmdir @mountpoint
66
+ end
67
+ FileUtils.rm_r(@tmpdir)
68
+ end
69
+ end
70
+ describe "SqliteMapper" do
71
+
72
+ let(:fixture) { SQLFixture.new }
73
+ let(:fs) { fixture.fs }
74
+
75
+ after(:each) do
76
+ fixture.cleanup
77
+ end
78
+
79
+ context "filesystem outside FUSE" do
80
+ before(:each) do
81
+ fs.mounted()
82
+ sleep(0.5)
83
+ end
84
+
85
+ after(:each) do
86
+ fs.unmounted()
87
+ end
88
+
89
+ it "should map files from a sqlite database" do
90
+ fs.directory?("/").should be_true
91
+ fs.directory?("/textfiles").should be_true
92
+ fs.directory?("/pictures/201103").should be_true
93
+ fs.file?("/textfiles/hello").should be_true
94
+ fs.directory?("/textfiles/hello").should be_false
95
+ fs.file?("/artist/album/mysong.mp3").should be_true
96
+ fs.directory?("/artist/album/mysong.mp3").should be_false
97
+ fs.file?("/some/unknown/path").should be_false
98
+ end
99
+
100
+ context "an updated database" do
101
+
102
+ it "should add new files" do
103
+ fixture.pathmap("added.txt","/textfiles/added.txt")
104
+ fixture.db_force_write()
105
+ sleep(0.3)
106
+ fs.file?("/textfiles/added.txt").should be_true
107
+ end
108
+
109
+ it "should remove files and directories no longer mapped" do
110
+ fixture.unpathmap("/textfiles/hello")
111
+ fixture.db_force_write()
112
+ sleep(0.3)
113
+ fs.file?("/textfiles/hello").should be_false
114
+ fs.directory?("/textfiles").should be_false
115
+ end
116
+ end
117
+
118
+ context "a real Fuse filesystem" do
119
+ before(:each) do
120
+ fs.use_raw_file_access = true
121
+ fs.allow_write = true
122
+ @mountpoint = fixture.mount
123
+ end
124
+
125
+ it "should read files" do
126
+
127
+ hello_path = (@mountpoint + "textfiles/hello")
128
+ hello_path.open do |f|
129
+ f.read.should == "/textfiles/hello"
130
+ end
131
+ end
132
+
133
+ end
134
+ end
135
+ end
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfusefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.1.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: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2013-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rfuse
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '1.0'
21
+ version: 1.0.4RC0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: 1.0.4RC0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +91,38 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
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'
94
126
  description: A more Ruby like way to write FUSE filesystems - inspired by (compatible
95
127
  with) FuseFS, implemented over RFuse
96
128
  email:
@@ -100,6 +132,7 @@ extensions: []
100
132
  extra_rdoc_files: []
101
133
  files:
102
134
  - .gitignore
135
+ - .travis.yml
103
136
  - Gemfile
104
137
  - History.rdoc
105
138
  - README.rdoc
@@ -111,8 +144,10 @@ files:
111
144
  - lib/fusefs/dirlink.rb
112
145
  - lib/fusefs/metadir.rb
113
146
  - lib/fusefs/pathmapper.rb
147
+ - lib/fusefs/sqlitemapper.rb
114
148
  - lib/rfusefs.rb
115
149
  - lib/rfusefs/version.rb
150
+ - rfusefs.gemspec
116
151
  - samples/demo.rb
117
152
  - samples/dictfs.rb
118
153
  - samples/hello.rb
@@ -122,10 +157,12 @@ files:
122
157
  - samples/yamlfs.rb
123
158
  - spec-fusefs/fusefs_spec.rb
124
159
  - spec/metadir_spec.rb
160
+ - spec/mount_unmount_spec.rb
125
161
  - spec/pathmapper_spec.rb
126
162
  - spec/rfusefs_spec.rb
127
163
  - spec/sample_spec.rb
128
164
  - spec/spec_helper.rb
165
+ - spec/sqlitemapper_spec.rb
129
166
  homepage: http://rubygems.org/gems/rfusefs
130
167
  licenses: []
131
168
  post_install_message:
@@ -138,12 +175,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
175
  - - ! '>='
139
176
  - !ruby/object:Gem::Version
140
177
  version: '0'
178
+ segments:
179
+ - 0
180
+ hash: -2524811135440594792
141
181
  required_rubygems_version: !ruby/object:Gem::Requirement
142
182
  none: false
143
183
  requirements:
144
- - - ! '>='
184
+ - - ! '>'
145
185
  - !ruby/object:Gem::Version
146
- version: '0'
186
+ version: 1.3.1
147
187
  requirements: []
148
188
  rubyforge_project:
149
189
  rubygems_version: 1.8.24