From a4abb8a8730c8bb293861b8c3d534c04898450e4 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Sat, 12 Nov 2016 10:47:21 -0500 Subject: [PATCH] cap: add sshfs_get_absolute_path guest capability --- .../guest/linux/sshfs_get_absolute_path.rb | 25 +++++++++++++++++++ lib/vagrant-sshfs/errors.rb | 4 +++ lib/vagrant-sshfs/plugin.rb | 5 ++++ locales/synced_folder_sshfs.yml | 2 ++ 4 files changed, 36 insertions(+) create mode 100644 lib/vagrant-sshfs/cap/guest/linux/sshfs_get_absolute_path.rb diff --git a/lib/vagrant-sshfs/cap/guest/linux/sshfs_get_absolute_path.rb b/lib/vagrant-sshfs/cap/guest/linux/sshfs_get_absolute_path.rb new file mode 100644 index 0000000..24ca144 --- /dev/null +++ b/lib/vagrant-sshfs/cap/guest/linux/sshfs_get_absolute_path.rb @@ -0,0 +1,25 @@ +module VagrantPlugins + module GuestLinux + module Cap + class SSHFSGetAbsolutePath + def self.sshfs_get_absolute_path(machine, path) + abs_path = "" + machine.communicate.execute("readlink -f #{path}") do |type, data| + if type == :stdout + abs_path = data + end + end + + if ! abs_path + # If no real absolute path was detected then error out + error_class = VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSGetAbsolutePathFailed + raise error_class, path: path + end + + # Chomp the string so that any trailing newlines are killed + return abs_path.chomp + end + end + end + end +end diff --git a/lib/vagrant-sshfs/errors.rb b/lib/vagrant-sshfs/errors.rb index e9c7964..48d4909 100644 --- a/lib/vagrant-sshfs/errors.rb +++ b/lib/vagrant-sshfs/errors.rb @@ -33,6 +33,10 @@ class SSHFSNotInstalledInGuest < SSHFSError class SSHFSExeNotAvailable < SSHFSError error_key(:exe_not_in_host) end + + class SSHFSGetAbsolutePathFailed < SSHFSError + error_key(:get_absolute_path_failed) + end end end end diff --git a/lib/vagrant-sshfs/plugin.rb b/lib/vagrant-sshfs/plugin.rb index 8a13873..3ab61ad 100644 --- a/lib/vagrant-sshfs/plugin.rb +++ b/lib/vagrant-sshfs/plugin.rb @@ -65,6 +65,11 @@ class Plugin < Vagrant.plugin("2") VagrantPlugins::GuestLinux::Cap::MountSSHFS end + guest_capability("linux", "sshfs_get_absolute_path") do + require_relative "cap/guest/linux/sshfs_get_absolute_path" + VagrantPlugins::GuestLinux::Cap::SSHFSGetAbsolutePath + end + guest_capability("redhat", "sshfs_installed") do require_relative "cap/guest/redhat/sshfs_client" VagrantPlugins::GuestRedHat::Cap::SSHFSClient diff --git a/locales/synced_folder_sshfs.yml b/locales/synced_folder_sshfs.yml index 7d6324b..0f631ba 100644 --- a/locales/synced_folder_sshfs.yml +++ b/locales/synced_folder_sshfs.yml @@ -35,6 +35,8 @@ en: try again. sshfs_not_in_guest: |- The necessary SSHFS software is not installed in the guest. + get_absolute_path_failed: |- + Could not get the absolute path of the folder within the guest '%{path}' install_failed_arch: |- The install of the sshfs client software failed. On Arch this is most likely because the package lists are not up to date [1] and partial upgrades are not