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

Function yaml_lock_release

src/cli/config_yaml_edit.c:518–555  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516}
517
518static int yaml_lock_release(yaml_config_lock_t *lock) {
519 int result = YAML_ERROR;
520#ifdef _WIN32
521 if (lock->handle != INVALID_HANDLE_VALUE) {
522 BY_HANDLE_FILE_INFORMATION info;
523 FILE_DISPOSITION_INFO disposition = {.DeleteFile = TRUE};
524 bool same = GetFileInformationByHandle(lock->handle, &info) &&
525 (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&
526 (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&
527 info.dwVolumeSerialNumber == lock->volume_serial &&
528 info.nFileIndexHigh == lock->file_index_high &&
529 info.nFileIndexLow == lock->file_index_low;
530 bool removed = same && SetFileInformationByHandle(lock->handle, FileDispositionInfo,
531 &disposition, sizeof(disposition));
532 BOOL closed = CloseHandle(lock->handle);
533 result = removed && closed ? 0 : YAML_ERROR;
534 lock->handle = INVALID_HANDLE_VALUE;
535 }
536#else
537 if (lock->descriptor >= 0) {
538 struct stat handle_state;
539 struct stat path_state;
540 bool same =
541 fstat(lock->descriptor, &handle_state) == 0 && lstat(lock->path, &path_state) == 0 &&
542 yaml_lock_file_state_is_safe(&handle_state) &&
543 yaml_lock_file_state_is_safe(&path_state) && handle_state.st_dev == lock->device &&
544 handle_state.st_ino == lock->inode && handle_state.st_uid == lock->owner &&
545 yaml_lock_file_state_matches(&handle_state, &path_state);
546 int unlocked = yaml_flock_nointr(lock->descriptor, LOCK_UN);
547 int closed = close(lock->descriptor);
548 result = same && unlocked == 0 && closed == 0 ? 0 : YAML_ERROR;
549 lock->descriptor = -1;
550 }
551#endif
552 free(lock->path);
553 lock->path = NULL;
554 return result;
555}
556
557static bool yaml_snapshot_state_equal(const yaml_file_snapshot_t *left,
558 const yaml_file_snapshot_t *right) {

Calls 5

lstatFunction · 0.85
yaml_flock_nointrFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected