Skip to content

Commit c0709a3

Browse files
committed
fix(release): reconcile all-open validation
1 parent 697bb47 commit c0709a3

4 files changed

Lines changed: 559 additions & 94 deletions

File tree

lib/named-backup-export.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const BACKUP_WINDOWS_RESERVED_NAME_REGEX =
1616
/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
1717
const BACKUP_INVALID_SUFFIXES = [".tmp", ".wal"];
1818
const BACKUP_PROHIBITED_SUBSTRINGS = [".rotate."];
19+
const inFlightNamedBackupExports = new Set<string>();
1920

2021
export interface NamedBackupExportDependencies {
2122
getStoragePath: () => string;
@@ -227,14 +228,23 @@ export async function exportNamedBackupFile(
227228
const storagePath = dependencies.getStoragePath();
228229
const destination = resolveNamedBackupPath(name, storagePath);
229230
const backupRoot = getNamedBackupRoot(storagePath);
231+
const exportKey = normalizePathForComparison(destination);
232+
if (!options?.force && inFlightNamedBackupExports.has(exportKey)) {
233+
throw new Error(`File already exists: ${destination}`);
234+
}
230235
assertWithinDirectory(dirname(backupRoot), backupRoot);
231236
await fs.mkdir(backupRoot, { recursive: true });
232-
await dependencies.exportAccounts(
233-
destination,
234-
options?.force === true,
235-
(resolvedPath) => {
236-
assertWithinDirectory(backupRoot, resolvedPath);
237-
},
238-
);
239-
return destination;
237+
inFlightNamedBackupExports.add(exportKey);
238+
try {
239+
await dependencies.exportAccounts(
240+
destination,
241+
options?.force === true,
242+
(resolvedPath) => {
243+
assertWithinDirectory(backupRoot, resolvedPath);
244+
},
245+
);
246+
return destination;
247+
} finally {
248+
inFlightNamedBackupExports.delete(exportKey);
249+
}
240250
}

0 commit comments

Comments
 (0)