From dd06c62ac555b88bdca4a5b09ccf689c91567fe2 Mon Sep 17 00:00:00 2001 From: gaozengqi Date: Sat, 26 Mar 2022 14:48:08 +0800 Subject: [PATCH] Move unix_socket file to "/.vagrant.d/tmp" Moving them together also helps to implement the NFS support later. --- lib/vagrant-qemu/driver.rb | 17 +++++++++++++---- lib/vagrant-qemu/provider.rb | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-qemu/driver.rb b/lib/vagrant-qemu/driver.rb index cce30cb..485bff6 100644 --- a/lib/vagrant-qemu/driver.rb +++ b/lib/vagrant-qemu/driver.rb @@ -11,10 +11,12 @@ class Driver # @return [String] VM ID attr_reader :vm_id attr_reader :data_dir + attr_reader :tmp_dir - def initialize(id, dir) + def initialize(id, dir, tmp) @vm_id = id @data_dir = dir + @tmp_dir = tmp.join("vagrant-qemu") end def get_current_state @@ -32,6 +34,8 @@ def delete if created? id_dir = @data_dir.join(@vm_id) FileUtils.rm_rf(id_dir) + id_tmp_dir = @tmp_dir.join(@vm_id) + FileUtils.rm_rf(id_tmp_dir) end end @@ -39,9 +43,12 @@ def start(options) if !running? id_dir = @data_dir.join(@vm_id) image_path = id_dir.join("linked-box.img").to_s - unix_socket_path = id_dir.join("qemu_socket").to_s pid_file = id_dir.join("qemu.pid").to_s + id_tmp_dir = @tmp_dir.join(@vm_id) + FileUtils.mkdir_p(id_tmp_dir) + unix_socket_path = id_tmp_dir.join("qemu_socket").to_s + cmd = [] cmd += %W(qemu-system-#{options[:arch]}) @@ -81,8 +88,8 @@ def start(options) def stop if running? - id_dir = @data_dir.join(@vm_id) - unix_socket_path = id_dir.join("qemu_socket").to_s + id_tmp_dir = @tmp_dir.join(@vm_id) + unix_socket_path = id_tmp_dir.join("qemu_socket").to_s sent = false execute("nc", "-w", "5", "-U", unix_socket_path) do |type, data| case type @@ -102,6 +109,8 @@ def import(options) # Make dir id_dir = @data_dir.join(new_id) FileUtils.mkdir_p(id_dir) + id_tmp_dir = @tmp_dir.join(new_id) + FileUtils.mkdir_p(id_tmp_dir) # Prepare firmware execute("cp", options[:qemu_dir].join("edk2-aarch64-code.fd").to_s, id_dir.join("edk2-aarch64-code.fd").to_s) diff --git a/lib/vagrant-qemu/provider.rb b/lib/vagrant-qemu/provider.rb index 3a3b487..cadb942 100644 --- a/lib/vagrant-qemu/provider.rb +++ b/lib/vagrant-qemu/provider.rb @@ -29,7 +29,7 @@ def action(name) end def machine_id_changed - @driver = Driver.new(@machine.id, @machine.data_dir) + @driver = Driver.new(@machine.id, @machine.data_dir, @machine.env.tmp_path) end def ssh_info