( envFile: string, tempFile: string, )
| 90 | * @throws {SetupError} When commit fails |
| 91 | */ |
| 92 | export async function commitTemp( |
| 93 | envFile: string, |
| 94 | tempFile: string, |
| 95 | ): Promise<void> { |
| 96 | try { |
| 97 | await fs.rename(tempFile, envFile); |
| 98 | } catch (_e: unknown) { |
| 99 | const originalError = errToError(_e); |
| 100 | try { |
| 101 | await fs.copyFile(tempFile, envFile); |
| 102 | try { |
| 103 | await fs.unlink(tempFile); |
| 104 | } catch (unlinkError: unknown) { |
| 105 | throw new SetupError( |
| 106 | SetupErrorCode.COMMIT_FAILED, |
| 107 | "Temp file committed but cleanup failed", |
| 108 | { |
| 109 | operation: "commitTemp", |
| 110 | filePath: envFile, |
| 111 | originalError: originalError.message, |
| 112 | unlinkError: errToError(unlinkError).message, |
| 113 | }, |
| 114 | originalError, |
| 115 | ); |
| 116 | } |
| 117 | } catch (copyError: unknown) { |
| 118 | throw new SetupError( |
| 119 | SetupErrorCode.COMMIT_FAILED, |
| 120 | "Failed to commit temporary file to .env", |
| 121 | { |
| 122 | operation: "commitTemp", |
| 123 | filePath: envFile, |
| 124 | originalError: originalError.message, |
| 125 | fallbackError: errToError(copyError).message, |
| 126 | }, |
| 127 | originalError, |
| 128 | ); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Restores .env file from backup if backup exists. |
no test coverage detected