@@ -247,32 +247,42 @@ def mkdtemp(self, prefix=None):
247
247
- prefix (str): The prefix of the temporary directory name.
248
248
"""
249
249
if prefix :
250
- command = ["ssh" ] + self . ssh_args + [ self . ssh_dest , f"mktemp -d { prefix } XXXXX" ]
250
+ command = ["mktemp" , "-d" , "-t" , prefix + " XXXXX" ]
251
251
else :
252
- command = ["ssh" ] + self . ssh_args + [ self . ssh_dest , "mktemp -d" ]
252
+ command = ["mktemp" , "-d" ]
253
253
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 )
255
255
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
263
264
264
265
def 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
+ """
265
271
if prefix :
266
- temp_dir = self . exec_command ( "mktemp {}XXXXX" . format ( prefix ), encoding = get_default_encoding ())
272
+ command = [ "mktemp" , "-t" , prefix + "XXXXX" ]
267
273
else :
268
- temp_dir = self . exec_command ( "mktemp" , encoding = get_default_encoding ())
274
+ command = [ "mktemp" ]
269
275
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
276
286
277
287
def copytree (self , src , dst ):
278
288
if not os .path .isabs (dst ):
0 commit comments