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

Function yaml_replace_file

src/cli/config_yaml_edit.c:854–884  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

852#endif
853
854static int yaml_replace_file(const char *temp_path, const char *path, bool destination_exists) {
855#ifdef _WIN32
856 wchar_t *wide_temp = cbm_utf8_to_wide(temp_path);
857 wchar_t *wide_path = cbm_utf8_to_wide(path);
858 if (!wide_temp || !wide_path) {
859 free(wide_temp);
860 free(wide_path);
861 return YAML_ERROR;
862 }
863 BOOL replaced = destination_exists ? ReplaceFileW(wide_path, wide_temp, NULL,
864 REPLACEFILE_WRITE_THROUGH, NULL, NULL)
865 : MoveFileExW(wide_temp, wide_path, MOVEFILE_WRITE_THROUGH);
866 free(wide_temp);
867 free(wide_path);
868 return replaced ? 0 : YAML_ERROR;
869#else
870 if (!destination_exists) {
871 if (link(temp_path, path) != 0) {
872 return YAML_ERROR;
873 }
874 if (cbm_unlink(temp_path) != 0) {
875 return YAML_ERROR;
876 }
877 return yaml_sync_parent_directory(path);
878 }
879 if (rename(temp_path, path) != 0) {
880 return YAML_ERROR;
881 }
882 return yaml_sync_parent_directory(path);
883#endif
884}
885
886static const char *yaml_temp_name(const char *temp_path) {
887 const char *slash = strrchr(temp_path, '/');

Callers 1

yaml_write_atomic_atFunction · 0.85

Calls 4

cbm_utf8_to_wideFunction · 0.85
linkFunction · 0.85
cbm_unlinkFunction · 0.85

Tested by

no test coverage detected