From b92168bc16d8251256ec34df938d616bca99cd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Wed, 26 Apr 2023 16:57:51 +0200 Subject: [PATCH] tools/tree-diff: don't pass file descriptor to `os.scandir()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `os.scandir()` can accept file descriptors only since Python 3.7. The tool would previously fail with exception when run using Python 3.6. The solution is to provide a path, which is done using a symlink in procfs (this is already used within the tool). Signed-off-by: Tomáš Hozza --- tools/tree-diff | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/tree-diff b/tools/tree-diff index 10c1cdb4..5fe4ae51 100755 --- a/tools/tree-diff +++ b/tools/tree-diff @@ -84,7 +84,7 @@ def symlink_diff(name, dir_fd1, dir_fd2, path, differences): # pylint: disable=too-many-branches def diff_aux(dir_fd1, dir_fd2, path, report): entries1 = set() - with os.scandir(dir_fd1) as it: + with os.scandir(f"/proc/self/fd/{dir_fd1}") as it: for dirent in it: try: stat2 = os.stat(dirent.name, dir_fd=dir_fd2, follow_symlinks=False) @@ -134,7 +134,7 @@ def diff_aux(dir_fd1, dir_fd2, path, report): diff_aux(child_fd1, child_fd2, os.path.join(path, dirent.name), report) os.close(child_fd2) os.close(child_fd1) - with os.scandir(dir_fd2) as it: + with os.scandir(f"/proc/self/fd/{dir_fd2}") as it: for dirent in it: if dirent.name not in entries1: report["added_files"] += [os.path.join(path, dirent.name)] @@ -156,7 +156,7 @@ def diff(dir_fd1, dir_fd2, report): def list_dir(dir_fd, path, target_list): - with os.scandir(dir_fd) as it: + with os.scandir(f"/proc/self/fd/{dir_fd}") as it: for dirent in it: p = os.path.join(path, dirent.name) target_list.append(p)