bfs 0.6.1 → 0.6.2

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: 13963edd5c68d92d4f5ce4ef5c3f3ef0131ddb318b36f4d7114e3e49e4a16a3b
4
- data.tar.gz: b805a46a30c795dd6dc9c8761876a4af5bd73dcc117a2f7c76c8acea7a957ed9
3
+ metadata.gz: 7e9c5b7b27a3bca8975dac3ccce6d99fc3e22a012758adf5a82baceeafd12aa7
4
+ data.tar.gz: 930feef7182ef50e2106e8b48f0af0cf388b8cfa8cb39d3bf6a2dc0bb556568f
5
5
  SHA512:
6
- metadata.gz: cd9c768fed6d9efa36379f9151c4066931cc92267d032b1b0e920c7150b7db108acb739ecd46b5e8c5853b0ff090767b259e35b0d98b1707fa41491c3eb9dd9e
7
- data.tar.gz: 123205693490cd8ee1394be308f28944d84e10098dae690cd54d3bf073710d2f538d397960b19d4d0c33ec271bdbbea3df796bd086733d57f9d28db2c52e7bd6
6
+ metadata.gz: 496a92c2ac19fb0fb11a4fafbf20db067df87b678dbfea6d90fdf53e8f9088c8b1f059d87a93cd2da3de6a610f033a5ed6dec2eba0cffedad31a76a518130071
7
+ data.tar.gz: 56991e1f1088e1b361635ba17b3c235e464bd98e587db34a28e7e7d01c3b60c692b4b508646686a008e38cd731413dfd13174e87fe9b6e135317d24558fbee39
data/lib/bfs.rb CHANGED
@@ -1,7 +1,36 @@
1
1
  require 'uri'
2
2
 
3
3
  module BFS
4
- FileInfo = Struct.new(:path, :size, :mtime, :content_type, :metadata)
4
+ class FileInfo < Hash
5
+ def initialize(**attrs)
6
+ update(size: 0, mtime: Time.at(0), mode: 0, metadata: {})
7
+ update(attrs)
8
+ end
9
+
10
+ def path
11
+ fetch(:path, nil)
12
+ end
13
+
14
+ def size
15
+ fetch(:size, 0)
16
+ end
17
+
18
+ def content_type
19
+ fetch(:content_type, nil)
20
+ end
21
+
22
+ def mtime
23
+ fetch(:mtime, Time.at(0))
24
+ end
25
+
26
+ def mode
27
+ fetch(:mode, 0)
28
+ end
29
+
30
+ def metadata
31
+ fetch(:metadata, {})
32
+ end
33
+ end
5
34
 
6
35
  def self.register(*schemes, &resolver)
7
36
  @registry ||= {}
@@ -25,6 +54,11 @@ module BFS
25
54
  path.sub!(%r{/+$}, '')
26
55
  path
27
56
  end
57
+
58
+ def self.norm_mode(mode)
59
+ mode = mode.to_i(8) if mode.is_a?(String)
60
+ mode & 0o000777
61
+ end
28
62
  end
29
63
 
30
64
  require 'bfs/helpers'
@@ -6,8 +6,8 @@ module BFS
6
6
  # Initializes a new bucket
7
7
  # @param [Hash] opts options
8
8
  # @option opts [String] :encoding Custom encoding. Default: Encoding.default_external.
9
- def initialize(**opts)
10
- @encoding = opts.delete(:encoding) || Encoding.default_external
9
+ def initialize(encoding: Encoding.default_external, **_opts)
10
+ @encoding = encoding
11
11
  end
12
12
 
13
13
  # Lists the contents of a bucket using a glob pattern
data/lib/bfs/bucket/fs.rb CHANGED
@@ -26,7 +26,8 @@ module BFS
26
26
  def info(path, **_opts)
27
27
  full = @root.join(norm_path(path))
28
28
  path = trim_prefix(full.to_s)
29
- BFS::FileInfo.new(path, full.size, full.mtime, nil, {})
29
+ stat = full.stat
30
+ BFS::FileInfo.new(path: path, size: stat.size, mtime: stat.mtime, mode: BFS.norm_mode(stat.mode))
30
31
  rescue Errno::ENOENT
31
32
  raise BFS::FileNotFound, path
32
33
  end
@@ -37,13 +38,12 @@ module BFS
37
38
  # @param [Hash] opts Additional options.
38
39
  # @option opts [String] :encoding Custom encoding.
39
40
  # @option opts [Integer] :perm Custom file permission, default: 0600.
40
- def create(path, **opts, &block)
41
+ def create(path, encoding: nil, perm: nil, **_opts, &block)
41
42
  full = @root.join(norm_path(path))
42
43
  FileUtils.mkdir_p(full.dirname.to_s)
43
44
 
44
- perm = opts[:perm]
45
- enc = opts[:encoding] || @encoding
46
- temp = BFS::TempWriter.new(full, perm: perm, encoding: enc) {|t| FileUtils.mv t, full.to_s }
45
+ enc = encoding || @encoding
46
+ temp = BFS::TempWriter.new(full, encoding: enc, perm: perm) {|t| FileUtils.mv t, full.to_s }
47
47
  return temp unless block
48
48
 
49
49
  begin
@@ -32,7 +32,7 @@ module BFS
32
32
  raise BFS::FileNotFound, path unless @files.key?(path)
33
33
 
34
34
  entry = @files[path]
35
- BFS::FileInfo.new(path, entry.io.size, entry.mtime, entry.content_type, entry.metadata)
35
+ BFS::FileInfo.new(path: path, size: entry.io.size, mtime: entry.mtime, content_type: entry.content_type, metadata: entry.metadata)
36
36
  end
37
37
 
38
38
  # Creates a new file and opens it for writing.
@@ -44,9 +44,10 @@ module BFS
44
44
  # @option opts [Hash] :metadata Metadata key-value pairs.
45
45
  def create(path, **opts, &block)
46
46
  io = StringIO.new
47
- io.set_encoding(opts[:encoding] || @encoding)
47
+ io.set_encoding(opts.delete(:encoding) || @encoding)
48
48
 
49
- @files[norm_path(path)] = Entry.new(io, Time.now, opts[:content_type], norm_meta(opts[:metadata]))
49
+ entry = Entry.new(io, Time.now, opts.delete(:content_type), norm_meta(opts.delete(:metadata)))
50
+ @files[norm_path(path)] = entry
50
51
  return io unless block
51
52
 
52
53
  begin
@@ -21,7 +21,14 @@ RSpec.describe BFS::Blob do
21
21
  subject.write('TESTDATA', content_type: 'text/plain', metadata: { 'x-key' => 'val' })
22
22
 
23
23
  info = subject.info
24
- expect(info).to eq(BFS::FileInfo.new('path/to/file.txt', 8, info.mtime, 'text/plain', 'X-Key' => 'val'))
24
+ expect(info).to eq(
25
+ path: 'path/to/file.txt',
26
+ size: 8,
27
+ mtime: info.mtime,
28
+ content_type: 'text/plain',
29
+ mode: 0,
30
+ metadata: { 'X-Key' => 'val' },
31
+ )
25
32
  expect(info.mtime).to be_within(1).of(Time.now)
26
33
 
27
34
  expect(subject.read).to eq('TESTDATA')
@@ -54,7 +61,13 @@ RSpec.describe BFS::Blob do
54
61
  expect(subject.read).to eq('TESTDATA')
55
62
 
56
63
  info = subject.info
57
- expect(info).to eq(BFS::FileInfo.new(path, 8, info.mtime, nil, {}))
64
+ expect(info).to eq(
65
+ path: path,
66
+ size: 8,
67
+ mtime: info.mtime,
68
+ mode: 0o600,
69
+ metadata: {},
70
+ )
58
71
  expect(info.mtime).to be_within(1).of(Time.now)
59
72
 
60
73
  expect(Pathname.glob("#{tmpdir}/**/*").select(&:file?).map(&:to_s)).to eq [
@@ -20,7 +20,7 @@ RSpec.describe BFS::Bucket::FS do
20
20
  it 'should support custom perms' do
21
21
  blob = BFS::Blob.new("file://#{tmpdir}/test.txt")
22
22
  blob.create(perm: 0o666) {|w| w.write 'foo' }
23
- expect(File.stat(File.join(tmpdir, 'test.txt')).mode).to eq(0o100666)
23
+ expect(blob.info.mode).to eq(0o666)
24
24
  blob.close
25
25
  end
26
26
  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.6.1
4
+ version: 0.6.2
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-02-11 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Minimalist abstraction for bucket storage
14
14
  email: dimitrij@blacksquaremedia.com
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.1.2
51
+ rubygems_version: 3.0.6
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: Multi-platform cloud bucket adapter