Skip to content

Commit

Permalink
Issue dustymabe#27 Switching to win32-process for creating sub proces…
Browse files Browse the repository at this point in the history
…ses on Windows
  • Loading branch information
Hardy Ferentschik authored and hferentschik committed Jun 20, 2016
1 parent 2a118f6 commit b9ce10c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build artifacts
pkg

# Ruby / Bundler
Gemfile.lock
.ruby-gemset
.ruby-version

# IDE config files
.idea
*.iml
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git", :ref => 'v1.8.4'
end

group :plugins do
Expand Down
37 changes: 30 additions & 7 deletions lib/vagrant-sshfs/cap/linux/sshfs_mount.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require "log4r"

require "vagrant/util/retryable"
require "tempfile"

# Only lead the gem on Windows
if Vagrant::Util::Platform.windows?
require 'win32/process'
end

module VagrantPlugins
module GuestLinux
module Cap
Expand Down Expand Up @@ -164,8 +168,31 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
# stdin <= r2 pipe2 w2 <= stdout
#
# Wire up things appropriately and start up the processes
p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => t1)
p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => t2)
if Vagrant::Util::Platform.windows?
#p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => t1, :new_pgroup => true)
#p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => t2, :new_pgroup => true)

# Need to handle Windows differently. Kernel.spawn fails to work, if the shell creating the process is closed.
# See https://github.com/dustymabe/vagrant-sshfs/issues/31
Process.create(:command_line => sftp_server_cmd,
:creation_flags => Process::DETACHED_PROCESS,
:process_inherit => false,
:thread_inherit => true,
:startup_info => {:stdin => w2, :stdout => r1, :stderr => t1})

Process.create(:command_line => ssh_cmd,
:creation_flags => Process::DETACHED_PROCESS,
:process_inherit => false,
:thread_inherit => true,
:startup_info => {:stdin => w1, :stdout => r2, :stderr => t2})
else
p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => t1, :pgroup => true)
p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => t2, :pgroup => true)

# Detach from the processes so they will keep running
Process.detach(p1)
Process.detach(p2)
end

# Check that the mount made it
mounted = false
Expand All @@ -181,10 +208,6 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
raise VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSSlaveMountFailed
end
machine.ui.info("Folder Successfully Mounted!")

# Detach from the processes so they will keep running
Process.detach(p1)
Process.detach(p2)
end

# Do a normal sshfs mount in which we will ssh into the guest
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-sshfs/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module SyncedFolderSSHFS
VERSION = "1.1.0"
VERSION = "1.1.0.dev"
end
end
2 changes: 2 additions & 0 deletions vagrant-sshfs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency 'win32-process'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
end

0 comments on commit b9ce10c

Please sign in to comment.