Content-Length: 3434 | pFad | http://github.com/postgrespro/testgres/pull/202.patch
thub.com
From 619fefa9432f023b48c0399ff7533f3f32965864 Mon Sep 17 00:00:00 2001
From: "d.kovalenko"
Date: Fri, 28 Feb 2025 20:05:08 +0300
Subject: [PATCH] [RemoteOperations] A call of mktemp is fixed
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
---
testgres/operations/remote_ops.py | 46 +++++++++++++++++++------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py
index 51f5b2e8..2a4e5c78 100644
--- a/testgres/operations/remote_ops.py
+++ b/testgres/operations/remote_ops.py
@@ -247,32 +247,42 @@ def mkdtemp(self, prefix=None):
- prefix (str): The prefix of the temporary directory name.
"""
if prefix:
- command = ["ssh"] + self.ssh_args + [self.ssh_dest, f"mktemp -d {prefix}XXXXX"]
+ command = ["mktemp", "-d", "-t", prefix + "XXXXX"]
else:
- command = ["ssh"] + self.ssh_args + [self.ssh_dest, "mktemp -d"]
+ command = ["mktemp", "-d"]
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+ exit_status, result, error = self.exec_command(command, verbose=True, encoding=get_default_encoding(), ignore_errors=True)
- if result.returncode == 0:
- temp_dir = result.stdout.strip()
- if not os.path.isabs(temp_dir):
- temp_dir = os.path.join('/home', self.username, temp_dir)
- return temp_dir
- else:
- raise ExecUtilException(f"Could not create temporary directory. Error: {result.stderr}")
+ assert type(result) == str # noqa: E721
+ assert type(error) == str # noqa: E721
+
+ if exit_status != 0:
+ raise ExecUtilException("Could not create temporary directory. Error code: {0}. Error message: {1}".format(exit_status, error))
+
+ temp_dir = result.strip()
+ return temp_dir
def mkstemp(self, prefix=None):
+ """
+ Creates a temporary file in the remote server.
+ Args:
+ - prefix (str): The prefix of the temporary directory name.
+ """
if prefix:
- temp_dir = self.exec_command("mktemp {}XXXXX".format(prefix), encoding=get_default_encoding())
+ command = ["mktemp", "-t", prefix + "XXXXX"]
else:
- temp_dir = self.exec_command("mktemp", encoding=get_default_encoding())
+ command = ["mktemp"]
- if temp_dir:
- if not os.path.isabs(temp_dir):
- temp_dir = os.path.join('/home', self.username, temp_dir.strip())
- return temp_dir
- else:
- raise ExecUtilException("Could not create temporary directory.")
+ exit_status, result, error = self.exec_command(command, verbose=True, encoding=get_default_encoding(), ignore_errors=True)
+
+ assert type(result) == str # noqa: E721
+ assert type(error) == str # noqa: E721
+
+ if exit_status != 0:
+ raise ExecUtilException("Could not create temporary file. Error code: {0}. Error message: {1}".format(exit_status, error))
+
+ temp_file = result.strip()
+ return temp_file
def copytree(self, src, dst):
if not os.path.isabs(dst):
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/postgrespro/testgres/pull/202.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy