{"version":3,"file":"accessible-dir.d.ts","sourceRoot":"","sources":["../../../src/shared/accessible-dir.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAO9B,KAAK,eAAe,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,GAAG,WAAW,CAAC,CAAC;AAEnE,KAAK,oBAAoB,GAAG;IAC3B,EAAE,CAAC,EAAE,eAAe,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAuC/F","sourcesContent":["import * as fs from \"node:fs\";\nimport {\n\tDEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS,\n\trunFileSystemOperationWithRetry,\n\twaitForFileSystemRetry,\n} from \"./file-system-retry.ts\";\n\ntype AccessibleDirFs = Pick<typeof fs, \"accessSync\" | \"mkdirSync\">;\n\ntype AccessibleDirOptions = {\n\tfs?: AccessibleDirFs;\n\tretryDirectoryErrors?: boolean;\n\tretryDelaysMs?: readonly number[];\n\twait?: (delayMs: number) => void;\n\tpid?: number;\n};\n\nexport function ensureAccessibleDir(dirPath: string, options: AccessibleDirOptions = {}): string {\n\tconst fsImpl = options.fs ?? fs;\n\tconst pid = options.pid ?? process.pid;\n\tconst retryDirectoryErrors = options.retryDirectoryErrors ?? process.platform === \"win32\";\n\tconst retryDelaysMs = retryDirectoryErrors ? (options.retryDelaysMs ?? DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS) : [];\n\tconst wait = options.wait ?? waitForFileSystemRetry;\n\n\tconst mkdirWithRetry = (target: string): void => {\n\t\trunFileSystemOperationWithRetry(\n\t\t\t() => {\n\t\t\t\tfsImpl.mkdirSync(target, { recursive: true });\n\t\t\t},\n\t\t\t{ retryDelaysMs, wait },\n\t\t);\n\t};\n\tconst accessWithRetry = (target: string): void => {\n\t\trunFileSystemOperationWithRetry(\n\t\t\t() => {\n\t\t\t\tfsImpl.accessSync(target, fs.constants.R_OK | fs.constants.W_OK);\n\t\t\t},\n\t\t\t{ retryDelaysMs, wait },\n\t\t);\n\t};\n\tconst fallbackPath = (): string => {\n\t\tconst fallback = `${dirPath}-${pid}`;\n\t\tmkdirWithRetry(fallback);\n\t\taccessWithRetry(fallback);\n\t\treturn fallback;\n\t};\n\n\ttry {\n\t\tmkdirWithRetry(dirPath);\n\t\taccessWithRetry(dirPath);\n\t\treturn dirPath;\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException | undefined)?.code;\n\t\tif (code !== \"EPERM\" && code !== \"EACCES\") throw error;\n\t\treturn fallbackPath();\n\t}\n}\n"]}