@@ -16,6 +16,7 @@ const BACKUP_WINDOWS_RESERVED_NAME_REGEX =
1616 / ^ ( c o n | p r n | a u x | n u l | c o m [ 1 - 9 ] | l p t [ 1 - 9 ] ) $ / i;
1717const BACKUP_INVALID_SUFFIXES = [ ".tmp" , ".wal" ] ;
1818const BACKUP_PROHIBITED_SUBSTRINGS = [ ".rotate." ] ;
19+ const inFlightNamedBackupExports = new Set < string > ( ) ;
1920
2021export 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