Skip to content

Commit b0f90d9

Browse files
[RemoteOperations] A call of mktemp is fixed (#202)
When we define a template we have to use "-t" option. It forces mktemp to return a path instead name. The following methods of RemoteOperations are fixed: - mkdtemp - mkstemp
1 parent 22826e0 commit b0f90d9

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

testgres/operations/remote_ops.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -247,32 +247,42 @@ def mkdtemp(self, prefix=None):
247247
- prefix (str): The prefix of the temporary directory name.
248248
"""
249249
if prefix:
250-
command = ["ssh"] + self.ssh_args + [self.ssh_dest, f"mktemp -d {prefix}XXXXX"]
250+
command = ["mktemp", "-d", "-t", prefix + "XXXXX"]
251251
else:
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

264265
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+
"""
265271
if prefix:
266-
temp_dir = self.exec_command("mktemp {}XXXXX".format(prefix), encoding=get_default_encoding())
272+
command = ["mktemp", "-t", prefix + "XXXXX"]
267273
else:
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

277287
def copytree(self, src, dst):
278288
if not os.path.isabs(dst):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy