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

Function yaml_lock_release

src/cli/config_yaml_edit.c:503–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501}
502
503static int yaml_lock_release(yaml_config_lock_t *lock) {
504 int result = YAML_ERROR;
505#ifdef _WIN32
506 if (lock->handle != INVALID_HANDLE_VALUE) {
507 BY_HANDLE_FILE_INFORMATION info;
508 FILE_DISPOSITION_INFO disposition = {.DeleteFile = TRUE};
509 bool same = GetFileInformationByHandle(lock->handle, &info) &&
510 (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&
511 (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&
512 info.dwVolumeSerialNumber == lock->volume_serial &&
513 info.nFileIndexHigh == lock->file_index_high &&
514 info.nFileIndexLow == lock->file_index_low;
515 bool removed = same && SetFileInformationByHandle(lock->handle, FileDispositionInfo,
516 &disposition, sizeof(disposition));
517 BOOL closed = CloseHandle(lock->handle);
518 result = removed && closed ? 0 : YAML_ERROR;
519 lock->handle = INVALID_HANDLE_VALUE;
520 }
521#else
522 if (lock->descriptor >= 0) {
523 struct stat handle_state;
524 struct stat path_state;
525 bool same =
526 fstat(lock->descriptor, &handle_state) == 0 && lstat(lock->path, &path_state) == 0 &&
527 yaml_lock_file_state_is_safe(&handle_state) &&
528 yaml_lock_file_state_is_safe(&path_state) && handle_state.st_dev == lock->device &&
529 handle_state.st_ino == lock->inode && handle_state.st_uid == lock->owner &&
530 yaml_lock_file_state_matches(&handle_state, &path_state);
531 int unlocked = yaml_flock_nointr(lock->descriptor, LOCK_UN);
532 int closed = close(lock->descriptor);
533 result = same && unlocked == 0 && closed == 0 ? 0 : YAML_ERROR;
534 lock->descriptor = -1;
535 }
536#endif
537 free(lock->path);
538 lock->path = NULL;
539 return result;
540}
541
542static bool yaml_snapshot_state_equal(const yaml_file_snapshot_t *left,
543 const yaml_file_snapshot_t *right) {

Calls 3

yaml_flock_nointrFunction · 0.85

Tested by

no test coverage detected