Skip to content

fix: preserve sha-suffixed active version dir in tidy()#1362

Merged
jfeingold35 merged 1 commit into
oclif:mainfrom
khaled4vokalz:fix/tidy-preserve-sha-suffixed-active-dir
Jun 30, 2026
Merged

fix: preserve sha-suffixed active version dir in tidy()#1362
jfeingold35 merged 1 commit into
oclif:mainfrom
khaled4vokalz:fix/tidy-preserve-sha-suffixed-active-dir

Conversation

@khaled4vokalz

Copy link
Copy Markdown
Contributor

What

Installed CLIs live in directories named "-" (e.g. "1.2.3-abc1234"), but this.config.version is plain semver ("1.2.3"). Two guards meant to stop the running CLI from deleting itself both failed for sha-suffixed installs:

With both guards failing, once a CLI stayed on the latest version for 42+ days, tidy() deleted the directory the current symlink points to, leaving current dangling and the CLI broken.

Restore the startsWith guard in isNotSpecial and resolve the real "-" directory in touch() via a shared resolveActiveDir helper. Add regression tests covering both the tidy guard and the touch backstop for sha-suffixed installs.

fixes: #1361

Installed CLIs live in directories named "<version>-<sha>" (e.g.
"1.2.3-abc1234"), but `this.config.version` is plain semver ("1.2.3").
Two guards meant to stop the running CLI from deleting itself both
failed for sha-suffixed installs:

- `tidy()`'s `isNotSpecial` used an exact-match `includes(version)`
  check, so "1.2.3-abc1234" was never recognized as the active version
  and lost its name-based protection. The `startsWith` guard that
  originally handled this (ca57247, oclif#621) was dropped in the ESM
  refactor (oclif#643); oclif#1290 later restored only the bin/current protection
  via the arg-swap fix, not the startsWith semantics.

- `touch()` joined the bare `config.version`, producing a path that
  does not exist on disk, so it silently no-op'd and never refreshed
  the active dir's mtime.

With both guards failing, once a CLI stayed on the latest version for
42+ days, `tidy()` deleted the directory the `current` symlink points
to, leaving `current` dangling and the CLI broken.

Restore the `startsWith` guard in `isNotSpecial` and resolve the real
"<version>-<sha>" directory in `touch()` via a shared `resolveActiveDir`
helper. Add regression tests covering both the tidy guard and the touch
backstop for sha-suffixed installs.

fixes: oclif#1361
@khaled4vokalz khaled4vokalz changed the title fix: preserve sha-suffixed active version dir in tidy() (#1361) fix: preserve sha-suffixed active version dir in tidy() Jun 30, 2026
@jfeingold35 jfeingold35 merged commit 4630b19 into oclif:main Jun 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tidy() deletes the active version directory for sha-suffixed installs (<version>-<sha>), breaking the CLI

2 participants