smart_s3_sync 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/Gemfile.lock +1 -1
- data/lib/smart_s3_sync.rb +0 -1
- data/lib/smart_s3_sync/digest_cache.rb +50 -0
- data/lib/smart_s3_sync/file_target.rb +3 -1
- data/lib/smart_s3_sync/version.rb +1 -1
- data/smart_s3_sync.gemspec +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfb96961e17f6b5f47c93c3ad6987719746b8465
|
4
|
+
data.tar.gz: 7d26d10a49ac44897d77eac3223857f20f89d8ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10bd450070e40a6b8224a6453f29659b1cd76c3f1da16b686d4121e90366a52f07452cfed3fa38b8d84d21edcede0b227aca86050bc4c8ed04d590ba0729fecf
|
7
|
+
data.tar.gz: 68313a3c35ed073772900647845c43e98a79912ad4cdf653da9fe6b5e177e19245079e9eb98d1e11cc6d40e4c1653e8bd712e28a71d6dfc3632cb2e38c7612aa
|
data/Gemfile.lock
CHANGED
data/lib/smart_s3_sync.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
module SmartS3Sync
|
5
|
+
module DigestCache
|
6
|
+
class << self
|
7
|
+
def digest(filename)
|
8
|
+
if (cr = cache_record(filename)) && File.mtime(filename).to_i <= cr[0]
|
9
|
+
cr[1]
|
10
|
+
else
|
11
|
+
Digest::MD5.file(filename).hexdigest.tap do |digest|
|
12
|
+
save_record(filename, File.mtime(filename).to_i, digest)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_record(filename, mtime, digest)
|
18
|
+
database.execute("INSERT OR REPLACE INTO files (filename, mtime, digest) VALUES (?, ?, ?)", [filename, mtime, digest])
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def cache_record(filename)
|
24
|
+
crow = nil
|
25
|
+
database.execute("SELECT mtime, digest FROM files WHERE filename = ? LIMIT 1", [filename]) do |row|
|
26
|
+
crow = row
|
27
|
+
end
|
28
|
+
crow
|
29
|
+
end
|
30
|
+
|
31
|
+
def database
|
32
|
+
@database ||= SQLite3::Database.new(database_filename).tap do |db|
|
33
|
+
if db.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='files'")[0][0] < 1
|
34
|
+
db.execute %{
|
35
|
+
CREATE TABLE files (
|
36
|
+
filename TEXT PRIMARY KEY,
|
37
|
+
mtime DATETIME,
|
38
|
+
digest VARCHAR(255)
|
39
|
+
)
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def database_filename
|
46
|
+
File.expand_path('.filescache.db', '~')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'tempfile'
|
2
|
+
require 'smart_s3_sync/digest_cache'
|
2
3
|
|
3
4
|
module SmartS3Sync
|
4
5
|
class FileTarget
|
@@ -71,11 +72,12 @@ module SmartS3Sync
|
|
71
72
|
destinations.each do |dest|
|
72
73
|
FileUtils.mkdir_p(File.dirname(dest))
|
73
74
|
FileUtils.ln(source, dest, :force => true)
|
75
|
+
DigestCache.save_record(dest, File.mtime(dest).to_i, digest.to_s)
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
79
|
def file_hash(path)
|
78
|
-
|
80
|
+
DigestCache.digest(path)
|
79
81
|
end
|
80
82
|
|
81
83
|
def download(fog_dir)
|
data/smart_s3_sync.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_s3_sync
|
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
|
- Chris Rhoden
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sqlite3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: fog
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,6 +82,7 @@ files:
|
|
68
82
|
- Rakefile
|
69
83
|
- bin/s5
|
70
84
|
- lib/smart_s3_sync.rb
|
85
|
+
- lib/smart_s3_sync/digest_cache.rb
|
71
86
|
- lib/smart_s3_sync/file_table.rb
|
72
87
|
- lib/smart_s3_sync/file_target.rb
|
73
88
|
- lib/smart_s3_sync/version.rb
|