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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fc095ce10f0585ef7c4ece472b54d4b6543017f47b0b49f267b0bdd199aa493
4
- data.tar.gz: e366f5a503feb6bf5843f8459823052ca939952aa3bd94288813a1ac58835bee
3
+ metadata.gz: 6bf5884a977c9d577fc09820f252807b903a8d1fbc73f32d10f111502512f789
4
+ data.tar.gz: e01f3f8c33b596ebe298921d607a180cde1d1b47331a88e2d774d3e1b7c4a04a
5
5
  SHA512:
6
- metadata.gz: 60d25fde695df0aa25eb4f3ced184a87692211b64982d33c1a9ec1bc8ca42f6eeb89a0ce343c9230a385e2ed622033982e0ce4e5ad89a1648cf6a9be2b24ab82
7
- data.tar.gz: 2539e624485bf2ddf7b171dbc981a51a5f5e4c60e378e78b5caa5c8286f1a11ae0ffb6c24246ac3b8737b6ab89a408fe81a1994cb63e20a8c4c1e5b280cccb55
6
+ metadata.gz: 9ff95022b49b9ec2bd51d8a30d14cdd07bb9c691d11fdbbe4da5b4522e405908e5f84398149725f57596b90e8c9249e855c1b11124f5f17cc6b4c7c22d6ad072
7
+ data.tar.gz: 013e221e874fa7b29c9d94589bade6d249adb3258b021872b1cdf5a18c22b607d571999d19abd66eea38069b3079cad8ecb2146f7785c48422c3ed72d1d3f1bf
@@ -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
- glob(dir) do |path|
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 glob(dir, &block)
88
- @client.ls(dir || '.') do |e|
89
- entry = Net::FTP::List.parse(e)
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
- glob subdir, &block
109
+ walk_r(subdir, &block)
93
110
  elsif entry.file?
94
- yield [dir, entry.basename].compact.join('/')
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', 'sftp') do |url, opts, block|
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) || url.scheme == 'sftp',
136
+ ssl: opts.key?(:ssl),
119
137
  }
120
138
  BFS::Bucket::FTP.open url.host, **opts, **extra, &block
121
139
  end
@@ -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: 'ftpuser', password: 'ftppass', prefix: SecureRandom.uuid } }
7
+ let(:conn_opts) { { port: 7021, username: 'user', password: 'pass', prefix: SecureRandom.uuid } }
6
8
 
7
- subject { described_class.new hostname, **conn_opts }
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 'should resolve from URL' do
15
- bucket = BFS.resolve('ftp://ftpuser:ftppass@127.0.0.1:7021')
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/ftpuser')
18
+ expect(bucket.instance_variable_get(:@client).pwd).to eq('/ftp/user')
18
19
  bucket.close
19
20
 
20
- bucket = BFS.resolve('ftp://ftpuser:ftppass@127.0.0.1:7021/a/b/')
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/ftpuser/a/b')
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.8.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: 2020-12-01 00:00:00.000000000 Z
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.8.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.8.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.1.4
70
+ rubygems_version: 3.2.15
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: FTP adapter for bfs