@boxes-dev/dvb 1.0.682 → 1.0.684

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/dvb.cjs CHANGED
@@ -3581,17 +3581,61 @@ var readProcessCommand = (pid) => {
3581
3581
  return command.length > 0 ? command : null;
3582
3582
  };
3583
3583
  var processCommandMentionsPath = (command, filePath) => command.split(/\s+/).includes(filePath);
3584
+ var processCommandLooksLikeUpdaterDaemon = (command, bootstrapPath) => {
3585
+ const parts = command.split(/\s+/).filter((part) => part.length > 0);
3586
+ if (!parts.includes("--daemon")) {
3587
+ return false;
3588
+ }
3589
+ const expectedBootstrapPath = bootstrapPath?.trim();
3590
+ if (expectedBootstrapPath) {
3591
+ return parts.includes(expectedBootstrapPath);
3592
+ }
3593
+ return parts.some((part) => {
3594
+ const baseName = import_node_path11.default.basename(part);
3595
+ return baseName === "dvb-update" || baseName === "dvb-update.cjs";
3596
+ });
3597
+ };
3584
3598
  var isReusableUpdaterDaemon = (record, expectedBootstrapPath, options = {}) => {
3585
3599
  const isProcessAliveFn = options.isProcessAliveFn ?? isProcessAlive;
3586
3600
  const readProcessCommandFn = options.readProcessCommandFn ?? readProcessCommand;
3587
3601
  if (!isProcessAliveFn(record.pid)) {
3588
3602
  return false;
3589
3603
  }
3604
+ const command = readProcessCommandFn(record.pid);
3605
+ if (!command) {
3606
+ return false;
3607
+ }
3590
3608
  if (typeof record.bootstrapPath === "string") {
3591
- return record.bootstrapPath === expectedBootstrapPath;
3609
+ return record.bootstrapPath === expectedBootstrapPath && processCommandMentionsPath(command, expectedBootstrapPath);
3610
+ }
3611
+ return processCommandMentionsPath(command, expectedBootstrapPath);
3612
+ };
3613
+ var tryTerminateProcess = (pid, signal) => {
3614
+ try {
3615
+ process.kill(pid, signal);
3616
+ } catch (error) {
3617
+ const code = error?.code;
3618
+ if (code !== "ESRCH") {
3619
+ throw error;
3620
+ }
3621
+ }
3622
+ };
3623
+ var retireStaleUpdaterDaemon = (record, options = {}) => {
3624
+ const isProcessAliveFn = options.isProcessAliveFn ?? isProcessAlive;
3625
+ const readProcessCommandFn = options.readProcessCommandFn ?? readProcessCommand;
3626
+ const killProcessFn = options.killProcessFn ?? tryTerminateProcess;
3627
+ if (!isProcessAliveFn(record.pid)) {
3628
+ return false;
3592
3629
  }
3593
3630
  const command = readProcessCommandFn(record.pid);
3594
- return command ? processCommandMentionsPath(command, expectedBootstrapPath) : false;
3631
+ if (!command) {
3632
+ return false;
3633
+ }
3634
+ if (!processCommandLooksLikeUpdaterDaemon(command, record.bootstrapPath)) {
3635
+ return false;
3636
+ }
3637
+ killProcessFn(record.pid, "SIGTERM");
3638
+ return true;
3595
3639
  };
3596
3640
  var readUpgradeSignal = async (signalPath) => {
3597
3641
  return await readJsonFileIfExists(signalPath);
@@ -3777,6 +3821,7 @@ var startBackgroundUpdater = async (homeDir = import_node_os2.default.homedir())
3777
3821
  return false;
3778
3822
  }
3779
3823
  if (existing) {
3824
+ retireStaleUpdaterDaemon(existing);
3780
3825
  (0, import_node_fs7.rmSync)(daemonPath, { force: true });
3781
3826
  }
3782
3827
  const child = (0, import_node_child_process.spawn)(process.execPath, [updaterBinPath, "--daemon"], {
@@ -3794,8 +3839,10 @@ var launchRuntime = async (kind, args) => {
3794
3839
  const startBackgroundUpdaterFn = runtimeManagerTestHooks.startBackgroundUpdater ?? startBackgroundUpdater;
3795
3840
  const runRuntimeChildFn = runtimeManagerTestHooks.runRuntimeChild ?? runRuntimeChild;
3796
3841
  let runtime = await ensureBundledRuntimeStagedFn(homeDir);
3797
- void startBackgroundUpdaterFn(homeDir).catch(() => {
3798
- });
3842
+ if (!(kind === "dvb" && args[0] === "upgrade")) {
3843
+ void startBackgroundUpdaterFn(homeDir).catch(() => {
3844
+ });
3845
+ }
3799
3846
  const signalPath = import_node_path11.default.join(
3800
3847
  await ensureUpdaterDir(homeDir),
3801
3848
  `upgrade-required-${kind}-${process.pid}-${Date.now()}.json`