Skip to content

adopt-project.py: a --work-dir that is a symlink leading round a loop is refused as "making it a directory failed (File exists)", which names a file in the way and not the loop #978

Closed

Description

@brettheap

Goal: plan, check and execute refuse a --work-dir that is a symlink round a loop in words that name the loop, and not "(File exists)", which reads as a file in the way.

Filed by lane openRepoShape-1 from the work on #903 (PR #963), which left L1-67's second nit of #457 alone, as its review (r903) asked for it to stay tracked. The refusal is right (exit 2, adopt-work-dir-unwritable, nothing made); the reason is the part that does not say what is wrong. Line numbers are at 9e6ed9bb, the head of #963.

The reason. _work_root (adopt-project.py:14825) makes the directory with _made_0755(root), and a failing os.mkdir becomes (:14864) "--work-dir <path> cannot be made: making it a directory failed ()". A symlink that leads to itself fails os.mkdir with EEXIST, so the reason is File exists, the words a plain file in the way gets. The person is told a file is there, and finds a link.

Measured, the same on 50178305 (v1.1.1), 11a60b71 and 9e6ed9bb. Probe setup: a stub gh first on PATH that exits 1, GH_TOKEN=bogus, an empty GH_CONFIG_DIR, GIT_CONFIG_GLOBAL=/dev/null, GIT_SSH_COMMAND=false, and a link to itself, made with ln -s <W> <W>. Then, for --source testorg/Thing and for a local source:

plan --source testorg/Thing --project Thing --org testorg --elected-by "Test Human" --elected-on 2026-09-02 --out <plan.yaml> --work-dir <W>
REFUSED adopt-work-dir-unwritable: --work-dir `<W>` cannot be made: making it a directory failed (File exists)
Remediation: Pass a --work-dir this user can write in, or none: without one, each run makes a new one.

Exit 2 for each of the four runs (base and head, org/repo and local), with no traceback. The remedy is written for a folder this user cannot write in, and says nothing of a link.

The fix:

  • Where os.mkdir fails with EEXIST and the --work-dir as typed is a symlink that does not lead to a directory (os.path.islink is true and os.path.isdir is false), the reason says so: "it is a symbolic link that leads round a loop". The code stays adopt-work-dir-unwritable, and the remedy says to remove or mend the link, besides passing another --work-dir.
  • tests/test_adopt_work_dir_refusal.py::test_a_work_dir_that_is_a_symlink_loop_is_refused (:156) builds the loop and asserts mkdir_says(work) (:109), the machine's own error, so it holds "(File exists)" as it is. It should hold the new words, for plan, check and execute; a file in the way keeps File exists, which is right for it.
  • Not in this issue: the order of plan's refusals, which is adopt-project.py plan: refusals that need only the flags come after the work directory, the source's git reads and gh repo clone #903's.

A dangling link never reaches this branch: _work_root takes os.path.realpath and makes the target (r903, measured for a link to a missing target-a and to missing-dir/target-b: both runs exited 0 and made the target).

Filed in v1.2.0 as #903's follow-up (#963); lane 3, the release owner, may place it otherwise.

Activity

  1. added this to the v1.2.0 milestone on Oct 18, 2026
  2. brettheap commented on Oct 20, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-1, session 300f8f46-004a-4e72-8587-4f192be2e108@Eagle, 2026-10-20T10:45:28Z, for #978

    Logged in lanes/log/openRepoShape-1.md at a256e5367d8dd63062c17f8872e91fa7bc08b6d1.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoShape#978:
       none
    2. `gh pr list --repo opensoft/openRepoShape --state all --search "#978"`, kept where the row or its body names `#978`:
    963	adopt-project.py: `plan` asks the leg-path, pin, date and value refusals of its flags, and an `org/repo` source's own name and derived id, before the work directory, git's reads of the source and `gh repo clone`, and says why it cannot clone into a `--work-dir` nobody can write in (#903)	fix/903-plan-flag-refusals-first	MERGED
    3. `git ls-remote --heads [email protected]:opensoft/openRepoShape` branches naming `978` as a whole token:
       none
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions