mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-07 06:07:32 +02:00
test: functional: drop rmtree usage and add lint check
`shutil.rmtree` is dangerous because it recursively deletes. There are not likely to be any issues with it's current uses, but it is possible that some of the assumptions being made now won't always be true, e.g. about what some of the variables being passed to `rmtree` represent. For some remaining uses of rmtree that can't be avoided for now, use `cleanup_dir` which asserts that the recursively deleted folder is a child of the the `tmpdir` of the test run. Otherwise, `tempfile.TemporaryDirectory` should be used which does it's own deleting on being garbage collected, or old fashioned unlinking and rmdir in the case of directories with known contents.
This commit is contained in:
@@ -11,7 +11,6 @@ from enum import Enum
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
@@ -20,7 +19,6 @@ import time
|
||||
import urllib.parse
|
||||
import collections
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@@ -163,8 +161,8 @@ class TestNode():
|
||||
self.args.append("-ipcbind=unix")
|
||||
else:
|
||||
# Work around default CI path exceeding maximum socket path length.
|
||||
self.ipc_tmp_dir = pathlib.Path(tempfile.mkdtemp(prefix="test-ipc-"))
|
||||
self.ipc_socket_path = self.ipc_tmp_dir / "node.sock"
|
||||
self.ipc_tmp_dir = tempfile.TemporaryDirectory(prefix="test-ipc-")
|
||||
self.ipc_socket_path = Path(self.ipc_tmp_dir.name) / "node.sock"
|
||||
self.args.append(f"-ipcbind=unix:{self.ipc_socket_path}")
|
||||
|
||||
if self.version_is_at_least(190000):
|
||||
@@ -248,9 +246,6 @@ class TestNode():
|
||||
# this destructor is called.
|
||||
print(self._node_msg("Cleaning up leftover process"), file=sys.stderr)
|
||||
self.process.kill()
|
||||
if self.ipc_tmp_dir:
|
||||
print(self._node_msg(f"Cleaning up ipc directory {str(self.ipc_tmp_dir)!r}"))
|
||||
shutil.rmtree(self.ipc_tmp_dir)
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
|
||||
|
||||
Reference in New Issue
Block a user