s3repo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/s3repo.rb +0 -2
- data/lib/s3repo/cache.rb +22 -34
- data/lib/s3repo/repo.rb +21 -13
- data/s3repo.gemspec +2 -1
- metadata +16 -4
- data/lib/s3repo/metadata.rb +0 -9
- data/lib/s3repo/package.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0641c73158e5144c4a988efb266b2fa57b2cde5d
|
4
|
+
data.tar.gz: 5ef0a969a378659cbc9f2aeb5f16b1a962890fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 047abc0e5e6448278c265082985f14d7a7da59026720658f42899ecd5547b2f9be88770ea5091e35ce6bb97ba66488ac9b516c09d7290066d198f52c9db433a4
|
7
|
+
data.tar.gz: e6272c8574e44c6c830d87ba15718c70c0c10f0ba619d3e5ee2855c61f3830122514a2514cd933ffbf0fe86ea0f7ce5a28b35c655a5381782d3e0bc45e5a69a3
|
data/lib/s3repo.rb
CHANGED
data/lib/s3repo/cache.rb
CHANGED
@@ -12,51 +12,39 @@ module S3Repo
|
|
12
12
|
[partialdir, cachedir].each { |x| FileUtils.mkdir_p x }
|
13
13
|
end
|
14
14
|
|
15
|
-
def serve(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def serve(key, refresh = true)
|
16
|
+
path = expand_path key
|
17
|
+
download(key, path) if refresh || !cached?(path)
|
18
|
+
File.open(path) { |fh| fh.read }
|
19
|
+
rescue Aws::S3::Errors::NoSuchKey
|
20
|
+
nil
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
def expand_path(
|
25
|
-
File.absolute_path(
|
25
|
+
def expand_path(key)
|
26
|
+
File.absolute_path(key, cachedir)
|
26
27
|
end
|
27
28
|
|
28
|
-
def cached?(
|
29
|
-
File.exist?
|
29
|
+
def cached?(path)
|
30
|
+
File.exist? path
|
30
31
|
end
|
31
32
|
|
32
|
-
def download(
|
33
|
-
FileUtils.mkdir_p File.dirname(
|
34
|
-
tmpfile
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def safe_download(path)
|
41
|
-
tmpfile = Tempfile.create(path.split('/').last, partialdir)
|
42
|
-
object = client.get_object(key: path)
|
43
|
-
tmpfile << object.body.read
|
33
|
+
def download(key, path)
|
34
|
+
FileUtils.mkdir_p File.dirname(path)
|
35
|
+
tmpfile = Tempfile.create(key, partialdir)
|
36
|
+
object = client.get_object(
|
37
|
+
key: key, if_none_match: etags[key], response_target: tmpfile
|
38
|
+
)
|
44
39
|
tmpfile.close
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
tag = object.etag.gsub('"', '')
|
50
|
-
return tag if tag.match(/^\h+$/)
|
51
|
-
fail('Invalid etag')
|
40
|
+
File.rename tmpfile.path, path
|
41
|
+
etags[key] = object.etag
|
42
|
+
rescue Aws::S3::Errors::NotModified
|
43
|
+
return
|
52
44
|
end
|
53
45
|
|
54
|
-
def
|
55
|
-
|
56
|
-
current = File.readlink(epath).split('-').last
|
57
|
-
new = parse_etag client.head_object(key: path)
|
58
|
-
return if new == current
|
59
|
-
[epath, File.readlink(epath)].each { |x| File.unlink x }
|
46
|
+
def etags
|
47
|
+
@etags ||= {}
|
60
48
|
end
|
61
49
|
|
62
50
|
def cachedir
|
data/lib/s3repo/repo.rb
CHANGED
@@ -1,30 +1,38 @@
|
|
1
|
+
require 'basiccache'
|
2
|
+
|
1
3
|
module S3Repo
|
2
4
|
##
|
3
5
|
# Repo object, represents an Arch repo inside an S3 bucket
|
4
6
|
class Repo < Base
|
7
|
+
def initialize(params = {})
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
5
11
|
def add_package(file)
|
6
12
|
upload!(file)
|
7
|
-
package = Package.new(client: client, key: file)
|
8
|
-
metadata.add_package(package)
|
9
|
-
package
|
10
13
|
end
|
11
14
|
|
12
15
|
def packages
|
13
|
-
|
16
|
+
meta_cache.cache { parse_packages }
|
14
17
|
end
|
15
18
|
|
16
|
-
def
|
17
|
-
|
19
|
+
def include?(key)
|
20
|
+
!packages.find { |x| x.key == key }.nil?
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
|
23
|
+
def serve(key)
|
24
|
+
refresh = !key.match(/\.pkg\.tar\.xz$/)
|
25
|
+
file_cache.serve(key, refresh)
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
25
29
|
|
26
|
-
def
|
27
|
-
@
|
30
|
+
def file_cache
|
31
|
+
@file_cache ||= Cache.new(client: client, tmpdir: @options[:tmpdir])
|
32
|
+
end
|
33
|
+
|
34
|
+
def meta_cache
|
35
|
+
@meta_cache ||= BasicCache::TimeCache.new lifetime: 600
|
28
36
|
end
|
29
37
|
|
30
38
|
def upload!(file)
|
@@ -36,9 +44,9 @@ module S3Repo
|
|
36
44
|
end
|
37
45
|
|
38
46
|
def parse_packages
|
39
|
-
|
40
|
-
|
41
|
-
|
47
|
+
client.list_objects(bucket: bucket).contents.select do |x|
|
48
|
+
x.key.match(/.*\.pkg\.tar\.xz$/)
|
49
|
+
end
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
data/s3repo.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 's3repo'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.3'
|
4
4
|
s.date = Time.now.strftime('%Y-%m-%d')
|
5
5
|
|
6
6
|
s.summary = 'S3 Archlinux repo library'
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_dependency 'mercenary', '~> 0.3.4'
|
18
18
|
s.add_dependency 'aws-sdk', '~> 2.0.0'
|
19
|
+
s.add_dependency 'basiccache', '~> 1.0.0'
|
19
20
|
|
20
21
|
s.add_development_dependency 'rubocop', '~> 0.28.0'
|
21
22
|
s.add_development_dependency 'rake', '~> 10.4.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3repo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercenary
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: basiccache
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,8 +142,6 @@ files:
|
|
128
142
|
- lib/s3repo/base.rb
|
129
143
|
- lib/s3repo/cache.rb
|
130
144
|
- lib/s3repo/client.rb
|
131
|
-
- lib/s3repo/metadata.rb
|
132
|
-
- lib/s3repo/package.rb
|
133
145
|
- lib/s3repo/repo.rb
|
134
146
|
- s3repo.gemspec
|
135
147
|
- spec/s3repo_spec.rb
|
data/lib/s3repo/metadata.rb
DELETED
data/lib/s3repo/package.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module S3Repo
|
2
|
-
##
|
3
|
-
# Package object, represents a single package tarball
|
4
|
-
class Package < Base
|
5
|
-
private
|
6
|
-
|
7
|
-
def info
|
8
|
-
lines = `tar xOf #{@options[:file]} .PKGINFO`.split("\n")
|
9
|
-
lines.reject! { |x| x.match(/^#/) }
|
10
|
-
lines.map { |x| x.split(' = ', 2) }.to_h
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|