{"version":3,"file":"file-system-retry.d.ts","sourceRoot":"","sources":["../../../src/shared/file-system-retry.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mCAAmC,wDAAyD,CAAC;AAE1G,MAAM,MAAM,sBAAsB,GAAG;IACpC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAgB5D;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGlE;AAED,wBAAgB,+BAA+B,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAE,sBAA2B,GAAG,CAAC,CAY9G","sourcesContent":["const WAIT_BUFFER = typeof SharedArrayBuffer !== \"undefined\" ? new SharedArrayBuffer(4) : undefined;\nconst WAIT_VIEW = WAIT_BUFFER ? new Int32Array(WAIT_BUFFER) : undefined;\nconst RETRYABLE_FILE_SYSTEM_ERROR_CODES = new Set([\"EACCES\", \"EBUSY\", \"EPERM\"]);\n\nexport const DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS = [10, 25, 50, 100, 200, 500, 1000, 2000, 4000] as const;\n\nexport type FileSystemRetryOptions = {\n\tretryDelaysMs?: readonly number[];\n\twait?: (delayMs: number) => void;\n};\n\nexport function waitForFileSystemRetry(delayMs: number): void {\n\tif (delayMs <= 0) return;\n\tif (WAIT_VIEW) {\n\t\ttry {\n\t\t\t// Callers are synchronous status/result writers; Atomics.wait gives\n\t\t\t// Windows directory and rename locks time to clear without burning CPU.\n\t\t\tAtomics.wait(WAIT_VIEW, 0, 0, delayMs);\n\t\t\treturn;\n\t\t} catch {\n\t\t\t// Fall through to the portable busy wait below.\n\t\t}\n\t}\n\tconst end = Date.now() + delayMs;\n\twhile (Date.now() < end) {\n\t\t// Portable fallback for runtimes where Atomics.wait is unavailable.\n\t}\n}\n\nexport function isRetryableFileSystemError(error: unknown): boolean {\n\tconst code = (error as NodeJS.ErrnoException | undefined)?.code;\n\treturn typeof code === \"string\" && RETRYABLE_FILE_SYSTEM_ERROR_CODES.has(code);\n}\n\nexport function runFileSystemOperationWithRetry<T>(operation: () => T, options: FileSystemRetryOptions = {}): T {\n\tconst retryDelaysMs = options.retryDelaysMs ?? DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS;\n\tconst wait = options.wait ?? waitForFileSystemRetry;\n\tfor (let attempt = 0; ; attempt++) {\n\t\ttry {\n\t\t\treturn operation();\n\t\t} catch (error) {\n\t\t\tconst delayMs = retryDelaysMs[attempt];\n\t\t\tif (delayMs === undefined || !isRetryableFileSystemError(error)) throw error;\n\t\t\twait(delayMs);\n\t\t}\n\t}\n}\n"]}