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

Function yaml_lock_release

src/cli/config_yaml_edit.c:517–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Calls 3

yaml_flock_nointrFunction · 0.85

Tested by

no test coverage detected