MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / acquire

Method acquire

packages/server/src/inspector.rs:505–528  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

503
504impl RegistryFileLock {
505 fn acquire(path: &Path) -> io::Result<Self> {
506 #[cfg(unix)]
507 {
508 if let Some(parent) = path.parent() {
509 fs::create_dir_all(parent)?;
510 }
511 let lock_path = path.with_extension("json.lock");
512 let file = fs::OpenOptions::new()
513 .create(true)
514 .write(true)
515 .truncate(false)
516 .open(lock_path)?;
517 let result = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX) };
518 if result != 0 {
519 return Err(io::Error::last_os_error());
520 }
521 Ok(Self { file })
522 }
523 #[cfg(not(unix))]
524 {
525 let _ = path;
526 Ok(Self {})
527 }
528 }
529}
530
531impl Drop for RegistryFileLock {

Callers

nothing calls this directly

Calls 2

openMethod · 0.80
createMethod · 0.80

Tested by

no test coverage detected