MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / text_replace_file

Function text_replace_file

src/cli/config_text_edit.c:574–604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

572#endif
573
574static int text_replace_file(const char *temp_path, const char *path, int destination_exists) {
575#ifdef _WIN32
576 wchar_t *wide_temp = cbm_utf8_to_wide(temp_path);
577 wchar_t *wide_path = cbm_utf8_to_wide(path);
578 if (!wide_temp || !wide_path) {
579 free(wide_temp);
580 free(wide_path);
581 return TEXT_ERROR;
582 }
583 BOOL replaced = destination_exists ? ReplaceFileW(wide_path, wide_temp, NULL,
584 REPLACEFILE_WRITE_THROUGH, NULL, NULL)
585 : MoveFileExW(wide_temp, wide_path, MOVEFILE_WRITE_THROUGH);
586 free(wide_temp);
587 free(wide_path);
588 return replaced ? TEXT_OK : TEXT_ERROR;
589#else
590 if (!destination_exists) {
591 if (link(temp_path, path) != 0) {
592 return TEXT_ERROR;
593 }
594 if (cbm_unlink(temp_path) != 0) {
595 return TEXT_ERROR;
596 }
597 return text_sync_parent_directory(path);
598 }
599 if (rename(temp_path, path) != 0) {
600 return TEXT_ERROR;
601 }
602 return text_sync_parent_directory(path);
603#endif
604}
605
606static const char *text_temp_name(const char *temp_path) {
607 const char *slash = strrchr(temp_path, '/');

Callers 1

Calls 4

cbm_utf8_to_wideFunction · 0.85
linkFunction · 0.85
cbm_unlinkFunction · 0.85

Tested by

no test coverage detected