@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.
@@ -582,7 +582,8 @@ async function acquireProfileLock(profile, options) {
582
582
  const lockPath = profileLockPath(profile);
583
583
  const turnDirectory = profileTurnLockPath(profile);
584
584
  const directory = profilePath(profile);
585
- await mkdir(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
585
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) throw new ProfileDeletedError(profile);
586
+ if (!options.requireProfile) await mkdir(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
586
587
  await mkdir(dirname(turnDirectory), { recursive: true, mode: PRIVATE_DIR_MODE });
587
588
  for (const path of [tinycloudHomePath(), profilesPath(), directory]) {
588
589
  await chmod(path, PRIVATE_DIR_MODE).catch((error) => {
@@ -591,11 +592,15 @@ async function acquireProfileLock(profile, options) {
591
592
  }
592
593
  const { turn, firstWaitedTurn } = await acquireTurn(profile, turnDirectory, deadline);
593
594
  try {
595
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) {
596
+ await rmdir(directory).catch(() => void 0);
597
+ throw new ProfileDeletedError(profile);
598
+ }
594
599
  const deletion = await readJson(join(turnDirectory, "deleted.json")).catch(() => null);
595
600
  const deletedWhileWaiting = typeof deletion?.slot === "number" && deletion.slot >= firstWaitedTurn;
596
601
  while (true) {
597
602
  const token = randomUUID();
598
- if (await publishProfileLock(profile, lockPath, token)) {
603
+ if (await publishProfileLock(profile, lockPath, token, options.requireProfile === true)) {
599
604
  return {
600
605
  deletedWhileWaiting,
601
606
  turnSlot: turn.slot,
@@ -846,12 +851,13 @@ async function collectTurns(profile, turn) {
846
851
  }
847
852
  }
848
853
  }
849
- async function publishProfileLock(profile, lockPath, token) {
854
+ async function publishProfileLock(profile, lockPath, token, requireProfile) {
850
855
  try {
851
856
  await mkdir(lockPath, { mode: PRIVATE_DIR_MODE });
852
857
  } catch (error) {
853
858
  if (isErrno(error, "EEXIST")) return false;
854
859
  if (!isErrno(error, "ENOENT")) throw error;
860
+ if (requireProfile) throw new ProfileDeletedError(profile);
855
861
  await mkdir(profilePath(profile), { recursive: true, mode: PRIVATE_DIR_MODE });
856
862
  return false;
857
863
  }