@tinycloud/operations 0.4.0-beta.13 → 0.4.0-beta.14

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.
@@ -590,7 +590,8 @@ async function acquireProfileLock(profile, options) {
590
590
  const lockPath = profileLockPath(profile);
591
591
  const turnDirectory = profileTurnLockPath(profile);
592
592
  const directory = profilePath(profile);
593
- await (0, import_promises.mkdir)(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
593
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) throw new ProfileDeletedError(profile);
594
+ if (!options.requireProfile) await (0, import_promises.mkdir)(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
594
595
  await (0, import_promises.mkdir)((0, import_node_path.dirname)(turnDirectory), { recursive: true, mode: PRIVATE_DIR_MODE });
595
596
  for (const path of [tinycloudHomePath(), profilesPath(), directory]) {
596
597
  await (0, import_promises.chmod)(path, PRIVATE_DIR_MODE).catch((error) => {
@@ -599,11 +600,15 @@ async function acquireProfileLock(profile, options) {
599
600
  }
600
601
  const { turn, firstWaitedTurn } = await acquireTurn(profile, turnDirectory, deadline);
601
602
  try {
603
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) {
604
+ await (0, import_promises.rmdir)(directory).catch(() => void 0);
605
+ throw new ProfileDeletedError(profile);
606
+ }
602
607
  const deletion = await readJson((0, import_node_path.join)(turnDirectory, "deleted.json")).catch(() => null);
603
608
  const deletedWhileWaiting = typeof deletion?.slot === "number" && deletion.slot >= firstWaitedTurn;
604
609
  while (true) {
605
610
  const token = (0, import_node_crypto.randomUUID)();
606
- if (await publishProfileLock(profile, lockPath, token)) {
611
+ if (await publishProfileLock(profile, lockPath, token, options.requireProfile === true)) {
607
612
  return {
608
613
  deletedWhileWaiting,
609
614
  turnSlot: turn.slot,
@@ -854,12 +859,13 @@ async function collectTurns(profile, turn) {
854
859
  }
855
860
  }
856
861
  }
857
- async function publishProfileLock(profile, lockPath, token) {
862
+ async function publishProfileLock(profile, lockPath, token, requireProfile) {
858
863
  try {
859
864
  await (0, import_promises.mkdir)(lockPath, { mode: PRIVATE_DIR_MODE });
860
865
  } catch (error) {
861
866
  if (isErrno(error, "EEXIST")) return false;
862
867
  if (!isErrno(error, "ENOENT")) throw error;
868
+ if (requireProfile) throw new ProfileDeletedError(profile);
863
869
  await (0, import_promises.mkdir)(profilePath(profile), { recursive: true, mode: PRIVATE_DIR_MODE });
864
870
  return false;
865
871
  }