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
|
# File 'lib/vagrant-parallels/util/unix_mount_helpers.rb', line 16
def detect_owner_group_ids(machine, guest_path, mount_options, options)
mount_uid = find_mount_options_id("uid", mount_options)
mount_gid = find_mount_options_id("gid", mount_options)
if mount_uid.nil?
if options[:owner].to_i.to_s == options[:owner].to_s
mount_uid = options[:owner]
self.class_variable_get(:@@logger).debug("Owner user ID (provided): #{mount_uid}")
else
output = {stdout: '', stderr: ''}
uid_command = "id -u #{options[:owner]}"
machine.communicate.execute(uid_command,
error_class: Errors::ParallelsMountFailed,
error_key: :parallels_mount_failed,
command: uid_command,
output: output[:stderr]
) { |type, data| output[type] << data if output[type] }
mount_uid = output[:stdout].chomp
self.class_variable_get(:@@logger).debug("Owner user ID (lookup): #{options[:owner]} -> #{mount_uid}")
end
else
machine.ui.warn "Detected mount owner ID within mount options. (uid: #{mount_uid} guestpath: #{guest_path})"
end
if mount_gid.nil?
if options[:group].to_i.to_s == options[:group].to_s
mount_gid = options[:group]
self.class_variable_get(:@@logger).debug("Owner group ID (provided): #{mount_gid}")
else
begin
output = {stdout: '', stderr: ''}
gid_command = "getent group #{options[:group]}"
machine.communicate.execute(gid_command,
error_class: Errors::ParallelsMountFailed,
error_key: :parallels_mount_failed,
command: gid_command,
output: output[:stderr]
) { |type, data| output[type] << data if output[type] }
mount_gid = output[:stdout].split(':').at(2).to_s.chomp
self.class_variable_get(:@@logger).debug("Owner group ID (lookup): #{options[:group]} -> #{mount_gid}")
rescue Vagrant::Errors::ParallelsMountFailed
if options[:owner] == options[:group]
self.class_variable_get(:@@logger).debug("Failed to locate group `#{options[:group]}`. Group name matches owner. Fetching effective group ID.")
output = {stdout: ''}
result = machine.communicate.execute("id -g #{options[:owner]}",
error_check: false
) { |type, data| output[type] << data if output[type] }
mount_gid = output[:stdout].chomp if result == 0
self.class_variable_get(:@@logger).debug("Owner group ID (effective): #{mount_gid}")
end
raise unless mount_gid
end
end
else
machine.ui.warn "Detected mount group ID within mount options. (gid: #{mount_gid} guestpath: #{guest_path})"
end
{:gid => mount_gid, :uid => mount_uid}
end
|