You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ju...@apache.org on 2026/10/16 12:42:00 UTC
(buildstream) 01/01: utils.py: Fix `_ensure_real_directory()`
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/ensure_real_directory
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 390a5705b1beb22c654cecd39a9e11882d6330b1
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 10:30:39 2026 +0200
utils.py: Fix `_ensure_real_directory()`
`os.path.split()` splits the path into a `(head, tail)` pair, not into a
list of all path segments.
Use `pathlib` to iterate over all path segments and also reject absolute
paths.
`_ensure_real_directory()` is only called from `_process_list()`,
though, where it's separately called for each level in the hierarchy.
Due to this, each path segment was already checked and thus, the
previous bug didn't cause any issues.
---
src/buildstream/utils.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 8673813dc..09cb6b2bd 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -34,7 +34,7 @@ import tempfile
import threading
import itertools
from contextlib import contextmanager
-from pathlib import Path
+from pathlib import Path, PurePath
from typing import Callable, IO, Iterable, Iterator, Optional, Tuple, Union, Pattern
from google.protobuf import timestamp_pb2
@@ -1064,7 +1064,10 @@ def _copy_directories(srcdir, destdir, target):
#
def _ensure_real_directory(root, path):
destpath = root
- for name in os.path.split(path):
+ purepath = PurePath(path)
+ if purepath.is_absolute():
+ raise UtilError(f"Expected relative path, got absolute path: {path}")
+ for name in purepath.parts:
destpath = os.path.join(destpath, name)
try:
deststat = os.lstat(destpath)