Class: VagrantNfs4j::Utils
- Inherits:
-
Object
- Object
- VagrantNfs4j::Utils
- Defined in:
- lib/vagrant-nfs4j/utils.rb
Class Method Summary collapse
- .apply_mount_options(mount_options, share = nil) ⇒ Object
- .get_share_alias_machine_id(share_alias) ⇒ Object
- .hostpath_to_share_alias(hostpath) ⇒ Object
- .hostpath_to_share_path(hostpath) ⇒ Object
- .prefix_alias(machine, share_alias) ⇒ Object
- .which(cmd, more_paths = []) ⇒ Object
Class Method Details
.apply_mount_options(mount_options, share = nil) ⇒ Object
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 |
# File 'lib/vagrant-nfs4j/utils.rb', line 30 def self.(, share = nil) if to_delete = [] .each_with_index do |opt, i| uid = nil uid_matches = /uid=(\d+)/.match(opt) if uid_matches uid = /uid=(\d+)/.match(opt).captures[0].to_i to_delete.push(i) end if uid and share unless share['permissions'] share['permissions'] = {} end share['permissions']['uid'] = uid end gid = nil gid_matches = /gid=(\d+)/.match(opt) if gid_matches to_delete.push(i) gid = gid_matches.captures[0].to_i end if gid and share unless share['permissions'] share['permissions'] = {} end share['permissions']['gid'] = gid end mask = nil mask_matches = /mask=(\d+)/.match(opt) if mask_matches to_delete.push(i) mask = mask_matches.captures[0].to_i end if mask and share unless share['permissions'] share['permissions'] = {} end share['permissions']['mask'] = mask end end to_delete.reverse.each do |i| .delete_at(i) end end return end |
.get_share_alias_machine_id(share_alias) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/vagrant-nfs4j/utils.rb', line 23 def self.get_share_alias_machine_id(share_alias) matches = /\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})(?:\/|\z)/.match(share_alias) if matches return matches.captures[0] end end |
.hostpath_to_share_alias(hostpath) ⇒ Object
10 11 12 13 |
# File 'lib/vagrant-nfs4j/utils.rb', line 10 def self.hostpath_to_share_alias(hostpath) path = hostpath.dup return "/#{path.gsub(':', '').gsub('\\', '/')}" end |
.hostpath_to_share_path(hostpath) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/vagrant-nfs4j/utils.rb', line 3 def self.hostpath_to_share_path(hostpath) path = hostpath.dup path.gsub!("'", "'\\\\''") path.gsub!('/', '\\') return path end |
.prefix_alias(machine, share_alias) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/vagrant-nfs4j/utils.rb', line 15 def self.prefix_alias(machine, share_alias) if share_alias.start_with? '/' return "/#{machine.id}#{share_alias}" else return "/#{machine.id}/#{share_alias}" end end |
.which(cmd, more_paths = []) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vagrant-nfs4j/utils.rb', line 85 def self.which(cmd, more_paths = []) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] exts = exts.map {|e| e.downcase} path = [more_paths, *ENV['PATH'].split(File::PATH_SEPARATOR)].flatten.map {|path| path.gsub(/\\/, '/')} path.each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end return cmd end |