Class: VagrantPlugins::Cachier::Action::InstallBuckets

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-cachier/action/install_buckets.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env, opts = {}) ⇒ InstallBuckets

Returns a new instance of InstallBuckets.



7
8
9
10
11
# File 'lib/vagrant-cachier/action/install_buckets.rb', line 7

def initialize(app, env, opts = {})
  @app    = app
  @logger = Log4r::Logger.new("vagrant::cachier::action::clean")
  @opts   = opts
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/vagrant-cachier/action/install_buckets.rb', line 13

def call(env)
  @app.call(env)

  return unless env[:machine].config.cache.enabled?

  chmod_bucket_root(env[:machine]) if @opts[:chmod]
  configure_cache_buckets(env)
end

#chmod_bucket_root(machine) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-cachier/action/install_buckets.rb', line 22

def chmod_bucket_root(machine)
  machine.communicate.sudo 'mkdir -p /tmp/vagrant-cache'

  # https://github.com/fgrehm/vagrant-cachier/issues/107
  if ! smb_synced_folder_enabled?(machine)
    @logger.info "'chmod'ing bucket root dir to 777..."
    machine.communicate.sudo 'chmod 777 /tmp/vagrant-cache'
  end
end

#configure_cache_buckets(env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant-cachier/action/install_buckets.rb', line 32

def configure_cache_buckets(env)
  if env[:machine].config.cache.auto_detect
    Bucket.auto_detect(env)
  end

  return unless env[:machine].config.cache.buckets.any?

  env[:ui].info 'Configuring cache buckets...'
  cache_config = env[:machine].config.cache
  cache_config.buckets.each do |bucket_name, configs|
    @logger.info "Installing #{bucket_name} with configs #{configs.inspect}"
    Bucket.install(bucket_name, env, configs)
  end

  data_file = env[:machine].data_dir.join('cache_dirs')
  data_file.open('w') { |f| f.print env[:cache_dirs].uniq.join("\n") }
end

#smb_synced_folder_enabled?(machine) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagrant-cachier/action/install_buckets.rb', line 50

def smb_synced_folder_enabled?(machine)
  synced_folder_opts = machine.config.cache.synced_folder_opts
  synced_folder_opts ||= {}

  # If smb was explicitly enabled
  if synced_folder_opts[:type] && synced_folder_opts[:type].to_s == 'smb'
    return true
  elsif machine.provider_name.to_sym == :hyperv
    # If the provider in use is hyperv, the default synced folder is 'smb'
    # unless specified
    return synced_folder_opts[:type] == nil
  end
end