bincache 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/bin/bincache CHANGED
@@ -6,7 +6,7 @@
6
6
  # bincache dir script1 script2 ... scriptn
7
7
 
8
8
  ## dev env
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
9
+ $LOAD_PATH.unshift(File.join('..','lib'))
10
10
 
11
11
  require 'rubygems'
12
12
  require 'bincache'
data/bincache.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bincache}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Martin Rhoads"]
data/lib/bincache.rb CHANGED
@@ -7,7 +7,8 @@ require 'right_aws'
7
7
  class BinCache
8
8
 
9
9
  def initialize()
10
- @download_dir = '/tmp'
10
+ ## set cache_dir to'/var/tmp/bincache' or ENV['BINCACHE_DIR'] if it is set
11
+ @cache_dir = (ENV['BINCACHE_DIR'] && ENV['BINCACHE_DIR']) || '/var/tmp/bincache'
11
12
 
12
13
  print_and_exit "s3 keys not set. Please set S3_BUCKET and S3_PREFIX" unless ENV['S3_BUCKET'] && ENV['S3_PREFIX']
13
14
  @bucket = ENV['S3_BUCKET']
@@ -28,7 +29,7 @@ class BinCache
28
29
  `rm -rf #{directory} && mkdir -p #{directory}` && return if scripts.empty?
29
30
 
30
31
  ## hash the scripts
31
- hash = Digest::MD5.hexdigest(scripts.inspect)
32
+ hash = Digest::MD5.hexdigest("#{directory.inspect}#{scripts.inspect}")
32
33
 
33
34
  ## pop the last script
34
35
  pop = scripts.pop
@@ -41,6 +42,9 @@ class BinCache
41
42
  end
42
43
 
43
44
  def check_for_hash?(hash)
45
+ ## return true if the hash is already on our local fs
46
+ return true if File.exists?(File.join(@cache_dir,hash))
47
+
44
48
  key = RightAws::S3::Key.create( @right_s3_bucket, "#{@prefix}#{hash}" )
45
49
  key.exists?
46
50
  end
@@ -48,13 +52,13 @@ class BinCache
48
52
  def step(script,directory,hash)
49
53
  if download_hash? hash
50
54
  `rm -rf #{directory}`
51
- `cd #{File.dirname directory} && tar -xzvf #{File.join(@download_dir,hash)} `
55
+ `cd #{File.dirname directory} && tar -xzvf #{File.join(@cache_dir,hash)} `
52
56
  else
53
- `mkdir -p #{directory}`
57
+ `mkdir -p #{directory} #{@cache_dir}`
54
58
  Dir.chdir directory
55
59
  res = `#{script}`
56
- `cd #{File.dirname directory} && tar -czvf #{@download_dir}/#{hash} #{File.basename directory} `
57
- upload_file("#{@download_dir}/#{hash}")
60
+ `cd #{File.dirname directory} && tar -czvf #{@cache_dir}/#{hash} #{File.basename directory} `
61
+ upload_file("#{@cache_dir}/#{hash}")
58
62
  end
59
63
  end
60
64
 
@@ -69,8 +73,12 @@ class BinCache
69
73
  end
70
74
 
71
75
  def download_hash?(hash)
76
+ ## return true if the hash is already on our local fs
77
+ return true if File.exists?(File.join(@cache_dir,hash))
78
+
79
+ ## attempt to download the hash from s3
72
80
  begin
73
- File.open(File.join(@download_dir,hash) , 'w') {|f| f.write( @right_s3_interface.get_object(@bucket, "#{@prefix}#{hash}") ) }
81
+ File.open(File.join(@cache_dir,hash) , 'w') {|f| f.write( @right_s3_interface.get_object(@bucket, "#{@prefix}#{hash}") ) }
74
82
  rescue
75
83
  return false
76
84
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bincache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Martin Rhoads