omnistore 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/omnistore/storage/local.rb +14 -3
- data/lib/omnistore/storage/s3.rb +5 -0
- data/lib/omnistore/version.rb +1 -1
- data/spec/omnistore/storage/local_spec.rb +103 -16
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
@@ -11,11 +11,23 @@ module OmniStore
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def exist?(path)
|
14
|
-
File.exist?(
|
14
|
+
File.exist?(expand(path))
|
15
15
|
end
|
16
16
|
|
17
17
|
def delete(path)
|
18
|
-
FileUtils.
|
18
|
+
FileUtils.rm(expand(path))
|
19
|
+
end
|
20
|
+
|
21
|
+
def move(src, dest, other = self, options = {})
|
22
|
+
src_path = expand(src)
|
23
|
+
dest_path = expand(dest, other.dir)
|
24
|
+
FileUtils.mv(src_path, dest_path, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def expand(path, dir = @dir)
|
30
|
+
File.expand_path(path, dir)
|
19
31
|
end
|
20
32
|
end
|
21
33
|
|
@@ -35,7 +47,6 @@ module OmniStore
|
|
35
47
|
def exist?(path)
|
36
48
|
@@mountpoint.values.find {|m| m.exist?(path) }
|
37
49
|
end
|
38
|
-
alias :find :exist?
|
39
50
|
|
40
51
|
def delete(path)
|
41
52
|
@@mountpoint.values.each {|m| m.delete(path) }
|
data/lib/omnistore/storage/s3.rb
CHANGED
@@ -23,6 +23,11 @@ module OmniStore
|
|
23
23
|
def write(key, options_or_data = nil, options = nil)
|
24
24
|
bucket.objects[key].write(options_or_data, options)
|
25
25
|
end
|
26
|
+
|
27
|
+
def move(src, dest, other = self, options = {})
|
28
|
+
options[:bucket_name] = other.bucket.name
|
29
|
+
bucket.objects[key].move_to(dest, options)
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
def mount!
|
data/lib/omnistore/version.rb
CHANGED
@@ -3,31 +3,118 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
describe OmniStore::Storage::Local do
|
5
5
|
|
6
|
+
def expand_path(path, mountpoint = OmniStore::Config.mountpoint)
|
7
|
+
File.expand_path(path, mountpoint)
|
8
|
+
end
|
9
|
+
|
6
10
|
before(:each) do
|
7
11
|
OmniStore::Config.storage = 'local'
|
8
12
|
OmniStore::Config.mountpoint = MOUNTPOINT
|
9
|
-
OmniStore::Storage.remount!
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
describe "#mount!" do
|
16
|
+
it 'should not raise error' do
|
17
|
+
OmniStore::Config.mountpoint = MOUNTPOINT
|
18
|
+
lambda { OmniStore::Storage::Local.mount! }.should_not raise_error
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
it 'should not raise error when hash mountpoint' do
|
22
|
+
OmniStore::Config.mountpoint = { :a => MOUNTPOINT, :b => TMPDIR }
|
23
|
+
lambda { OmniStore::Storage::Local.mount! }.should_not raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise error when mount fails' do
|
27
|
+
OmniStore::Config.mountpoint = nil
|
28
|
+
lambda { OmniStore::Storage::Local.mount! }.should raise_error(OmniStore::Errors::InvalidMountpoint)
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
OmniStore::
|
27
|
-
OmniStore::Storage
|
28
|
-
|
29
|
-
|
32
|
+
context "single mountpoint" do
|
33
|
+
let(:src) { 'test.txt' }
|
34
|
+
let(:src_fullpath) { expand_path(src) }
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
OmniStore::Config.mountpoint = MOUNTPOINT
|
38
|
+
OmniStore::Storage.remount!
|
39
|
+
FileUtils.touch(src_fullpath)
|
40
|
+
end
|
41
|
+
after(:each) { FileUtils.rm_f(src_fullpath) }
|
42
|
+
|
43
|
+
describe "#exist?" do
|
44
|
+
it 'should return true' do
|
45
|
+
OmniStore::Storage::Local.exist?(src).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return false' do
|
49
|
+
OmniStore::Storage::Local.exist?(src + '.bk').should be_false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#delete" do
|
54
|
+
it 'should return true' do
|
55
|
+
lambda { OmniStore::Storage::Local.delete(src) }.should_not raise_error
|
56
|
+
File.exist?(src_fullpath).should be_false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#move" do
|
61
|
+
let(:dst) { src + '.mv' }
|
62
|
+
let(:dst_fullpath) { expand_path(dst) }
|
63
|
+
let(:mountpoint) { OmniStore::Storage::Local.mountpoint(MOUNTPOINT) }
|
64
|
+
after(:each) { FileUtils.rm_f(dst_fullpath) }
|
65
|
+
|
66
|
+
it 'should move to target path' do
|
67
|
+
lambda { mountpoint.move(src, dst) }.should_not raise_error
|
68
|
+
File.exist?(src_fullpath).should be_false
|
69
|
+
File.exist?(dst_fullpath).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should raise error when source file is not exists' do
|
73
|
+
lambda { mountpoint.move(dst, src) }.should raise_error
|
74
|
+
end
|
30
75
|
end
|
31
76
|
end
|
32
77
|
|
78
|
+
context "dounble mountpoint" do
|
79
|
+
let(:src) { 'test.txt' }
|
80
|
+
let(:src_fullpath) { expand_path(src, MOUNTPOINT) }
|
81
|
+
|
82
|
+
before(:each) do
|
83
|
+
OmniStore::Config.mountpoint = { :a => MOUNTPOINT, :b => TMPDIR }
|
84
|
+
OmniStore::Storage.remount!
|
85
|
+
FileUtils.touch(src_fullpath)
|
86
|
+
end
|
87
|
+
after(:each) { FileUtils.rm_f(src_fullpath) }
|
88
|
+
|
89
|
+
describe "#exist?" do
|
90
|
+
it 'should return true' do
|
91
|
+
OmniStore::Storage::Local.exist?(src).should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return false' do
|
95
|
+
OmniStore::Storage::Local.exist?(src + '.bk').should be_false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#delete" do
|
100
|
+
it 'should return true' do
|
101
|
+
lambda { OmniStore::Storage::Local.delete(src) }.should raise_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#move" do
|
106
|
+
let(:dst) { src + '.mv' }
|
107
|
+
let(:dst_fullpath) { expand_path(dst, TMPDIR) }
|
108
|
+
let(:mountpoint) { OmniStore::Storage::Local.mountpoint(:a) }
|
109
|
+
let(:another) { OmniStore::Storage::Local.mountpoint(:b) }
|
110
|
+
after(:each) { FileUtils.rm_f(dst_fullpath) }
|
111
|
+
|
112
|
+
it 'should move to target path of another mountpoint' do
|
113
|
+
lambda { mountpoint.move(src, dst, another) }.should_not raise_error
|
114
|
+
File.exist?(src_fullpath).should be_false
|
115
|
+
File.exist?(File.join(MOUNTPOINT, dst)).should be_false
|
116
|
+
File.exist?(File.join(TMPDIR, dst)).should be_true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
33
120
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnistore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash: -
|
121
|
+
hash: -704812863
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash: -
|
130
|
+
hash: -704812863
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
133
|
rubygems_version: 1.8.24
|