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

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.
@@ -721,7 +721,8 @@ async function acquireProfileLock(profile, options) {
721
721
  const lockPath = profileLockPath(profile);
722
722
  const turnDirectory = profileTurnLockPath(profile);
723
723
  const directory = profilePath(profile);
724
- await (0, import_promises.mkdir)(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
724
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) throw new ProfileDeletedError(profile);
725
+ if (!options.requireProfile) await (0, import_promises.mkdir)(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
725
726
  await (0, import_promises.mkdir)((0, import_node_path.dirname)(turnDirectory), { recursive: true, mode: PRIVATE_DIR_MODE });
726
727
  for (const path of [tinycloudHomePath(), profilesPath(), directory]) {
727
728
  await (0, import_promises.chmod)(path, PRIVATE_DIR_MODE).catch((error) => {
@@ -730,11 +731,15 @@ async function acquireProfileLock(profile, options) {
730
731
  }
731
732
  const { turn, firstWaitedTurn } = await acquireTurn(profile, turnDirectory, deadline);
732
733
  try {
734
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) {
735
+ await (0, import_promises.rmdir)(directory).catch(() => void 0);
736
+ throw new ProfileDeletedError(profile);
737
+ }
733
738
  const deletion = await readJson((0, import_node_path.join)(turnDirectory, "deleted.json")).catch(() => null);
734
739
  const deletedWhileWaiting = typeof deletion?.slot === "number" && deletion.slot >= firstWaitedTurn;
735
740
  while (true) {
736
741
  const token = (0, import_node_crypto.randomUUID)();
737
- if (await publishProfileLock(profile, lockPath, token)) {
742
+ if (await publishProfileLock(profile, lockPath, token, options.requireProfile === true)) {
738
743
  return {
739
744
  deletedWhileWaiting,
740
745
  turnSlot: turn.slot,
@@ -979,12 +984,13 @@ async function collectTurns(profile, turn) {
979
984
  }
980
985
  }
981
986
  }
982
- async function publishProfileLock(profile, lockPath, token) {
987
+ async function publishProfileLock(profile, lockPath, token, requireProfile) {
983
988
  try {
984
989
  await (0, import_promises.mkdir)(lockPath, { mode: PRIVATE_DIR_MODE });
985
990
  } catch (error) {
986
991
  if (isErrno(error, "EEXIST")) return false;
987
992
  if (!isErrno(error, "ENOENT")) throw error;
993
+ if (requireProfile) throw new ProfileDeletedError(profile);
988
994
  await (0, import_promises.mkdir)(profilePath(profile), { recursive: true, mode: PRIVATE_DIR_MODE });
989
995
  return false;
990
996
  }