Skip to content

do_adjust_git: FileExistsError on dangling symlinks when DL_DIR path changes #122

@timblaktu

Description

@timblaktu

Summary

do_adjust_git() in meta/classes-recipe/dpkg-base.bbclass fails with
FileExistsError when DL_DIR changes between kas-container sessions,
leaving a dangling symlink at ${WORKDIR}/git.

Root Cause

Lines 30 and 33 use os.path.exists(), which follows symlinks. When the
symlink target no longer exists (dangling), os.path.exists() returns
False — even though the symlink itself still exists on disk.

This causes:

  1. Line 30: The stale symlink check (if os.path.exists(git_link) and ...)
    evaluates to False, so the dangling symlink is not removed.
  2. Line 33: The creation check (if not os.path.exists(git_link)) evaluates
    to True, so os.symlink() attempts to create a new symlink — but
    the old one still exists, raising FileExistsError.

Reproduction

  1. Run an ISAR build with DL_DIR=/path/a
  2. Change DL_DIR to /path/b (e.g., kas-container mounts change between sessions)
  3. Run the build again — do_adjust_git fails with:
    FileExistsError: [Errno 17] File exists: '/path/b/git' -> '${WORKDIR}/git'
    

Fix

Replace os.path.exists() with os.path.lexists() on both lines.
os.path.lexists() checks for the existence of the path itself (the symlink
entry) rather than following the symlink to its target.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions