bfs-scp 0.6.0 → 0.6.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fc1b42d4747715149cbe00ed2712c973680221579ab7a420ac46f6bd1bb2333
4
- data.tar.gz: abf74a6979b1959547f91ed3ab238dab1a3120ffcd0191dc552c17916c4a0627
3
+ metadata.gz: f7d0399a5fa1d89c350c262f5051f3a00910581075f61fd4a43c5ea1bc75708e
4
+ data.tar.gz: '019131a51c1f72e08726ec832702b3da3dceda032752b7601b1f8728adb5af91'
5
5
  SHA512:
6
- metadata.gz: 8aef59c1210055d2852a39a1c8100e8f63e19094e6b8708614c66339386321ff15434538e6add8e7112bfd1c6caf360e5cff62ae4c34a9d8a35d642ccf1349ad
7
- data.tar.gz: f1f5755b3f4d2751582d7dd4fc592dad5bfbf98c6e07527372bd04e6dbd52c793c390675a9d7ade419aa854d5e9e9347530828d0c8bd5c1c636d4dd87abc30d3
6
+ metadata.gz: c03f5bdc38ad4d7bd7ee475489d0697c3d933ac16e832a205dd88c92377b208c81a0d20b8799f9403d44c294c66ad36392afebc43654f98ca22dc55bac4ee459
7
+ data.tar.gz: 3ce40183b6d57dc539ae9b6084e798ba3277a98d7d1c0475e4b8c730541e99bfcbf027b7b5ba4614295eab1259a9c49eb62d375a261c12710252dfb8d51766d1
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = '>= 2.4.0'
18
+ s.required_ruby_version = '>= 2.5.0'
19
19
 
20
20
  s.add_dependency 'bfs', s.version
21
21
  s.add_dependency 'net-scp'
@@ -1,6 +1,6 @@
1
1
  require 'bfs'
2
2
  require 'net/scp'
3
- require 'cgi'
3
+ require 'net/ssh'
4
4
  require 'shellwords'
5
5
 
6
6
  module BFS
@@ -10,7 +10,7 @@ module BFS
10
10
  class CommandError < RuntimeError
11
11
  attr_reader :status
12
12
 
13
- def initialize(cmd, status, extra=nil)
13
+ def initialize(cmd, status, extra = nil)
14
14
  @status = status
15
15
  super ["Command '#{cmd}' exited with status #{status}", extra].join(': ')
16
16
  end
@@ -28,16 +28,11 @@ module BFS
28
28
  # @option opts [Integer] :keepalive_interval interval if keepalive enabled. Default: 300.
29
29
  # @option opts [Array<String>] :keys an array of file names of private keys to use for publickey and hostbased authentication.
30
30
  # @option opts [Boolean|Symbol] :verify_host_key specifying how strict host-key verification should be, either false, true, :very, or :secure.
31
- def initialize(host, opts={})
32
- opts = opts.dup
33
- opts.keys.each do |key|
34
- val = opts.delete(key)
35
- opts[key.to_sym] = val unless val.nil?
36
- end
37
- super(opts)
31
+ def initialize(host, prefix: nil, **opts)
32
+ super(**opts)
38
33
 
39
- @prefix = opts.delete(:prefix)
40
- @client = Net::SCP.start(host, nil, opts)
34
+ @prefix = prefix
35
+ @client = Net::SCP.start(host, nil, **opts.slice(*Net::SSH::VALID_OPTIONS))
41
36
 
42
37
  if @prefix # rubocop:disable Style/GuardClause
43
38
  @prefix = norm_path(@prefix) + '/'
@@ -46,7 +41,7 @@ module BFS
46
41
  end
47
42
 
48
43
  # Lists the contents of a bucket using a glob pattern
49
- def ls(pattern='**/*', _opts={})
44
+ def ls(pattern = '**/*', **_opts)
50
45
  prefix = @prefix ? abs_path(@prefix) : '/'
51
46
  Enumerator.new do |y|
52
47
  sh! 'find', prefix, '-type', 'f' do |out|
@@ -59,24 +54,27 @@ module BFS
59
54
  end
60
55
 
61
56
  # Info returns the object info
62
- def info(path, _opts={})
57
+ def info(path, **_opts)
63
58
  full = full_path(path)
64
59
  path = norm_path(path)
65
- out = sh! 'stat', '-c', '%s;%Z', full
60
+ out = sh! 'stat', '-c', '%s;%Z;%a', full
66
61
 
67
- size, epoch = out.strip.split(';', 2).map(&:to_i)
68
- BFS::FileInfo.new(path, size, Time.at(epoch))
62
+ size, epoch, mode = out.strip.split(';', 3)
63
+ BFS::FileInfo.new(path: path, size: size.to_i, mtime: Time.at(epoch.to_i), mode: BFS.norm_mode(mode))
69
64
  rescue CommandError => e
70
65
  e.status == 1 ? raise(BFS::FileNotFound, path) : raise
71
66
  end
72
67
 
73
68
  # Creates a new file and opens it for writing
74
- def create(path, opts={}, &block)
69
+ # @option opts [String|Encoding] :encoding Custom file encoding.
70
+ # @option opts [Integer] :perm Custom file permission, default: 0600.
71
+ def create(path, encoding: self.encoding, perm: self.perm, **opts, &block)
75
72
  full = full_path(path)
76
- enc = opts.delete(:encoding) || @encoding
77
- temp = BFS::TempWriter.new(path, encoding: enc) do |temp_path|
73
+
74
+ opts[:preserve] = true if perm && !opts.key?(:preserve)
75
+ temp = BFS::TempWriter.new(path, encoding: encoding, perm: perm) do |temp_path|
78
76
  mkdir_p File.dirname(full)
79
- @client.upload!(temp_path, full)
77
+ @client.upload!(temp_path, full, **opts)
80
78
  end
81
79
  return temp unless block
82
80
 
@@ -88,20 +86,19 @@ module BFS
88
86
  end
89
87
 
90
88
  # Opens an existing file for reading
91
- def open(path, opts={}, &block)
89
+ def open(path, encoding: self.encoding, tempdir: nil, **_opts, &block)
92
90
  full = full_path(path)
93
- enc = opts.delete(:encoding) || @encoding
94
- temp = Tempfile.new(File.basename(path), encoding: enc)
91
+ temp = Tempfile.new(File.basename(path), tempdir, encoding: encoding)
95
92
  temp.close
96
93
 
97
94
  @client.download!(full, temp.path)
98
- File.open(temp.path, encoding: enc, &block)
95
+ File.open(temp.path, encoding: encoding, &block)
99
96
  rescue Net::SCP::Error
100
97
  raise BFS::FileNotFound, path
101
98
  end
102
99
 
103
100
  # Deletes a file.
104
- def rm(path, _opts={})
101
+ def rm(path, **_opts)
105
102
  path = full_path(path)
106
103
  sh! 'rm', '-f', path
107
104
  end
@@ -110,7 +107,7 @@ module BFS
110
107
  #
111
108
  # @param [String] src The source path.
112
109
  # @param [String] dst The destination path.
113
- def cp(src, dst, _opts={})
110
+ def cp(src, dst, **_opts)
114
111
  full_src = full_path(src)
115
112
  full_dst = full_path(dst)
116
113
 
@@ -124,7 +121,7 @@ module BFS
124
121
  #
125
122
  # @param [String] src The source path.
126
123
  # @param [String] dst The destination path.
127
- def mv(src, dst, _opts={})
124
+ def mv(src, dst, **_opts)
128
125
  full_src = full_path(src)
129
126
  full_dst = full_path(dst)
130
127
 
@@ -186,14 +183,10 @@ module BFS
186
183
  end
187
184
  end
188
185
 
189
- BFS.register('scp', 'ssh') do |url|
190
- opts = {}
191
- CGI.parse(url.query.to_s).each do |key, values|
192
- opts[key.to_sym] = values.first
193
- end
186
+ BFS.register('scp', 'ssh') do |url, opts|
194
187
  opts[:user] ||= CGI.unescape(url.user) if url.user
195
188
  opts[:password] ||= CGI.unescape(url.password) if url.password
196
189
  opts[:port] ||= url.port if url.port
197
190
 
198
- BFS::Bucket::SCP.new url.host, opts
191
+ BFS::Bucket::SCP.new(url.host, **opts)
199
192
  end
@@ -14,14 +14,14 @@ run_spec = \
14
14
 
15
15
  RSpec.describe BFS::Bucket::SCP, if: run_spec do
16
16
  context 'absolute' do
17
- subject { described_class.new sandbox[:host], sandbox[:opts].merge(prefix: SecureRandom.uuid) }
17
+ subject { described_class.new sandbox[:host], **sandbox[:opts].merge(prefix: SecureRandom.uuid) }
18
18
  after { subject.close }
19
19
 
20
20
  it_behaves_like 'a bucket', content_type: false, metadata: false
21
21
  end
22
22
 
23
23
  context 'relative' do
24
- subject { described_class.new sandbox[:host], sandbox[:opts].merge(prefix: "~/#{SecureRandom.uuid}") }
24
+ subject { described_class.new sandbox[:host], **sandbox[:opts].merge(prefix: "~/#{SecureRandom.uuid}") }
25
25
  after { subject.close }
26
26
 
27
27
  it_behaves_like 'a bucket', content_type: false, metadata: false
@@ -45,4 +45,11 @@ RSpec.describe BFS::Bucket::SCP, if: run_spec do
45
45
  abs.close
46
46
  rel.close
47
47
  end
48
+
49
+ it 'should support custom perms' do
50
+ blob = BFS::Blob.new("scp://root:root@127.0.0.1:7022/#{SecureRandom.uuid}/file.txt")
51
+ blob.create(perm: 0o666) {|w| w.write 'foo' }
52
+ expect(blob.info.mode).to eq(0o666)
53
+ blob.close
54
+ end
48
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs-scp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bfs
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: 0.6.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: 0.6.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-scp
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -60,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.4.0
63
+ version: 2.5.0
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.0.6
70
+ rubygems_version: 3.1.2
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: SCP/SSH adapter for bfs