bfs-scp 0.8.2 → 0.8.3
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 +4 -4
- data/lib/bfs/bucket/scp.rb +44 -18
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d524b38b123694cf69ceb9b14ed758047564190ef3dba78e2eccc191970f0e89
|
4
|
+
data.tar.gz: 8e805bf4b7f688334333a5afb4fdff89c1c78fa734812e82e1d8fe3630a45ccd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3956f06a9b2f00fb526f2768cb69b767372dab35adcb2b889a08bf440a1e43f462676a72927712e7e81fe1ddebf8a49687eb3b1ffe56cd8edd96c764f76e485
|
7
|
+
data.tar.gz: 424781ca80c8e6302511abc854e850db438408e54dc7af3d5eea5acf12bbc8aff99722be2f633588b271613fc8b6892f1d7ab739e1d8c8e1165a42d2c340eca8
|
data/lib/bfs/bucket/scp.rb
CHANGED
@@ -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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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!
|
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!
|
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!
|
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!
|
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!
|
171
|
+
sh! %(mkdir -p #{Shellwords.escape(path)})
|
145
172
|
end
|
146
173
|
|
147
|
-
def sh!(
|
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(
|
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(
|
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.
|
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-
|
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.
|
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.
|
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.
|
70
|
+
rubygems_version: 3.2.15
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: SCP/SSH adapter for bfs
|