Skip to content

Commit 6897614

Browse files
authored
fix: is_subdir to return True when path == root (#558)
* fix: is_subdir to return True when path == root regression introduced in #480 fix #557
1 parent 3e4b6b3 commit 6897614

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

src/auditwheel/elfutils.py

-10
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@ def elf_read_rpaths(fn: Path) -> dict[str, list[str]]:
126126
return result
127127

128128

129-
def is_subdir(path: str | Path | None, directory: str | Path) -> bool:
130-
if path is None:
131-
return False
132-
133-
path = Path(path).resolve()
134-
directory = Path(directory).resolve()
135-
136-
return directory in path.parents
137-
138-
139129
def get_undefined_symbols(path: Path) -> set[str]:
140130
undef_symbols = set()
141131
with open(path, "rb") as f:

src/auditwheel/policy/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from pathlib import Path
1010
from typing import Any
1111

12-
from auditwheel.elfutils import filter_undefined_symbols, is_subdir
13-
1412
from ..architecture import Architecture
13+
from ..elfutils import filter_undefined_symbols
1514
from ..lddtree import DynamicExecutable
1615
from ..libc import Libc, get_libc
1716
from ..musllinux import find_musl_libc, get_musl_version
17+
from ..tools import is_subdir
1818

1919
_HERE = Path(__file__).parent
2020
LIBPYTHON_RE = re.compile(r"^libpython\d+\.\d+m?.so(.\d)*$")

src/auditwheel/repair.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
from auditwheel.patcher import ElfPatcher
1717

18-
from .elfutils import elf_read_dt_needed, elf_read_rpaths, is_subdir
18+
from .elfutils import elf_read_dt_needed, elf_read_rpaths
1919
from .hashfile import hashfile
2020
from .policy import WheelPolicies, get_replace_platforms
21+
from .tools import is_subdir
2122
from .wheel_abi import get_wheel_elfdata
2223
from .wheeltools import InWheelCtx, add_platforms
2324

src/auditwheel/tools.py

+10
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,13 @@ def __call__(
231231
option_string: str | None = None, # noqa: ARG002
232232
) -> None:
233233
setattr(namespace, self.dest, values)
234+
235+
236+
def is_subdir(path: str | Path | None, root: str | Path) -> bool:
237+
if path is None:
238+
return False
239+
240+
path = Path(path).resolve()
241+
root = Path(root).resolve()
242+
243+
return root == path or root in path.parents

tests/unit/test_tools.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from auditwheel.tools import EnvironmentDefault, dir2zip, zip2dir
11+
from auditwheel.tools import EnvironmentDefault, dir2zip, is_subdir, zip2dir
1212

1313

1414
@pytest.mark.parametrize(
@@ -205,3 +205,13 @@ def test_dir2zip_folders(tmp_path: Path) -> None:
205205
else:
206206
assert info.filename == "dummy-1.0.dist-info/METADATA"
207207
assert len(expected_dirs) == 0
208+
209+
210+
def test_is_subdir(tmp_path: Path) -> None:
211+
root = tmp_path / "root"
212+
subdir = root / "subdir"
213+
subdir.mkdir(parents=True)
214+
assert is_subdir(subdir, root)
215+
assert is_subdir(root, root)
216+
assert not is_subdir(None, root)
217+
assert not is_subdir(tmp_path, root)

0 commit comments

Comments
 (0)