From ad9f992c9ffb00a11a699b8b2e468ab454872148 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Thu, 4 Jun 2026 17:27:57 +0300 Subject: [PATCH] fix: NodeApp uses os_ops instead platform/tempfile --- src/node_app.py | 77 +++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/node_app.py b/src/node_app.py index 27334f8a..8daecb87 100644 --- a/src/node_app.py +++ b/src/node_app.py @@ -4,8 +4,6 @@ from .node import PortManager import os -import platform -import tempfile import typing @@ -16,7 +14,7 @@ class NodeApp: _test_path: str _os_ops: OsOperations - _port_manager: PortManager + _port_manager: typing.Optional[PortManager] _nodes_to_cleanup: typing.List[PostgresNode] def __init__( @@ -60,7 +58,7 @@ def os_ops(self) -> OsOperations: return self._os_ops @property - def port_manager(self) -> PortManager: + def port_manager(self) -> typing.Optional[PortManager]: assert self._port_manager is None or isinstance(self._port_manager, PortManager) return self._port_manager @@ -158,6 +156,8 @@ def make_simple( # set major version pg_version_file = self._os_ops.read(self._os_ops.build_path(node.data_dir, 'PG_VERSION')) + + # What is it ??? node.major_version_str = str(pg_version_file.rstrip()) node.major_version = float(node.major_version_str) @@ -200,7 +200,7 @@ def make_simple( # Define delayed propertyes if "unix_socket_directories" not in options.keys(): - options["unix_socket_directories"] = __class__._gettempdir_for_socket() + options["unix_socket_directories"] = self._gettempdir_for_socket() # Set config values node.set_auto_conf(options) @@ -260,49 +260,50 @@ def _paramlist_append_if_not_exist( return updated_params return __class__._paramlist_append(user_params, updated_params, param) - @staticmethod - def _gettempdir_for_socket() -> str: - platform_system_name = platform.system().lower() - - if platform_system_name == "windows": - return __class__._gettempdir() - - # - # [2025-02-17] Hot fix. - # - # Let's use hard coded path as Postgres likes. - # - # pg_config_manual.h: - # - # #ifndef WIN32 - # #define DEFAULT_PGSOCKET_DIR "/tmp" - # #else - # #define DEFAULT_PGSOCKET_DIR "" - # #endif - # - # On the altlinux-10 tempfile.gettempdir() may return - # the path to "private" temp directiry - "/temp/.private//" - # - # But Postgres want to find a socket file in "/tmp" (see above). - # + def _gettempdir_for_socket(self) -> str: + assert isinstance(self._os_ops, OsOperations) - return "/tmp" + platform_name = self._os_ops.get_platform() + + if platform_name == "linux": + # + # [2025-02-17] Hot fix. + # + # Let's use hard coded path as Postgres likes. + # + # pg_config_manual.h: + # + # #ifndef WIN32 + # #define DEFAULT_PGSOCKET_DIR "/tmp" + # #else + # #define DEFAULT_PGSOCKET_DIR "" + # #endif + # + # On the altlinux-10 tempfile.gettempdir() may return + # the path to "private" temp directiry - "/temp/.private//" + # + # But Postgres want to find a socket file in "/tmp" (see above). + # + return "/tmp" + + return self._gettempdir() + + def _gettempdir(self) -> str: + assert isinstance(self._os_ops, OsOperations) - @staticmethod - def _gettempdir() -> str: - v = tempfile.gettempdir() + v = self._os_ops.get_tempdir() # # Paranoid checks # if type(v) is str: - __class__._raise_bugcheck("tempfile.gettempdir returned a value with type {0}.".format(type(v).__name__)) + __class__._raise_bugcheck("os_ops.get_tempdir returned a value with type {0}.".format(type(v).__name__)) if v == "": - __class__._raise_bugcheck("tempfile.gettempdir returned an empty string.") + __class__._raise_bugcheck("os_ops.get_tempdir returned an empty string.") - if not os.path.exists(v): - __class__._raise_bugcheck("tempfile.gettempdir returned a not exist path [{0}].".format(v)) + if not self._os_ops.path_exists(v): + __class__._raise_bugcheck("os_ops.get_tempdir returned a not exist path [{0}].".format(v)) # OK return v