Skip to content

Commit 96ab764

Browse files
committed
Fix CEFS extraction for root paths by standardizing on None
Change get_extraction_path_from_symlink to return None instead of Path('.') when extracting from root. This prevents the bug where temp_dir/Path('.') equals temp_dir itself, causing rmtree to fail after the directory was renamed. This standardizes the codebase on using None to indicate 'extract everything' as previously discussed.
1 parent ea4d23b commit 96ab764

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

bin/lib/cefs/paths.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,26 +217,26 @@ def parse_cefs_target(cefs_target: Path, cefs_image_dir: Path, mount_point: Path
217217
return cefs_image_path, is_already_consolidated
218218

219219

220-
def get_extraction_path_from_symlink(symlink_target: Path, mount_point: Path) -> Path:
220+
def get_extraction_path_from_symlink(symlink_target: Path, mount_point: Path) -> Path | None:
221221
"""Determine what to extract from a CEFS image based on symlink target.
222222
223-
Returns the relative path after {mount_point}/XX/HASH/ or Path(".") if at root.
223+
Returns the relative path after {mount_point}/XX/HASH/ or None if at root.
224224
225225
Args:
226226
symlink_target: The symlink target path
227227
mount_point: CEFS mount point (e.g., /cefs)
228228
229229
Examples (assuming mount_point=/cefs):
230230
/cefs/ab/abcd1234567890abcdef12/content → Path("content")
231-
/cefs/ab/abcd1234567890abcdef12 → Path(".")
231+
/cefs/ab/abcd1234567890abcdef12 → None
232232
/cefs/ab/abcd1234567890abcdef12/gcc-4.5 → Path("gcc-4.5")
233233
/cefs/ab/abcd1234567890abcdef12/libs/boost → Path("libs/boost")
234234
"""
235235
parts = symlink_target.parts
236236
mount_parts = mount_point.parts
237237
# Need at least mount_point + XX + HASH to have any relative path
238238
if len(parts) <= len(mount_parts) + 2:
239-
return Path(".")
239+
return None
240240

241241
relative_parts = parts[len(mount_parts) + 2 :]
242242
return Path(*relative_parts)

bin/test/cefs/paths_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_parse_cefs_target_variations(tmp_path):
6767
def test_get_extraction_path_from_symlink():
6868
mount_point = Path("/cefs")
6969
test_cases = [
70-
(Path("/cefs/ab/abcdef1234567890abcdef12"), Path(".")),
70+
(Path("/cefs/ab/abcdef1234567890abcdef12"), None),
7171
(Path("/cefs/ab/abcdef1234567890abcdef12/content"), Path("content")),
7272
(Path("/cefs/ab/abcdef1234567890abcdef12/gcc-4.5"), Path("gcc-4.5")),
7373
(Path("/cefs/ab/abcdef1234567890abcdef12/libs/boost"), Path("libs/boost")),
@@ -201,7 +201,7 @@ def test_get_extraction_path_with_custom_mount():
201201
custom_mount = Path("/test/cefs")
202202

203203
test_cases = [
204-
(custom_mount / "ab" / "abcd1234", Path(".")),
204+
(custom_mount / "ab" / "abcd1234", None),
205205
(custom_mount / "ab" / "abcd1234" / "content", Path("content")),
206206
(custom_mount / "ab" / "abcd1234" / "deep" / "path", Path("deep/path")),
207207
]

0 commit comments

Comments
 (0)