@boxes-dev/dvb 1.0.663 → 1.0.665

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
@@ -3111,6 +3111,17 @@ var readJsonFileIfExists = async (filePath) => {
3111
3111
  throw error;
3112
3112
  }
3113
3113
  };
3114
+ var readJsonFileIfExistsSync = (filePath) => {
3115
+ try {
3116
+ const raw = (0, import_node_fs7.readFileSync)(filePath, "utf8");
3117
+ return JSON.parse(raw);
3118
+ } catch (error) {
3119
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
3120
+ return null;
3121
+ }
3122
+ throw error;
3123
+ }
3124
+ };
3114
3125
  var writeJsonFileAtomic = async (filePath, value) => {
3115
3126
  const tempPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
3116
3127
  await import_promises2.default.mkdir(import_node_path11.default.dirname(filePath), { recursive: true, mode: 448 });
@@ -3254,6 +3265,15 @@ var ensureUpdaterDir = async (homeDir = import_node_os2.default.homedir()) => {
3254
3265
  }
3255
3266
  return updaterDir;
3256
3267
  };
3268
+ var ensureUpdaterDirSync = (homeDir = import_node_os2.default.homedir()) => {
3269
+ const updaterDir = resolveUpdaterDir(homeDir);
3270
+ (0, import_node_fs7.mkdirSync)(updaterDir, { recursive: true, mode: 448 });
3271
+ try {
3272
+ (0, import_node_fs7.chmodSync)(updaterDir, 448);
3273
+ } catch {
3274
+ }
3275
+ return updaterDir;
3276
+ };
3257
3277
  var trimUpdaterError = (error) => {
3258
3278
  const message = error instanceof Error ? error.message : String(error);
3259
3279
  return message.length > MAX_UPDATER_ERROR_LENGTH ? `${message.slice(0, MAX_UPDATER_ERROR_LENGTH)}...` : message;
@@ -3550,6 +3570,29 @@ var resolveBootstrapBinPath = (name) => {
3550
3570
  const basePath = resolveBasePath();
3551
3571
  return import_node_path11.default.join(import_node_path11.default.dirname(basePath), `${name}.cjs`);
3552
3572
  };
3573
+ var readProcessCommand = (pid) => {
3574
+ const ps2 = (0, import_node_child_process.spawnSync)("ps", ["-p", String(pid), "-o", "command="], {
3575
+ encoding: "utf8"
3576
+ });
3577
+ if (ps2.error || ps2.status !== 0 || typeof ps2.stdout !== "string") {
3578
+ return null;
3579
+ }
3580
+ const command = ps2.stdout.trim();
3581
+ return command.length > 0 ? command : null;
3582
+ };
3583
+ var processCommandMentionsPath = (command, filePath) => command.split(/\s+/).includes(filePath);
3584
+ var isReusableUpdaterDaemon = (record, expectedBootstrapPath, options = {}) => {
3585
+ const isProcessAliveFn = options.isProcessAliveFn ?? isProcessAlive;
3586
+ const readProcessCommandFn = options.readProcessCommandFn ?? readProcessCommand;
3587
+ if (!isProcessAliveFn(record.pid)) {
3588
+ return false;
3589
+ }
3590
+ if (typeof record.bootstrapPath === "string") {
3591
+ return record.bootstrapPath === expectedBootstrapPath;
3592
+ }
3593
+ const command = readProcessCommandFn(record.pid);
3594
+ return command ? processCommandMentionsPath(command, expectedBootstrapPath) : false;
3595
+ };
3553
3596
  var readUpgradeSignal = async (signalPath) => {
3554
3597
  return await readJsonFileIfExists(signalPath);
3555
3598
  };
@@ -3726,14 +3769,16 @@ var runUpdaterPass = async (homeDir = import_node_os2.default.homedir()) => {
3726
3769
  }
3727
3770
  };
3728
3771
  var startBackgroundUpdater = async (homeDir = import_node_os2.default.homedir()) => {
3729
- await ensureUpdaterDir(homeDir);
3730
- const existing = await readJsonFileIfExists(
3731
- resolveUpdaterDaemonPath(homeDir)
3732
- );
3733
- if (existing && isProcessAlive(existing.pid)) {
3772
+ ensureUpdaterDirSync(homeDir);
3773
+ const updaterBinPath = resolveBootstrapBinPath("dvb-update");
3774
+ const daemonPath = resolveUpdaterDaemonPath(homeDir);
3775
+ const existing = readJsonFileIfExistsSync(daemonPath);
3776
+ if (existing && isReusableUpdaterDaemon(existing, updaterBinPath)) {
3734
3777
  return false;
3735
3778
  }
3736
- const updaterBinPath = resolveBootstrapBinPath("dvb-update");
3779
+ if (existing) {
3780
+ (0, import_node_fs7.rmSync)(daemonPath, { force: true });
3781
+ }
3737
3782
  const child = (0, import_node_child_process.spawn)(process.execPath, [updaterBinPath, "--daemon"], {
3738
3783
  env: withBootstrapInstallOwnerEnv(process.env),
3739
3784
  stdio: "ignore",