Skip to content

Cleanup: dead code removal + assorted low-risk correctness fixes#318

Merged
MarshallOfSound merged 6 commits into
mainfrom
sam/squirrel-cleanup
May 4, 2026
Merged

Cleanup: dead code removal + assorted low-risk correctness fixes#318
MarshallOfSound merged 6 commits into
mainfrom
sam/squirrel-cleanup

Conversation

@MarshallOfSound

@MarshallOfSound MarshallOfSound commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Batch of small, independent cleanups found during a whole-repo audit. Each is an atomic commit; happy to split any out if preferred.

Commit Tests
chore: remove dead truncateLogs / backwardTruncateFilereduceEach: was never followed by flatten, so the inner signal was emitted as a value and never subscribed; the rotation has been a no-op since it landed in 2016. The helper also opened the handle write-only then called readDataToEndOfFile, so wiring it up would have thrown rather than rotated. n/a (dead code removal)
fix: handle file:// feed URLs in JSONFILE mode — the JSONFILE manifest transform sat inside if ([response isKindOfClass:NSHTTPURLResponse.class]), so a local-file feed (which the header docs explicitly mention for testing) skipped the transform and failed with SQRLUpdaterErrorInvalidJSON. Only the HTTP-status checks stay gated now. +1
fix: don't release uninitialized IOPMAssertionID on create failure — initialize to kIOPMNullAssertionID and guard the release. The out-param is documented as written on success only. none — IOPMAssertionCreateWithDescription is called directly inside a static C function with no injection point; making it fail under test would require refactoring the function signature. The fix is mechanical (init + guard).
fix: use saved errno snapshot when building rmdir NSErrorcode:errnocode:code, matching the parallel rename() error path that already does this. covered by the should report the rmdir errno… case below
fix: don't leak mkdtemp parent dir when bundle was already moveddeleteOwnedBundleAtURL: now treats ENOENT from removeItemAtURL: as success so the chained rmdir runs. Previously every successful install left one empty 0700 dir under NSTemporaryDirectory() plus a spurious "No such file" log line. +3 (-deleteOwnedBundleAtURL: happy path, already-gone path, non-empty parent reports ENOTEMPTY)
chore: remove pre-10.13 releaseDate fallback parser — the fallback used DD (day-of-year) instead of dd, but the primary ZZZZZ format already accepts every shape it covered on the current deployment target. +2 (confirms +0000 / -07:00 parse via the primary path)

@MarshallOfSound MarshallOfSound force-pushed the sam/squirrel-cleanup branch from c34af32 to db97a0e Compare May 3, 2026 21:44
@MarshallOfSound MarshallOfSound enabled auto-merge (squash) May 3, 2026 21:54
truncateLogs was wired into performHousekeeping but its reduceEach: returned
a merged signal as a value rather than flattening it, so the inner defer
block was never subscribed and the file-handle work never executed. The
helper it would have called also opened the log with fileHandleForWritingToURL:
(O_WRONLY) and then called readDataToEndOfFile, which would raise
NSFileHandleOperationException — so making the chain actually run would
have turned a no-op into a crash once a ShipIt log crossed 8 MB.

Nobody has missed this since it landed, so delete it instead of fixing it.
The JSONFILE manifest transform (extract currentRelease, walk releases,
re-serialize updateTo) lived inside the
'if ([response isKindOfClass:NSHTTPURLResponse.class])' guard. For a
file:// updateRequest NSURLConnection returns a plain NSURLResponse, so
the transform was skipped and the raw manifest was passed straight to
-updateFromJSONData:, which expects the inner {url:...} shape and fails
with SQRLUpdaterErrorInvalidJSON.

Only the RELEASESERVER status-code checks actually need an
NSHTTPURLResponse; move the read-only-volume check and the JSONFILE
manifest transform outside the guard so they run for both transports.
IOPMAssertionCreateWithDescription only writes the out-param on success;
on failure the stack uint32_t held garbage and the disposable block
unconditionally passed it to IOPMAssertionRelease.

Initialize to kIOPMNullAssertionID and skip the release when creation
failed. Not unit-testable without faking the IOKit error path.
errno was already snapshotted into 'code' immediately after rmdir() failed
and used for strerror(), but the NSError on the next line read live errno
which can be clobbered by the intervening dictionary/string allocations.
The parallel rename() error path already does this correctly.

Diagnostic-only (the error is logged then swallowed).
In the default install path installItemToURL: renames the staged
update bundle into place, after which the same staged URL is fed back
into deleteOwnedBundleAtURL: for cleanup. removeItemAtURL: failed
ENOENT, the error was logged and swallowed, and the chained then: that
rmdirs the parent mkdtemp directory never ran. Net effect: one empty
0700 mkdtemp dir under NSTemporaryDirectory() per successful install.

Treat NSFileNoSuchFileError as success so the parent rmdir still runs.
The fallback existed for 10.7-era NSDateFormatter where ZZZZZ didn't
leniently accept '+HH:MM' offsets, and it carried a 'DD' (day-of-year)
typo that would have produced wrong dates anyway.

On the current 10.13 deployment target the primary ZZZZZ format already
parses '+01:00', '-0700' and 'Z'. New tests cover those shapes
explicitly so a regression in formatter leniency would surface.
@MarshallOfSound MarshallOfSound force-pushed the sam/squirrel-cleanup branch from db97a0e to 00a7b17 Compare May 4, 2026 05:40
@MarshallOfSound MarshallOfSound disabled auto-merge May 4, 2026 05:49
@MarshallOfSound MarshallOfSound merged commit f8b4e2a into main May 4, 2026
4 of 8 checks passed
@MarshallOfSound MarshallOfSound deleted the sam/squirrel-cleanup branch May 4, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant