From 1fbdcb1af787ef4a105e9a52e57ead5626ada98c Mon Sep 17 00:00:00 2001 From: Zdenek Zambersky Date: Mar 28 2022 20:36:59 +0000 Subject: Added cygwin guest support --- diff --git a/0001-Add-support-for-cygwin.patch b/0001-Add-support-for-cygwin.patch new file mode 100644 index 0000000..c237c21 --- /dev/null +++ b/0001-Add-support-for-cygwin.patch @@ -0,0 +1,200 @@ +From c448668a05bbee2dcca746efd326ba00e7bf5ddc Mon Sep 17 00:00:00 2001 +From: Zdenek Zambersky +Date: Wed, 25 Sep 2019 16:14:18 +0200 +Subject: [PATCH] Add support for cygwin + +--- + .../cap/guest/cygwin/sshfs_client.rb | 11 +++++ + .../cap/guest/cygwin/sshfs_forward_mount.rb | 45 +++++++++++++++++++ + .../cap/guest/linux/sshfs_forward_mount.rb | 32 ++++++++++--- + lib/vagrant-sshfs/plugin.rb | 26 +++++++++++ + 4 files changed, 109 insertions(+), 5 deletions(-) + create mode 100644 lib/vagrant-sshfs/cap/guest/cygwin/sshfs_client.rb + create mode 100644 lib/vagrant-sshfs/cap/guest/cygwin/sshfs_forward_mount.rb + +diff --git a/lib/vagrant-sshfs/cap/guest/cygwin/sshfs_client.rb b/lib/vagrant-sshfs/cap/guest/cygwin/sshfs_client.rb +new file mode 100644 +index 0000000..302198e +--- /dev/null ++++ b/lib/vagrant-sshfs/cap/guest/cygwin/sshfs_client.rb +@@ -0,0 +1,11 @@ ++module VagrantPlugins ++ module GuestCygwin ++ module Cap ++ class SSHFSClient ++ def self.sshfs_installed(machine) ++ machine.communicate.test("type sshfs") ++ end ++ end ++ end ++ end ++end +diff --git a/lib/vagrant-sshfs/cap/guest/cygwin/sshfs_forward_mount.rb b/lib/vagrant-sshfs/cap/guest/cygwin/sshfs_forward_mount.rb +new file mode 100644 +index 0000000..464d908 +--- /dev/null ++++ b/lib/vagrant-sshfs/cap/guest/cygwin/sshfs_forward_mount.rb +@@ -0,0 +1,45 @@ ++require_relative "../linux/sshfs_forward_mount" ++ ++module VagrantPlugins ++ module GuestCygwin ++ module Cap ++ class MountSSHFS < VagrantPlugins::GuestLinux::Cap::MountSSHFS ++ ++ def self.is_cygwin(machine, opts) ++ return true ++ end ++ ++ def self.sshfs_forward_get_umount_cmd(expanded_guest_path) ++ # sshfs-win mount is not seen as mount by cygwin, ++ # so we cannot unmount it using umount, ++ # we need to kill sshfs process ( which causes umount ) ++ ++ cmd = 'sh -c "' ++ # iterate over cmdlines of all cygwin processes ++ cmd += 'for cmdline in /proc/*/cmdline ; do' ++ # if command starts with sshfs ++ cmd += ' if strings -n 1 \\"\\${cmdline}\\" | head -n 1 | grep -q \'^sshfs\\$\'' ++ # and contains #{expanded_guest_path} ++ cmd += " && strings -n 1 \\\"\\${cmdline}\\\" | grep -q '^#{expanded_guest_path}\\$' ;" ++ cmd += ' then' ++ # get pid from proc path ++ cmd += ' pid=\\"\\$( basename \\"\\$( dirname \\"\\${cmdline}\\" )\\" )\\" ;' ++ cmd += ' printf \'Syncing cached writes ...\\\\n\' ;' ++ # synchronize casched writes to filesystems (just in case) ++ cmd += ' sync ;' ++ cmd += ' printf \'Killing sshfs process: %s ...\\\\n\' \\"\\${pid}\\" ;' ++ # kill sshfs process ++ cmd += ' kill \\"\\${pid}\\" ;' ++ # break the loop ++ cmd += ' break ;' ++ cmd += ' fi' ++ cmd += ' done' ++ cmd += '"' ++ ++ return cmd ++ end ++ ++ end ++ end ++ end ++end +diff --git a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb +index 83ee384..4f15ec9 100644 +--- a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb ++++ b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb +@@ -21,6 +21,10 @@ module VagrantPlugins + "cat /proc/mounts" + end + ++ def self.is_cygwin(machine, opts) ++ return false ++ end ++ + def self.sshfs_forward_is_folder_mounted(machine, opts) + mounted = false + guest_path = opts[:guestpath] +@@ -29,6 +33,11 @@ module VagrantPlugins + # can safely say it is not mounted + exists = machine.communicate.test("test -e #{guest_path}", sudo: true) + return false unless exists ++ # If path exists in cygwin it is considered mounted ++ # ( see comments for creating mountpoint lower ) ++ if self.is_cygwin(machine, opts) ++ return true ++ end + + # find the absolute path so that we can properly check if it is mounted + # https://github.com/dustymabe/vagrant-sshfs/issues/44 +@@ -66,9 +75,13 @@ module VagrantPlugins + :shell_expand_guest_path, opts[:guestpath]) + + # Create the mountpoint inside the guest +- machine.communicate.tap do |comm| +- comm.sudo("mkdir -p #{expanded_guest_path}") +- comm.sudo("chmod 777 #{expanded_guest_path}") ++ # for sshfs-win/cygwin to work, directory must NOT exist in place ++ # of future mount (unlike for sshfs/linux) ++ unless self.is_cygwin(machine, opts) ++ machine.communicate.tap do |comm| ++ comm.sudo("mkdir -p #{expanded_guest_path}") ++ comm.sudo("chmod 777 #{expanded_guest_path}") ++ end + end + + # Mount path information: if arbitrary host mounting then +@@ -98,6 +111,10 @@ module VagrantPlugins + end + end + ++ def self.sshfs_forward_get_umount_cmd(expanded_guest_path) ++ return "umount #{expanded_guest_path}" ++ end ++ + def self.sshfs_forward_unmount_folder(machine, opts) + # opts contains something like: + # { :type=>:sshfs, +@@ -120,7 +137,7 @@ module VagrantPlugins + + # Build up the command and connect + error_class = VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSUnmountFailed +- cmd = "umount #{expanded_guest_path}" ++ cmd = self.sshfs_forward_get_umount_cmd(expanded_guest_path) + machine.communicate.sudo( + cmd, error_class: error_class, error_key: :unmount_failed) + end +@@ -210,7 +227,12 @@ module VagrantPlugins + + # The remote sshfs command that will run (in slave mode) + sshfs_opts+= ' -o slave ' +- sshfs_cmd = "sudo -E sshfs :#{hostpath} #{expanded_guest_path}" ++ if self.is_cygwin(machine, opts) ++ # cygwin does not support -E option ++ sshfs_cmd = "sudo sshfs :#{hostpath} #{expanded_guest_path}" ++ else ++ sshfs_cmd = "sudo -E sshfs :#{hostpath} #{expanded_guest_path}" ++ end + sshfs_cmd+= sshfs_opts + ' ' + sshfs_opts_append + ' ' + + # The ssh command to connect to guest and then launch sshfs +diff --git a/lib/vagrant-sshfs/plugin.rb b/lib/vagrant-sshfs/plugin.rb +index e8590ce..eefbf8a 100644 +--- a/lib/vagrant-sshfs/plugin.rb ++++ b/lib/vagrant-sshfs/plugin.rb +@@ -166,6 +166,32 @@ module VagrantPlugins + require_relative "cap/guest/freebsd/sshfs_client" + VagrantPlugins::GuestFreeBSD::Cap::SSHFSClient + end ++ ++ guest_capability("cygwin", "sshfs_forward_mount_folder") do ++ require_relative "cap/guest/cygwin/sshfs_forward_mount" ++ VagrantPlugins::GuestCygwin::Cap::MountSSHFS ++ end ++ ++ guest_capability("cygwin", "sshfs_forward_unmount_folder") do ++ require_relative "cap/guest/cygwin/sshfs_forward_mount" ++ VagrantPlugins::GuestCygwin::Cap::MountSSHFS ++ end ++ ++ guest_capability("cygwin", "sshfs_forward_is_folder_mounted") do ++ require_relative "cap/guest/cygwin/sshfs_forward_mount" ++ VagrantPlugins::GuestCygwin::Cap::MountSSHFS ++ end ++ ++ guest_capability("cygwin", "sshfs_get_absolute_path") do ++ require_relative "cap/guest/linux/sshfs_get_absolute_path" ++ VagrantPlugins::GuestLinux::Cap::SSHFSGetAbsolutePath ++ end ++ ++ guest_capability("cygwin", "sshfs_installed") do ++ require_relative "cap/guest/cygwin/sshfs_client" ++ VagrantPlugins::GuestCygwin::Cap::SSHFSClient ++ end ++ + end + end + end +-- +2.20.1 + diff --git a/vagrant-sshfs.spec b/vagrant-sshfs.spec index c7598be..546c2e4 100644 --- a/vagrant-sshfs.spec +++ b/vagrant-sshfs.spec @@ -3,11 +3,12 @@ Name: %{vagrant_plugin_name} Version: 1.3.6 -Release: 3%{?dist} +Release: 999.zz%{?dist} Summary: A Vagrant synced folder plugin that mounts folders via SSHFS License: GPLv2 URL: https://github.com/dustymabe/vagrant-sshfs Source0: https://rubygems.org/gems/%{vagrant_plugin_name}-%{version}.gem +Patch0: 0001-Add-support-for-cygwin.patch Requires: vagrant >= 1.9.1 BuildRequires: ruby(release) @@ -33,7 +34,9 @@ Documentation for %{name}. %prep %setup -b 0 -q -n %{vagrant_plugin_name}-%{version} - +pushd .. +%patch0 -p1 +popd # remove dependencies on windows libraries (needed for windows, not linux) %gemspec_remove_dep -s ../%{vagrant_plugin_name}-%{version}.gemspec -g win32-process @@ -69,6 +72,9 @@ cp -a .%{vagrant_plugin_dir}/* \ %{vagrant_plugin_instdir}/vagrant-sshfs.gemspec %changelog +* Mon Mar 28 2022 Fedora Release Engineering - 1.3.6-999.zz +- Cygwin guest support + * Sat Jan 22 2022 Fedora Release Engineering - 1.3.6-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild