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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a600ba0ea981cdf7b074cdcdc0149ec8b64bf12
4
- data.tar.gz: bb072d16d43306e46684715260b6ff87459ace2a
3
+ metadata.gz: cfb96961e17f6b5f47c93c3ad6987719746b8465
4
+ data.tar.gz: 7d26d10a49ac44897d77eac3223857f20f89d8ec
5
5
  SHA512:
6
- metadata.gz: 04e6df13749d305bb7dbc05cda2a26fb1b572ae4ecf973a4ba02cfd42d67a37193068ce039f8ada47e1d320d3ab14a6d5b4057d4f2456cd3ff6223793548b69b
7
- data.tar.gz: c5ebb77b645d42f2ae01966f548a04d251c50fe22c3949c26f7bdde564d7d68356fc2135cbbb46980cf6e69fde98880267fb6e40bd012a01ed88608b6ba52125
6
+ metadata.gz: 10bd450070e40a6b8224a6453f29659b1cd76c3f1da16b686d4121e90366a52f07452cfed3fa38b8d84d21edcede0b227aca86050bc4c8ed04d590ba0729fecf
7
+ data.tar.gz: 68313a3c35ed073772900647845c43e98a79912ad4cdf653da9fe6b5e177e19245079e9eb98d1e11cc6d40e4c1653e8bd712e28a71d6dfc3632cb2e38c7612aa
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_s3_sync (0.0.1)
4
+ smart_s3_sync (0.0.2)
5
5
  fog
6
6
  sqlite3
7
7
 
@@ -10,7 +10,6 @@ module SmartS3Sync
10
10
  bucket = Fog::Storage.new(connection_options).directories.
11
11
  get(remote_dir, {:prefix => remote_prefix})
12
12
 
13
-
14
13
  # Add all files in the cloud to our map.
15
14
  bucket.files.each { |file| table.push(file) }
16
15
 
@@ -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
- Digest::MD5.file(path).hexdigest
80
+ DigestCache.digest(path)
79
81
  end
80
82
 
81
83
  def download(fog_dir)
@@ -1,3 +1,3 @@
1
1
  module SmartS3Sync
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "sqlite3"
21
22
  spec.add_dependency "fog"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
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.2
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