backup-pcs 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ebcf35902015043bb5553060f30656a92097f66
4
- data.tar.gz: 4aea4a4a9c582803a3a8cfb151fb7fed3cc30d58
3
+ metadata.gz: de274b823183c233c391023617bf094b6406140e
4
+ data.tar.gz: dbf975611cfa085310a9fae2dc855dd2cb60474f
5
5
  SHA512:
6
- metadata.gz: ab5c7a9629c8b181164e5a2f28622f985f898bb230cc440792e30be64110c2b3190c24511493b9997f29df10356a7be55cdbf8868ece47cdae2a1eb72eb6ae8d
7
- data.tar.gz: ecd95cc14b3d017d449a73ffae5702159e084ecb336a877f1398fc5a88eb39f8e65c29215999cd271e8b4fe4bbbfcea89270aeb52894eb3c9e12550a54abb573
6
+ metadata.gz: 5df5182c7e80a3b366df2c6680454893bc308c47c89104c3c0eaf8c18a172184c17457e6beb5755b1d26d1ec2ea2d1932c4f0fc778d5640836428d0102ff1c4f
7
+ data.tar.gz: 79e9c98d5d765e8803478b73e613a9cf5607dcee9eea7e2cc4269934e949cc507738d4fa4aa1bb6ea6a49690c16fb11f26f7ac896bc1ed951f78cf3edf6386a1
data/README.md CHANGED
@@ -13,6 +13,8 @@ $ gem install backup-pcs
13
13
  ```
14
14
  `backup-pcs` 当前支持 Ruby(MRI) 版本:1.9.3, 2.0, 2.1
15
15
 
16
+ 如果你使用的是 `Backup 3.x` 版,请对应使用 `backup-pcs` 的 `0.0.3` 版本
17
+
16
18
  ## 用法
17
19
 
18
20
  此说明只提供了本 Gem 的配置使用方法,关于 Backup 的详细使用方法,请参考 [Backup GitHub Page](https://github.com/meskyanichi/backup)
@@ -37,6 +39,7 @@ store_with :PCS do |p|
37
39
  p.client_secret = 'a_cliet_secret'
38
40
  p.dir_name = 'Backups' # 开通 PCS API 权限时所设置的文件目录
39
41
  p.path = 'data' # 保存路径,从 dir_name 算起
42
+ # p.cache_path = '.cache' # 授权文件保存目录,默认在 Backup 的 .cache 下,可以设置为绝对路径
40
43
  # p.keep = 2
41
44
  # p.max_retries = 10 # 出错后重试次数,默认 10 次
42
45
  # p.retry_waitsec = 30 # 出错后重试等待秒数,默认 30 秒
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "baidu-sdk", "~> 0.0.4"
22
- spec.add_runtime_dependency "backup", "~> 3.9"
22
+ spec.add_runtime_dependency "backup", "~> 4.0"
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  end
@@ -1,5 +1,5 @@
1
1
  module Backup
2
2
  module PCS
3
- VERSION = "0.0.3"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -6,14 +6,16 @@ require 'baidu/pcs'
6
6
  module Backup
7
7
  module Storage
8
8
  class PCS < Base
9
+ include Storage::Cycler
9
10
  class Error < Backup::Error; end
10
11
 
11
- attr_accessor :client_id, :client_secret, :dir_name, :max_retries, :retry_waitsec
12
+ attr_accessor :client_id, :client_secret, :cache_path, :dir_name, :max_retries, :retry_waitsec
12
13
 
13
14
  def initialize(model, storage_id=nil)
14
15
  super
15
16
 
16
17
  @path ||= 'backups'
18
+ @cache_path ||= '.cache'
17
19
  @max_retries ||= 10
18
20
  @retry_waitsec ||= 30
19
21
  end
@@ -94,11 +96,12 @@ module Backup
94
96
  end
95
97
 
96
98
  def cached_file
97
- File.join(Config.cache_path, "pcs_#{storage_id}_#{client_id}")
99
+ path = cache_path.start_with?('/') ? cache_path : File.join(Config.root_path, cache_path)
100
+ File.join(path, "pcs_#{storage_id}_#{client_id}")
98
101
  end
99
102
 
100
103
  def write_cache!(session)
101
- FileUtils.mkdir_p(Config.cache_path)
104
+ FileUtils.mkdir_p(File.dirname(cached_file))
102
105
  File.open(cached_file, "w") do |cache_file|
103
106
  cache_file.write(Base64.encode64(Marshal.dump(session)))
104
107
  end
@@ -12,6 +12,10 @@ module Backup
12
12
  expect(storage).to be_a(Storage::Base)
13
13
  end
14
14
 
15
+ it 'includes Storage::::Cycler' do
16
+ expect(storage).to be_a(Storage::Cycler)
17
+ end
18
+
15
19
  it 'has default config' do
16
20
  expect(storage.storage_id ).to be_nil
17
21
  expect(storage.keep ).to be_nil
@@ -19,6 +23,7 @@ module Backup
19
23
  expect(storage.client_secret).to be_nil
20
24
  expect(storage.dir_name ).to be_nil
21
25
  expect(storage.path ).to eq 'backups'
26
+ expect(storage.cache_path ).to eq '.cache'
22
27
  expect(storage.max_retries ).to be 10
23
28
  expect(storage.retry_waitsec).to be 30
24
29
  end
@@ -30,6 +35,7 @@ module Backup
30
35
  c.client_secret = 'cs'
31
36
  c.dir_name = 'dn'
32
37
  c.path = 'myback'
38
+ c.cache_path = '.mycache_path'
33
39
  c.max_retries = 2
34
40
  c.retry_waitsec = 3
35
41
  end
@@ -40,9 +46,22 @@ module Backup
40
46
  expect(storage.client_secret).to eq('cs')
41
47
  expect(storage.dir_name ).to eq('dn')
42
48
  expect(storage.path ).to eq 'myback'
49
+ expect(storage.cache_path ).to eq '.mycache_path'
43
50
  expect(storage.max_retries ).to be(2)
44
51
  expect(storage.retry_waitsec).to be(3)
45
52
  end
53
+
54
+ it 'inits with absolute cache path' do
55
+ storage = Storage::PCS.new(model, 'sid') do |c|
56
+ c.client_id = 'ci'
57
+ c.client_secret = 'cs'
58
+ c.cache_path = '/tmp/pcs_tmp'
59
+ c.dir_name = 'dn'
60
+ c.path = 'myback'
61
+ end
62
+
63
+ expect(storage.cache_path).to eq '/tmp/pcs_tmp'
64
+ end
46
65
  end
47
66
 
48
67
  describe '#transfer!' do
@@ -339,14 +358,15 @@ module Backup
339
358
  describe '#cached_file' do
340
359
  it 'has right cached file path' do
341
360
  path1 = Storage::PCS.new(model, 'sid') do |c|
342
- c.client_id = 'ci'
361
+ c.client_id = 'ci'
343
362
  end.send(:cached_file)
344
- expect(path1).to eq(Config.cache_path + '/pcs_sid_ci')
363
+ expect(path1).to eq("#{Config.root_path}/.cache/pcs_sid_ci")
345
364
 
346
365
  path2 = Storage::PCS.new(model) do |c|
347
- c.client_id = 'ci2'
366
+ c.client_id = 'ci2'
367
+ c.cache_path = '/tmp/pcs'
348
368
  end.send(:cached_file)
349
- expect(path2).to eq(Config.cache_path + '/pcs__ci2')
369
+ expect(path2).to eq('/tmp/pcs/pcs__ci2')
350
370
  end
351
371
  end
352
372
 
@@ -356,12 +376,13 @@ module Backup
356
376
 
357
377
  before do
358
378
  storage.client_id = 'ci'
379
+ allow(File).to receive(:dirname).and_return(File.join(Config.root_path, '.cache'))
359
380
  allow(FileUtils).to receive(:mkdir_p)
360
381
  allow(storage).to receive(:cached_file).and_return(cached_file)
361
382
  end
362
383
 
363
384
  it 'writes cached file' do
364
- expect(FileUtils).to receive(:mkdir_p).with(Config.cache_path)
385
+ expect(FileUtils).to receive(:mkdir_p).with(File.join(Config.root_path, '.cache'))
365
386
  expect(File).to receive(:open).with(cached_file, 'w').and_yield(cached_file)
366
387
  data = Base64.encode64(Marshal.dump(session))
367
388
  expect(cached_file).to receive(:write).with(data)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup-pcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lonre Wang
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.9'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.9'
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement