From a18433710c3165f880c2a137b52d9feff1e145f7 Mon Sep 17 00:00:00 2001
From: Marco Ratto <marco.ratto@jrc.ec.europa.eu>
Date: Wed, 27 Mar 2013 16:29:50 +0100
Subject: [PATCH] 1) Fix compatibility problems with the Port field in unix
 nodes of the cluster; 2) bug fix in security checks; (cherry picked from
 commit 8cd68dc02a5e1d43f7472f56a68af1902fbbe8fa)

---
 matlab/parallel/dynareParallelRmDir.m | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/matlab/parallel/dynareParallelRmDir.m b/matlab/parallel/dynareParallelRmDir.m
index 1a84986a1..2bba6bc5c 100644
--- a/matlab/parallel/dynareParallelRmDir.m
+++ b/matlab/parallel/dynareParallelRmDir.m
@@ -36,13 +36,13 @@ if nargin ==0,
 end
 
 % security check of remote folder delete
-ok(1)=isempty(strfind(Parallel_info.RemoteTmpFolder,'..'));
-tmp1=strfind(Parallel_info.RemoteTmpFolder,'2');
+ok(1)=isempty(strfind(PRCDir,'..'));
+tmp1=strfind(PRCDir,'2');
 ok(2)=tmp1(1)==1;
-ok(3)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'-'));
-ok(4)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'h'));
-ok(5)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'m'));
-ok(6)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'s'));
+ok(3)=~isempty(strfind(PRCDir,'-'));
+ok(4)=~isempty(strfind(PRCDir,'h'));
+ok(5)=~isempty(strfind(PRCDir,'m'));
+ok(6)=~isempty(strfind(PRCDir,'s'));
 ok(7)=~isempty(PRCDir);
 
 if sum(ok)<7,
@@ -55,8 +55,13 @@ for indPC=1:length(Parallel),
         error('The remote folder path structure does not comply the security standards!'),
     end
     while (1)
-        if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)
-            [stat NonServe] = system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -fr ',Parallel(indPC).RemoteDirectory,'/',PRCDir,]);
+        if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem),
+            if ~isempty(Parallel(indPC).Port),
+                ssh_token = ['-p ',Parallel(indPC).Port];
+            else
+                ssh_token = '';
+            end
+            [stat NonServe] = system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -fr ',Parallel(indPC).RemoteDirectory,'/',PRCDir,]);
             break;
         else
             if exist('OCTAVE_VERSION'), % Patch for peculiar behaviour of rmdir under Windows.
-- 
GitLab