bfs-scp 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bfs/bucket/scp.rb +44 -18
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4627ddec1e22cfa27903d4c4ac60cdfe70be0dd04ccb6ab7fed1c6151baac4a
4
- data.tar.gz: ee63b464044b610d84fae116446167093c6e3d643245bf5194bf965138d100fc
3
+ metadata.gz: d524b38b123694cf69ceb9b14ed758047564190ef3dba78e2eccc191970f0e89
4
+ data.tar.gz: 8e805bf4b7f688334333a5afb4fdff89c1c78fa734812e82e1d8fe3630a45ccd
5
5
  SHA512:
6
- metadata.gz: 8bd631d3af1b50eea69afcad98eeacf626462326145460572f17473666880c6c5312a53e1bf5637878ab4270d6582b4592a3214f267ae423c9b00619e11d7a74
7
- data.tar.gz: e0a7aeab8accb3266422b2a34b93946831da31852fd3d0684f84cb587a5df8af72d87e3b9fb98c3eb2445ba4cc11fe9e1bc1f6e1e74598e8759e6d8f900fa951
6
+ metadata.gz: e3956f06a9b2f00fb526f2768cb69b767372dab35adcb2b889a08bf440a1e43f462676a72927712e7e81fe1ddebf8a49687eb3b1ffe56cd8edd96c764f76e485
7
+ data.tar.gz: 424781ca80c8e6302511abc854e850db438408e54dc7af3d5eea5acf12bbc8aff99722be2f633588b271613fc8b6892f1d7ab739e1d8c8e1165a42d2c340eca8
@@ -42,14 +42,15 @@ module BFS
42
42
 
43
43
  # Lists the contents of a bucket using a glob pattern
44
44
  def ls(pattern = '**/*', **_opts)
45
- prefix = @prefix ? abs_path(@prefix) : '/'
46
- Enumerator.new do |y|
47
- sh! 'find', prefix, '-type', 'f' do |out|
48
- out.each_line do |line|
49
- path = trim_prefix(norm_path(line.strip))
50
- y << path if File.fnmatch?(pattern, path, File::FNM_PATHNAME)
51
- end
52
- end
45
+ Enumerator.new do |acc|
46
+ walk(pattern) {|path| acc << path }
47
+ end
48
+ end
49
+
50
+ # Iterates over the contents of a bucket using a glob pattern
51
+ def glob(pattern = '**/*', **_opts)
52
+ Enumerator.new do |acc|
53
+ walk(pattern, with_stat: true) {|info| acc << info }
53
54
  end
54
55
  end
55
56
 
@@ -57,9 +58,11 @@ module BFS
57
58
  def info(path, **_opts)
58
59
  full = full_path(path)
59
60
  path = norm_path(path)
60
- out = sh! 'stat', '-c', '%s;%Z;%a', full
61
+ out = sh! %(stat -c '%F;%s;%Z;%a' #{Shellwords.escape full})
62
+
63
+ type, size, epoch, mode = out.strip.split(';', 4)
64
+ raise BFS::FileNotFound, path unless type.include?('file')
61
65
 
62
- size, epoch, mode = out.strip.split(';', 3)
63
66
  BFS::FileInfo.new(path: path, size: size.to_i, mtime: Time.at(epoch.to_i), mode: BFS.norm_mode(mode))
64
67
  rescue CommandError => e
65
68
  e.status == 1 ? raise(BFS::FileNotFound, path) : raise
@@ -93,7 +96,7 @@ module BFS
93
96
  # Deletes a file.
94
97
  def rm(path, **_opts)
95
98
  path = full_path(path)
96
- sh! 'rm', '-f', path
99
+ sh! %(rm -f #{Shellwords.escape(path)})
97
100
  end
98
101
 
99
102
  # Copies src to dst
@@ -105,7 +108,7 @@ module BFS
105
108
  full_dst = full_path(dst)
106
109
 
107
110
  mkdir_p File.dirname(full_dst)
108
- sh! 'cp', '-a', '-f', full_src, full_dst
111
+ sh! %(cp -a -f #{Shellwords.escape(full_src)} #{Shellwords.escape(full_dst)})
109
112
  rescue CommandError => e
110
113
  e.status == 1 ? raise(BFS::FileNotFound, src) : raise
111
114
  end
@@ -119,7 +122,7 @@ module BFS
119
122
  full_dst = full_path(dst)
120
123
 
121
124
  mkdir_p File.dirname(full_dst)
122
- sh! 'mv', '-f', full_src, full_dst
125
+ sh! %(mv -f #{Shellwords.escape(full_src)} #{Shellwords.escape(full_dst)})
123
126
  rescue CommandError => e
124
127
  e.status == 1 ? raise(BFS::FileNotFound, src) : raise
125
128
  end
@@ -140,18 +143,41 @@ module BFS
140
143
  abs_path(super)
141
144
  end
142
145
 
146
+ def walk(pattern, with_stat: false)
147
+ prefix = @prefix ? abs_path(@prefix) : '/'
148
+ command = %(find #{Shellwords.escape(prefix)} -type f)
149
+ command << %( -exec stat -c '%s;%Z;%a;%n' {} \\;) if with_stat
150
+
151
+ sh!(command) do |out|
152
+ out.each_line do |line|
153
+ line.strip!
154
+
155
+ if with_stat
156
+ size, epoch, mode, path = out.strip.split(';', 4)
157
+ path = trim_prefix(norm_path(path))
158
+ next unless File.fnmatch?(pattern, path, File::FNM_PATHNAME)
159
+
160
+ info = BFS::FileInfo.new(path: path, size: size.to_i, mtime: Time.at(epoch.to_i), mode: BFS.norm_mode(mode))
161
+ yield info
162
+ else
163
+ path = trim_prefix(norm_path(line))
164
+ yield path if File.fnmatch?(pattern, path, File::FNM_PATHNAME)
165
+ end
166
+ end
167
+ end
168
+ end
169
+
143
170
  def mkdir_p(path)
144
- sh! 'mkdir', '-p', path
171
+ sh! %(mkdir -p #{Shellwords.escape(path)})
145
172
  end
146
173
 
147
- def sh!(*cmd) # rubocop:disable Metrics/MethodLength
174
+ def sh!(command) # rubocop:disable Metrics/MethodLength
148
175
  stdout = ''
149
176
  stderr = nil
150
177
  status = 0
151
- cmdstr = cmd.map {|x| Shellwords.escape(x) }.join(' ')
152
178
 
153
179
  @client.session.open_channel do |ch|
154
- ch.exec(cmdstr) do |_, _success|
180
+ ch.exec(command) do |_, _success|
155
181
  ch.on_data do |_, data|
156
182
  stdout << data
157
183
 
@@ -175,7 +201,7 @@ module BFS
175
201
  end
176
202
 
177
203
  @client.session.loop
178
- raise CommandError.new(cmdstr, status, stderr) unless status.zero?
204
+ raise CommandError.new(command, status, stderr) unless status.zero?
179
205
 
180
206
  stdout
181
207
  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.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-05-27 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.8.2
19
+ version: 0.8.3
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.8.2
26
+ version: 0.8.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-scp
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.1.4
70
+ rubygems_version: 3.2.15
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: SCP/SSH adapter for bfs