From a63156e48268acc4f049f9ef6bd5e5be10d47667 Mon Sep 17 00:00:00 2001 From: "Gustavo L. de M. Chaves" Date: Sun, 23 Mar 2014 17:16:18 -0300 Subject: [PATCH] Implement generic bucket This bucket must be explicitly enabled and may be useful for users wanting a generic caching mechanism that they can use directly instead of via some predefined packaging system. For instance, this enables one to implement a cache for packages downloaded via wget or curl. --- docs/buckets/generic.md | 41 +++++++++++++++++++++++++++ lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/bucket/generic.rb | 19 +++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 docs/buckets/generic.md create mode 100644 lib/vagrant-cachier/bucket/generic.rb diff --git a/docs/buckets/generic.md b/docs/buckets/generic.md new file mode 100644 index 0000000..c9e3f10 --- /dev/null +++ b/docs/buckets/generic.md @@ -0,0 +1,41 @@ +# Generic + +This bucket is never enabled by default. You have to enable it explicitly like +this: + +```ruby +Vagrant.configure("2") do |config| + config.cache.enable :generic, { :cache_dir => "/var/cache/some" } +end +``` + +The :cache_dir parameter is required. It specifies the directory on the guest +that will be cached under the "generic" bucket. + +You may enable more than one generic bucket by giving them different names via +the :name parameter, like this: + +```ruby +Vagrant.configure("2") do |config| + config.cache.enable :generic, { :name => "one", :cache_dir => "/var/cache/one" } + config.cache.enable :generic, { :name => "two", :cache_dir => "/var/cache/two" } +end +``` + +In this case you get two buckets called "generic-one" and "generic-two". + +The Generic bucket is useful if you want to implement a caching mechanism by +hand. For instance, if you want to cache your wget downloads under +/var/cache/wget you can do this: + +```ruby +Vagrant.configure("2") do |config| + config.cache.enable :generic, { :name => wget, :cache_dir => "/var/cache/wget" } +end +``` + +Then, you invoke wget like this: + +```sh +wget -N -P /var/cache/wget URL +``` diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index cb7adfe..74ee0c5 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -98,3 +98,4 @@ require_relative "bucket/apt_lists" require_relative "bucket/composer" require_relative "bucket/npm" require_relative "bucket/zypper" +require_relative "bucket/generic" diff --git a/lib/vagrant-cachier/bucket/generic.rb b/lib/vagrant-cachier/bucket/generic.rb new file mode 100644 index 0000000..fbc5f5a --- /dev/null +++ b/lib/vagrant-cachier/bucket/generic.rb @@ -0,0 +1,19 @@ +module VagrantPlugins + module Cachier + class Bucket + class Generic < Bucket + def self.capability + :generic_cache_dir + end + + def install + if @configs.has_key?(:cache_dir) + @name = @configs.has_key?(:name) ? "generic-#{@configs[:name]}" : "generic" + symlink(@configs[:cache_dir]) + else + @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Generic') + end + end + end + end +end