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

Function yaml_replace_file

src/cli/config_yaml_edit.c:814–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

812#endif
813
814static int yaml_replace_file(const char *temp_path, const char *path, bool destination_exists) {
815#ifdef _WIN32
816 wchar_t *wide_temp = cbm_utf8_to_wide(temp_path);
817 wchar_t *wide_path = cbm_utf8_to_wide(path);
818 if (!wide_temp || !wide_path) {
819 free(wide_temp);
820 free(wide_path);
821 return YAML_ERROR;
822 }
823 BOOL replaced = destination_exists ? ReplaceFileW(wide_path, wide_temp, NULL,
824 REPLACEFILE_WRITE_THROUGH, NULL, NULL)
825 : MoveFileExW(wide_temp, wide_path, MOVEFILE_WRITE_THROUGH);
826 free(wide_temp);
827 free(wide_path);
828 return replaced ? 0 : YAML_ERROR;
829#else
830 if (!destination_exists) {
831 if (link(temp_path, path) != 0) {
832 return YAML_ERROR;
833 }
834 if (cbm_unlink(temp_path) != 0) {
835 return YAML_ERROR;
836 }
837 return yaml_sync_parent_directory(path);
838 }
839 if (rename(temp_path, path) != 0) {
840 return YAML_ERROR;
841 }
842 return yaml_sync_parent_directory(path);
843#endif
844}
845
846static int yaml_write_atomic(const char *path, const char *data, size_t len,
847 const char *expected_data, size_t expected_len,

Callers 1

yaml_write_atomicFunction · 0.85

Calls 3

cbm_utf8_to_wideFunction · 0.85
cbm_unlinkFunction · 0.85

Tested by

no test coverage detected