MCPcopy Create free account
hub / github.com/apache/maka / writeBackupBytes

Function writeBackupBytes

packages/storage/src/memory-bundle-io.ts:846–870  ·  view source on GitHub ↗
(
  directory: DirectoryBinding,
  kind: MemoryBackupKind,
  bytes: Uint8Array,
)

Source from the content-addressed store, hash-verified

844}
845
846async function writeBackupBytes(
847 directory: DirectoryBinding,
848 kind: MemoryBackupKind,
849 bytes: Uint8Array,
850): Promise<void> {
851 const destination = backupPath(directory.path, kind);
852 await assertRegularOrMissing(destination, BACKUP_FILES[kind]);
853 const temporaryPath = `${destination}.${randomUUID()}.tmp`;
854 let handle: Awaited<ReturnType<typeof open>> | undefined;
855 try {
856 handle = await open(temporaryPath, 'wx', 0o600);
857 await handle.writeFile(bytes);
858 await handle.sync();
859 await handle.close();
860 handle = undefined;
861 await assertDirectoryBinding(directory);
862 await rename(temporaryPath, destination);
863 await chmod(destination, 0o600);
864 await syncDirectory(directory.path);
865 await assertDirectoryBinding(directory);
866 } finally {
867 if (handle) await handle.close();
868 await rm(temporaryPath, { force: true });
869 }
870}
871
872async function rotateRestoreHistory(directory: DirectoryBinding): Promise<void> {
873 for (let index = RESTORE_HISTORY_LIMIT - 1; index >= 1; index -= 1) {

Callers 1

writeMemoryBackupFunction · 0.85

Calls 10

backupPathFunction · 0.85
assertRegularOrMissingFunction · 0.85
assertDirectoryBindingFunction · 0.85
rmFunction · 0.85
syncDirectoryFunction · 0.70
writeFileMethod · 0.65
syncMethod · 0.65
closeMethod · 0.65
openFunction · 0.50
renameFunction · 0.50

Tested by

no test coverage detected