simple_fs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/simple_fs.rb +51 -0
- data/lib/simple_fs/file_pool.rb +29 -0
- data/lib/simple_fs/version.rb +3 -0
- data/simple_fs.gemspec +22 -0
- data/spec/filepool_spec.rb +38 -0
- data/spec/fixture/test +2083 -0
- data/spec/simple_fs_spec.rb +61 -0
- metadata +92 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..' , 'lib', 'simple_fs')
|
4
|
+
require 'sequel'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
describe SimpleFS, "一般操作" do
|
8
|
+
before(:all) do
|
9
|
+
@fs_path = '/tmp/fs'
|
10
|
+
FileUtils.rm_rf @fs_path if Dir.exist? @fs_path
|
11
|
+
@fs = SimpleFS::FS.new(@fs_path)
|
12
|
+
@db = Sequel.sqlite File.join(@fs_path, 'index.db')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "new" do
|
16
|
+
Dir.exist?(File.join(@fs_path, 'pool')).should == true
|
17
|
+
File.exist?(File.join(@fs_path, 'index.db')).should == true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "create" do
|
21
|
+
test_data = "This is test data."
|
22
|
+
test_data_md5 = Digest::MD5.hexdigest(test_data)
|
23
|
+
path = '/test'
|
24
|
+
@fs.create path, test_data
|
25
|
+
|
26
|
+
record = @db[:index].where(:path => '/test')
|
27
|
+
record.count.should == 1
|
28
|
+
record.first[:path].should == path
|
29
|
+
record.first[:file_id].should == test_data_md5
|
30
|
+
end
|
31
|
+
|
32
|
+
it "copy" do
|
33
|
+
old_path = '/test'
|
34
|
+
new_path = '/test2'
|
35
|
+
@fs.copy old_path, new_path
|
36
|
+
|
37
|
+
record_old = @db[:index].where(:path => old_path).first
|
38
|
+
record_new = @db[:index].where(:path => new_path).first
|
39
|
+
record_new[:path].should == new_path
|
40
|
+
record_new[:file_id].should == record_old[:file_id]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "move" do
|
44
|
+
old_path = '/test2'
|
45
|
+
new_path = '/test2_mv'
|
46
|
+
|
47
|
+
file_id = @db[:index].where(:path => old_path).first[:file_id]
|
48
|
+
@fs.move old_path, new_path
|
49
|
+
|
50
|
+
@db[:index].where(:path => old_path).count.should == 0
|
51
|
+
new_record = @db[:index].where(:path => new_path).first
|
52
|
+
new_record[:file_id].should == file_id
|
53
|
+
end
|
54
|
+
|
55
|
+
it "remove" do
|
56
|
+
path = "/test"
|
57
|
+
@fs.remove path
|
58
|
+
|
59
|
+
@db[:index].where(:path => path).count.should == 0
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_fs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Hsu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sqlite3
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sequel
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ''
|
47
|
+
email:
|
48
|
+
- nickhsu.tw@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/simple_fs.rb
|
59
|
+
- lib/simple_fs/file_pool.rb
|
60
|
+
- lib/simple_fs/version.rb
|
61
|
+
- simple_fs.gemspec
|
62
|
+
- spec/filepool_spec.rb
|
63
|
+
- spec/fixture/test
|
64
|
+
- spec/simple_fs_spec.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: ''
|
89
|
+
test_files:
|
90
|
+
- spec/filepool_spec.rb
|
91
|
+
- spec/fixture/test
|
92
|
+
- spec/simple_fs_spec.rb
|