MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / writeAll

Function writeAll

packages/plugins/file-secrets/src/index.ts:137–164  ·  view source on GitHub ↗
(
  filePath: string,
  secrets: Record<string, string>,
)

Source from the content-addressed store, hash-verified

135 );
136
137const writeAll = (
138 filePath: string,
139 secrets: Record<string, string>,
140): Effect.Effect<void, StorageError> => {
141 const dir = path.dirname(filePath);
142 const tmp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
143 return Effect.gen(function* () {
144 if (!fs.existsSync(dir)) {
145 yield* Effect.try({
146 try: () => fs.mkdirSync(dir, { recursive: true, mode: 0o700 }),
147 catch: toStorageError("Failed to create auth directory"),
148 });
149 }
150 yield* Effect.try({
151 try: () => {
152 fs.writeFileSync(tmp, JSON.stringify(secrets, null, 2), { mode: 0o600 });
153 // `mode` only applies when the file is created; chmod afterwards covers
154 // the case where a temporary file with broader permissions already exists.
155 fs.chmodSync(tmp, 0o600);
156 },
157 catch: toStorageError("Failed to write temporary auth file"),
158 });
159 yield* Effect.try({
160 try: () => fs.renameSync(tmp, filePath),
161 catch: toStorageError("Failed to replace auth file"),
162 });
163 });
164};
165
166const migrateLegacyAuthFile = ({
167 filePath,

Callers 2

migrateLegacyAuthFileFunction · 0.85
makeFileProviderFunction · 0.85

Calls 1

toStorageErrorFunction · 0.70

Tested by

no test coverage detected