From 2015aa6e74ff75dbe94c47f985c61da83b3e68f5 Mon Sep 17 00:00:00 2001 From: jakedev99 <6440039+jake-dev-99@users.noreply.github.com> Date: Thu, 9 Jul 2026 17:56:46 -0400 Subject: [PATCH] rc.2: two post-#26 review fixes on current main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rebased release/v1.0.0-rc.2 onto current main (028d710, incl. Dependabot's esbuild 0.25→0.28 bump from #28). The prior branch carried ~30 commits whose content already landed on main via the #26 squash (c055cc0), so a literal replay would conflict against its own merged twins. Collapsed to the genuine net delta over current main: - lib/entrypoint_cli.dart: unawaited(_logSubscription?.cancel()) + relocate `// ignore: cancel_subscriptions` to the .listen() site (Copilot/CodeRabbit feedback). - native/shim/embed_bundle.py: buffer + atomic os.replace() write so a read failure can't truncate bundle_data.c. Both files byte-identical to the reviewed rc.2 versions; esbuild stays at main's 0.28.1 (Dependabot bump preserved, not reverted). Co-Authored-By: Claude Opus 4.8 --- lib/entrypoint_cli.dart | 13 +++++++++---- native/shim/embed_bundle.py | 31 +++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/entrypoint_cli.dart b/lib/entrypoint_cli.dart index f7975f9..b11b844 100644 --- a/lib/entrypoint_cli.dart +++ b/lib/entrypoint_cli.dart @@ -140,7 +140,15 @@ For more details: https://github.com/jake-dev-99/quicktype_dart /// previous subscription before attaching a new one. static void _installLogForwarder() { Logger.root.level = Level.INFO; - _logSubscription?.cancel(); + // Fire-and-forget: cancel() stops delivering records synchronously; + // the Future it returns just signals completion of any async cleanup, + // which doesn't block attaching the next listener. + unawaited(_logSubscription?.cancel()); + // Subscription lives for the process lifetime (CLI is a short-lived + // binary); test re-entries cancel it via the unawaited() above. + // cancel_subscriptions fires on the .listen() site, not the field, + // so the ignore belongs here. + // ignore: cancel_subscriptions _logSubscription = Logger.root.onRecord.listen((record) { // Process stdout/stderr are owned by the runtime; never close them. if (record.level >= Level.WARNING) { @@ -151,8 +159,5 @@ For more details: https://github.com/jake-dev-99/quicktype_dart }); } - // ignore: cancel_subscriptions - // Subscription lives for the process lifetime; cancellation happens - // on re-entry (tests) via _installLogForwarder above. static StreamSubscription? _logSubscription; } diff --git a/native/shim/embed_bundle.py b/native/shim/embed_bundle.py index 974a0da..4c63478 100644 --- a/native/shim/embed_bundle.py +++ b/native/shim/embed_bundle.py @@ -14,6 +14,8 @@ const unsigned char qt_bundle_js[] — bundle bytes + trailing NUL const unsigned long qt_bundle_js_len — bundle length """ +import io +import os import sys # Characters that must not appear raw inside a C string literal. @@ -74,18 +76,35 @@ def main(): print(__doc__, file=sys.stderr) sys.exit(1) prelude, bundle, out_path = sys.argv[1:] + + # Buffer everything into memory first so a read failure on `prelude` + # or `bundle` (or a disk-full during emit) doesn't truncate the + # existing out_path. The atomic rename at the end guarantees + # consumers either see the complete old file or the complete new + # file — never a half-written one. + buf = io.BytesIO() + buf.write(b'// Auto-generated by embed_bundle.py \xe2\x80\x94 do not edit.\n\n') + emit(prelude, 'qt_prelude_js', buf) + emit(bundle, 'qt_bundle_js', buf) + + tmp_path = f'{out_path}.tmp-{os.getpid()}' try: - out = open(out_path, 'wb') + with open(tmp_path, 'wb') as tmp: + tmp.write(buf.getvalue()) + tmp.flush() + os.fsync(tmp.fileno()) + os.replace(tmp_path, out_path) except OSError as e: print( - f'embed_bundle.py: cannot open output {out_path} for writing: {e}', + f'embed_bundle.py: cannot write output {out_path}: {e}', file=sys.stderr, ) + if os.path.exists(tmp_path): + try: + os.unlink(tmp_path) + except OSError: + pass sys.exit(2) - with out: - out.write(b'// Auto-generated by embed_bundle.py \xe2\x80\x94 do not edit.\n\n') - emit(prelude, 'qt_prelude_js', out) - emit(bundle, 'qt_bundle_js', out) if __name__ == '__main__':