From db405c2146e69c7be77804530289265715cbc99c Mon Sep 17 00:00:00 2001
From: Jaume Devesa <jaumedevesa@gmail.com>
Date: Sat, 5 Jan 2013 10:13:11 +0100
Subject: [PATCH] Set the Absolute path based on the user's HOME

If the name of the script does not start with the root path ('/') it
attaches the current HOME directory to the script name to run a script
that is not in the classpath.
---
 libcloud/compute/ssh.py |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git libcloud/compute/ssh.py libcloud/compute/ssh.py
index c1a0521..36a9bc4 100644
--- libcloud/compute/ssh.py
+++ libcloud/compute/ssh.py
@@ -29,6 +29,7 @@ except ImportError:
 # Ref: https://bugs.launchpad.net/paramiko/+bug/392973
 
 from os.path import split as psplit
+from os.path import join as pjoin
 
 
 class BaseSSHClient(object):
@@ -179,6 +180,17 @@ class ParamikoSSHClient(BaseSSHClient):
         sftp.close()
 
     def run(self, cmd):
+        if cmd[0] != '/':
+            # If 'cmd' baed on relative path,
+            # set the absoute path joining the HOME path
+            sftp = self.client.open_sftp()
+            # Chdir to its own directory is mandatory because otherwise
+            # the 'getcwd()' method returns None
+            sftp.chdir(".")
+            cwd = sftp.getcwd()
+            sftp.close()
+            # Join the command to the current path
+            cmd = pjoin(cwd, cmd)
         # based on exec_command()
         bufsize = -1
         t = self.client.get_transport()
-- 
1.7.2.5

