Skip to content

Commit 8c778cd

Browse files
committed
fix(extractor): do not use Path.readlink to check for empty targets
We cannot use Path.readlink to check if the symlink target is not set (that happens with f_badsymlinks.img on Darwin systems, you need a broken filesystem and an OS that supports it). That's because Path.readlink returns a Path object with an empty name (i.e. Path("")), which is indiscernable from a symlink target that is the current directory (i.e. Path(".")). Since there is no difference between Path("") and Path("."), we can't differentiate between a symlink with an empty target and a symlink that points at the current directory.
1 parent 162cca4 commit 8c778cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

unblob/extractor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ def fix_symlink(path: Path, outdir: Path, task_result: TaskResult) -> Path:
6565
path.unlink()
6666
return path
6767

68-
target = path.readlink()
69-
if not target.name:
68+
raw_target = os.readlink(path) # noqa: PTH115
69+
if not raw_target:
7070
logger.error("Symlink with empty target, removing.")
7171
path.unlink()
7272
return path
7373

74+
target = Path(raw_target)
7475
if target.is_absolute():
7576
target = Path(target.as_posix().lstrip("/"))
7677
else:

0 commit comments

Comments
 (0)