bfs-ftp 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bfs/bucket/ftp.rb +29 -11
- data/spec/bfs/bucket/ftp_spec.rb +9 -8
- 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: 6bf5884a977c9d577fc09820f252807b903a8d1fbc73f32d10f111502512f789
|
4
|
+
data.tar.gz: e01f3f8c33b596ebe298921d607a180cde1d1b47331a88e2d774d3e1b7c4a04a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff95022b49b9ec2bd51d8a30d14cdd07bb9c691d11fdbbe4da5b4522e405908e5f84398149725f57596b90e8c9249e855c1b11124f5f17cc6b4c7c22d6ad072
|
7
|
+
data.tar.gz: 013e221e874fa7b29c9d94589bade6d249adb3258b021872b1cdf5a18c22b607d571999d19abd66eea38069b3079cad8ecb2146f7785c48422c3ed72d1d3f1bf
|
data/lib/bfs/bucket/ftp.rb
CHANGED
@@ -31,16 +31,22 @@ module BFS
|
|
31
31
|
|
32
32
|
# Lists the contents of a bucket using a glob pattern
|
33
33
|
def ls(pattern = '**/*', **_opts)
|
34
|
-
dir = pattern[%r{^[^*?\{\}\[\]]+/}]
|
35
|
-
dir&.chomp!('/')
|
36
|
-
|
37
34
|
Enumerator.new do |y|
|
38
|
-
|
35
|
+
walk(pattern) do |path, _|
|
39
36
|
y << path if File.fnmatch?(pattern, path, File::FNM_PATHNAME)
|
40
37
|
end
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
41
|
+
# Iterates over the contents of a bucket using a glob pattern
|
42
|
+
def glob(pattern = '**/*', **_opts)
|
43
|
+
Enumerator.new do |y|
|
44
|
+
walk(pattern) do |path, entry|
|
45
|
+
y << file_info(path, entry) if File.fnmatch?(pattern, path, File::FNM_PATHNAME)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
44
50
|
# Info returns the object info
|
45
51
|
def info(path, **_opts)
|
46
52
|
path = norm_path(path)
|
@@ -84,14 +90,26 @@ module BFS
|
|
84
90
|
|
85
91
|
private
|
86
92
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
93
|
+
def file_info(path, entry)
|
94
|
+
BFS::FileInfo.new(path: path, size: entry.filesize, mtime: entry.mtime)
|
95
|
+
end
|
96
|
+
|
97
|
+
def walk(pattern, &block)
|
98
|
+
dir = pattern[%r{^[^*?\{\}\[\]]+/}]
|
99
|
+
dir&.chomp!('/')
|
100
|
+
walk_r(dir, &block)
|
101
|
+
end
|
102
|
+
|
103
|
+
def walk_r(dir, &block)
|
104
|
+
entries = @client.list(dir || '.')
|
105
|
+
entries.each do |ent|
|
106
|
+
entry = Net::FTP::List.parse(ent)
|
90
107
|
if entry.dir?
|
91
108
|
subdir = [dir, entry.basename].compact.join('/')
|
92
|
-
|
109
|
+
walk_r(subdir, &block)
|
93
110
|
elsif entry.file?
|
94
|
-
|
111
|
+
path = [dir, entry.basename].compact.join('/')
|
112
|
+
yield(path, entry)
|
95
113
|
end
|
96
114
|
end
|
97
115
|
end
|
@@ -107,7 +125,7 @@ module BFS
|
|
107
125
|
end
|
108
126
|
end
|
109
127
|
|
110
|
-
BFS.register('ftp'
|
128
|
+
BFS.register('ftp') do |url, opts, block|
|
111
129
|
prefix = BFS.norm_path(opts[:prefix] || url.path)
|
112
130
|
opts[:prefix] = prefix unless prefix.empty?
|
113
131
|
|
@@ -115,7 +133,7 @@ BFS.register('ftp', 'sftp') do |url, opts, block|
|
|
115
133
|
username: url.user ? CGI.unescape(url.user) : nil,
|
116
134
|
password: url.password ? CGI.unescape(url.password) : nil,
|
117
135
|
port: url.port,
|
118
|
-
ssl: opts.key?(:ssl)
|
136
|
+
ssl: opts.key?(:ssl),
|
119
137
|
}
|
120
138
|
BFS::Bucket::FTP.open url.host, **opts, **extra, &block
|
121
139
|
end
|
data/spec/bfs/bucket/ftp_spec.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe BFS::Bucket::FTP, ftp: true do
|
4
|
+
subject { described_class.new hostname, **conn_opts }
|
5
|
+
|
4
6
|
let(:hostname) { '127.0.0.1' }
|
5
|
-
let(:conn_opts) { { port: 7021, username: '
|
7
|
+
let(:conn_opts) { { port: 7021, username: 'user', password: 'pass', prefix: SecureRandom.uuid } }
|
6
8
|
|
7
|
-
|
8
|
-
after { subject.close }
|
9
|
+
after { subject.close }
|
9
10
|
|
10
11
|
it_behaves_like 'a bucket',
|
11
12
|
content_type: false,
|
12
13
|
metadata: false
|
13
14
|
|
14
|
-
it '
|
15
|
-
bucket = BFS.resolve('ftp://
|
15
|
+
it 'resolves from URL' do
|
16
|
+
bucket = BFS.resolve('ftp://user:pass@127.0.0.1:7021')
|
16
17
|
expect(bucket).to be_instance_of(described_class)
|
17
|
-
expect(bucket.instance_variable_get(:@client).pwd).to eq('/ftp/
|
18
|
+
expect(bucket.instance_variable_get(:@client).pwd).to eq('/ftp/user')
|
18
19
|
bucket.close
|
19
20
|
|
20
|
-
bucket = BFS.resolve('ftp://
|
21
|
+
bucket = BFS.resolve('ftp://user:pass@127.0.0.1:7021/a/b/')
|
21
22
|
expect(bucket).to be_instance_of(described_class)
|
22
|
-
expect(bucket.instance_variable_get(:@client).pwd).to eq('/ftp/
|
23
|
+
expect(bucket.instance_variable_get(:@client).pwd).to eq('/ftp/user/a/b')
|
23
24
|
bucket.close
|
24
25
|
end
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bfs-ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-29 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.
|
19
|
+
version: 0.9.0
|
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.
|
26
|
+
version: 0.9.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: net-ftp-list
|
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: FTP adapter for bfs
|