-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
mounter.rb
107 lines (85 loc) · 2.86 KB
/
mounter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true
module VagrantBindfs
module Vagrant
module Actions
class Mounter # :nodoc:
attr_reader :app,
:env,
:hook
include Concerns::Machine
include Concerns::Log
def initialize(app, env, hook)
@app = app
@env = env
@hook = hook
end
def call(env)
app.call(env)
return if bound_folders(hook).empty?
bind_folders!
end
protected
def bind_folders!
info I18n.t('vagrant-bindfs.actions.mounter.start', hook: hook)
bound_folders(hook).each_value do |folder|
bind_folder!(folder)
end
end
def bind_folder!(folder)
folder.reverse_merge!(config.default_options)
folder.to_version!(bindfs_version)
return unless valid_folder?(folder)
machine.communicate.tap do |comm|
empty_mountpoint!(comm, folder) if empty_mountpoint?(folder)
ensure_mountpoint_exists!(comm, folder)
execute_bind_command!(comm, folder)
end
end
def valid_folder?(folder)
validator = VagrantBindfs::Bindfs::Validators::Runtime.new(folder, machine)
return true if validator.valid?
error I18n.t(
'vagrant-bindfs.validations.errors_found',
dest: folder.destination,
source: folder.source,
errors: validator.errors.join(' ')
)
false
end
def empty_mountpoint?(folder)
return false unless config.force_empty_mountpoints
return false if folder.options.key?('o') && folder.options['o'].include?('nonempty')
true
end
def empty_mountpoint!(comm, folder)
detail I18n.t(
'vagrant-bindfs.actions.mounter.force_empty_mountpoints',
dest: folder.destination
)
comm.sudo("rm -rf #{folder.destination}")
end
def ensure_mountpoint_exists!(comm, folder)
comm.sudo("mkdir -p #{folder.destination}")
end
def execute_bind_command!(comm, folder)
detail I18n.t(
'vagrant-bindfs.actions.mounter.entry',
dest: folder.destination,
source: folder.source
)
command = VagrantBindfs::Bindfs::Command.new(folder)
comm.sudo(command.to_s(bindfs_full_path),
error_class: VagrantBindfs::Vagrant::Error,
error_key: 'bindfs.mount_failed')
debug(command.to_s(bindfs_full_path))
end
def bindfs_version
@bindfs_version ||= guest.capability(:bindfs_bindfs_version)
end
def bindfs_full_path
@bindfs_full_path ||= guest.capability(:bindfs_bindfs_full_path)
end
end
end
end
end