bfs 0.8.2 → 0.8.3

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: 32e754ffdd81a72cc648eb786fc2ca34839c0debe67b80e2ee6256766c8194e4
4
- data.tar.gz: 443d181595af99d3b00be21809965d68e2373439435bfefbca35df168bdc1962
3
+ metadata.gz: 03b755b393438097fae39868308111fa84eab83caab2fd514098acc068f62feb
4
+ data.tar.gz: 1d35f8bc21448e828d13ee0e47b6c04ed156ebb9e4b1cd3273125ab16774945c
5
5
  SHA512:
6
- metadata.gz: 13cd555372996a1a2050229f57eae18c32215dc0303e83ccbc866ed4e6b3e5d1c8079a827520ed39871c39152cf96a01532bc254ad2f1a9e996cf6a32b5c24c9
7
- data.tar.gz: 8ac28da9c0c664810e5665299f1cd97609dba0c789fc42244e9494a95a8587ef799ecee64c38eec40a301c2e1d131bcb98aad89d0ee4d43ab4f66a2db14203c7
6
+ metadata.gz: a95cfcb805b0f91b3dba7113abab08d5792030cd111e8772a94824baee0fe10d9b932d50e5d6f8e17575b1f224ceea43e46e556029bd7e0a70f610794c277b25
7
+ data.tar.gz: 947eea2d6c8482718cb6e33b04038b8e8c23ae9f5b0e43e0af4e6a401adf19d6c1bf8a5784b92c659ac8d589845195c9fe3e51f5e7d3ce278ffe49fdf6693cfd
@@ -40,6 +40,11 @@ module BFS
40
40
  raise 'not implemented'
41
41
  end
42
42
 
43
+ # Iterates over the contents of a bucket using a glob pattern
44
+ def glob(_pattern = '**', **_opts)
45
+ raise 'not implemented'
46
+ end
47
+
43
48
  # Info returns the info for a single file
44
49
  def info(_path, **_opts)
45
50
  raise 'not implemented'
data/lib/bfs/bucket/fs.rb CHANGED
@@ -15,19 +15,30 @@ module BFS
15
15
 
16
16
  # Lists the contents of a bucket using a glob pattern
17
17
  def ls(pattern = '**/*', **_opts)
18
- Enumerator.new do |y|
19
- Pathname.glob(@root.join(pattern)) do |pname|
20
- y << trim_prefix(pname.to_s) if pname.file?
18
+ Enumerator.new do |acc|
19
+ walk(pattern) do |path, _|
20
+ acc << path
21
+ end
22
+ end
23
+ end
24
+
25
+ # Iterates over the contents of a bucket using a glob pattern
26
+ def glob(pattern = '**/*', **_opts)
27
+ Enumerator.new do |acc|
28
+ walk(pattern) do |path, stat|
29
+ acc << file_info(path, stat)
21
30
  end
22
31
  end
23
32
  end
24
33
 
25
34
  # Info returns the info for a single file
26
35
  def info(path, **_opts)
27
- full = @root.join(norm_path(path))
28
- path = trim_prefix(full.to_s)
29
- stat = full.stat
30
- BFS::FileInfo.new(path: path, size: stat.size, mtime: stat.mtime, mode: BFS.norm_mode(stat.mode))
36
+ norm = norm_path(path)
37
+ pn = @root.join(norm)
38
+ stat = pn.stat
39
+ raise BFS::FileNotFound, path unless stat.file?
40
+
41
+ file_info(norm, stat)
31
42
  rescue Errno::ENOENT
32
43
  raise BFS::FileNotFound, path
33
44
  end
@@ -93,6 +104,19 @@ module BFS
93
104
  rescue Errno::ENOENT
94
105
  raise BFS::FileNotFound, norm_path(src)
95
106
  end
107
+
108
+ private
109
+
110
+ def walk(pattern)
111
+ Pathname.glob(@root.join(pattern)) do |pn|
112
+ stat = pn.stat
113
+ yield(trim_prefix(pn.to_s), stat) if stat.file?
114
+ end
115
+ end
116
+
117
+ def file_info(path, stat)
118
+ BFS::FileInfo.new(path: path, size: stat.size, mtime: stat.mtime, mode: BFS.norm_mode(stat.mode))
119
+ end
96
120
  end
97
121
  end
98
122
  end
@@ -36,8 +36,17 @@ module BFS
36
36
  # Lists the contents of a bucket using a glob pattern
37
37
  def ls(pattern = '**/*', **_opts)
38
38
  Enumerator.new do |y|
39
- @files.each_key do |key|
40
- y << key if File.fnmatch?(pattern, key, File::FNM_PATHNAME)
39
+ @files.each_key do |path|
40
+ y << path if File.fnmatch?(pattern, path, File::FNM_PATHNAME)
41
+ end
42
+ end
43
+ end
44
+
45
+ # Iterates over the contents of a bucket using a glob pattern
46
+ def glob(pattern = '**/*', **_opts)
47
+ Enumerator.new do |y|
48
+ @files.each_key do |path|
49
+ y << file_info(path) if File.fnmatch?(pattern, path, File::FNM_PATHNAME)
41
50
  end
42
51
  end
43
52
  end
@@ -47,8 +56,7 @@ module BFS
47
56
  path = norm_path(path)
48
57
  raise BFS::FileNotFound, path unless @files.key?(path)
49
58
 
50
- entry = @files[path]
51
- BFS::FileInfo.new(path: path, size: entry.io.size, mtime: entry.mtime, content_type: entry.content_type, metadata: entry.metadata)
59
+ file_info(path)
52
60
  end
53
61
 
54
62
  # Creates a new file and opens it for writing.
@@ -84,6 +92,13 @@ module BFS
84
92
  def rm(path, **_opts)
85
93
  @files.delete(norm_path(path))
86
94
  end
95
+
96
+ private
97
+
98
+ def file_info(path)
99
+ entry = @files[path]
100
+ BFS::FileInfo.new path: path, size: entry.io.size, mtime: entry.mtime, content_type: entry.content_type, metadata: entry.metadata
101
+ end
87
102
  end
88
103
  end
89
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs
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
  description: Minimalist abstraction for bucket storage
14
14
  email: dimitrij@blacksquaremedia.com
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.1.4
54
+ rubygems_version: 3.2.15
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: Multi-platform cloud bucket adapter