Class: VagrantWinNFSd::Cap::NFS

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-winnfsd/cap/nfs.rb

Class Method Summary collapse

Class Method Details

.nfs_export(env, machine, ips, folders) ⇒ Object



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
# File 'lib/vagrant-winnfsd/cap/nfs.rb', line 14

def self.nfs_export(env, machine, ips, folders)
  machine.ui.info I18n.t('vagrant_winnfsd.hosts.windows.nfs_export')
  sleep 0.5

  self.nfs_cleanup(machine.id)
  nfs_file_lines = []

  nfs_file_lines.push("# VAGRANT-BEGIN: #{Process.uid} #{machine.id}")
  folders.each do |k, opts|
    hostpath = opts[:hostpath].dup
    hostpath.gsub!("'", "'\\\\''")
    hostpath.gsub('/', '\\')
    nfs_file_lines.push("#{hostpath}")
  end
  nfs_file_lines.push("# VAGRANT-END: #{Process.uid} #{machine.id}")

  File.open(@nfs_path_file, 'a') do |f|
    f.puts(nfs_file_lines)
  end

  unless self.nfs_running?
    gid = machine.config.winnfsd.gid
    uid = machine.config.winnfsd.uid
    logging = machine.config.winnfsd.logging
    system("#{@nfs_start_command} #{logging} \"#{@nfs_path_file}\" #{uid} #{gid}")
    sleep 2
  end
end

.nfs_installed(environment) ⇒ Object



71
72
73
# File 'lib/vagrant-winnfsd/cap/nfs.rb', line 71

def self.nfs_installed(environment)
  true
end

.nfs_prune(environment, ui, valid_ids) ⇒ Object



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
# File 'lib/vagrant-winnfsd/cap/nfs.rb', line 43

def self.nfs_prune(environment, ui, valid_ids)
  return unless File.exist?(@nfs_path_file)

  @logger.info('Pruning invalid NFS entries...')

  output = false
  user = Process.uid

  File.read(@nfs_path_file).lines.each do |line|
    id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2]

    if id
      if valid_ids.include?(id)
        @logger.debug("Valid ID: #{id}")
      else
        unless output
          # We want to warn the user but we only want to output once
          ui.info I18n.t('vagrant_winnfsd.hosts.windows.nfs_prune')
          output = true
        end

        @logger.info("Invalid ID, pruning: #{id}")
        self.nfs_cleanup(id)
      end
    end
  end
end