MCPcopy Create free account
hub / github.com/PalisadoesFoundation/talawa-api / commitTemp

Function commitTemp

scripts/setup/AtomicEnvWriter.ts:92–131  ·  view source on GitHub ↗
(
	envFile: string,
	tempFile: string,
)

Source from the content-addressed store, hash-verified

90 * @throws {SetupError} When commit fails
91 */
92export 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.

Callers 4

initializeEnvFileFunction · 0.90
updateEnvVariableFunction · 0.90
atomicWriteEnvFunction · 0.85

Calls 1

errToErrorFunction · 0.85

Tested by

no test coverage detected