@@ -247,32 +247,42 @@ def mkdtemp(self, prefix=None):
247247 - prefix (str): The prefix of the temporary directory name.
248248 """
249249if prefix :
250- command = ["ssh" ] + self . ssh_args + [ self . ssh_dest , f"mktemp -d { prefix } XXXXX" ]
250+ command = ["mktemp" , "-d" , "-t" , prefix + " XXXXX" ]
251251else :
252- command = ["ssh" ] + self . ssh_args + [ self . ssh_dest ,"mktemp -d" ]
252+ command = ["mktemp" ,"-d" ]
253253
254- result = subprocess . run (command ,stdout = subprocess . PIPE , stderr = subprocess . PIPE , text = True )
254+ exit_status , result , error = self . exec_command (command ,verbose = True , encoding = get_default_encoding (), ignore_errors = True )
255255
256- if result .returncode == 0 :
257- temp_dir = result .stdout .strip ()
258- if not os .path .isabs (temp_dir ):
259- temp_dir = os .path .join ('/home' ,self .username ,temp_dir )
260- return temp_dir
261- else :
262- raise ExecUtilException (f"Could not create temporary directory. Error:{ result .stderr } " )
256+ assert type (result )== str # noqa: E721
257+ assert type (error )== str # noqa: E721
258+
259+ if exit_status != 0 :
260+ raise ExecUtilException ("Could not create temporary directory. Error code: {0}. Error message: {1}" .format (exit_status ,error ))
261+
262+ temp_dir = result .strip ()
263+ return temp_dir
263264
264265def mkstemp (self ,prefix = None ):
266+ """
267+ Creates a temporary file in the remote server.
268+ Args:
269+ - prefix (str): The prefix of the temporary directory name.
270+ """
265271if prefix :
266- temp_dir = self . exec_command ( "mktemp {}XXXXX" . format ( prefix ), encoding = get_default_encoding ())
272+ command = [ "mktemp" , "-t" , prefix + "XXXXX" ]
267273else :
268- temp_dir = self . exec_command ( "mktemp" , encoding = get_default_encoding ())
274+ command = [ "mktemp" ]
269275
270- if temp_dir :
271- if not os .path .isabs (temp_dir ):
272- temp_dir = os .path .join ('/home' ,self .username ,temp_dir .strip ())
273- return temp_dir
274- else :
275- raise ExecUtilException ("Could not create temporary directory." )
276+ exit_status ,result ,error = self .exec_command (command ,verbose = True ,encoding = get_default_encoding (),ignore_errors = True )
277+
278+ assert type (result )== str # noqa: E721
279+ assert type (error )== str # noqa: E721
280+
281+ if exit_status != 0 :
282+ raise ExecUtilException ("Could not create temporary file. Error code: {0}. Error message: {1}" .format (exit_status ,error ))
283+
284+ temp_file = result .strip ()
285+ return temp_file
276286
277287def copytree (self ,src ,dst ):
278288if not os .path .isabs (dst ):