///|
fn platform_atomic_replace(
  temporary : String,
  target : String,
) -> Unit raise PersistenceError {
  let bytes = wrap_fs_error(() => @fs.read_file_to_bytes(temporary))
  wrap_fs_error(() => @fs.write_bytes_to_file(target, bytes))
  wrap_fs_error(() => @fs.remove_file(temporary))
}

///|
fn platform_sync_file(_path : String) -> Unit {
  ()
}

///|
fn platform_try_acquire_lock(path : String) -> Int64? raise PersistenceError {
  if @fs.path_exists(path) {
    None
  } else {
    wrap_fs_error(() => @fs.write_bytes_to_file(path, b"MoonSearch writer lock"))
    Some(1L)
  }
}

///|
fn platform_release_lock(
  path : String,
  _token : Int64,
) -> Unit raise PersistenceError {
  if @fs.path_exists(path) {
    wrap_fs_error(() => @fs.remove_file(path))
  }
}

///|
fn platform_directory_capabilities() -> DirectoryCapabilities {
  {
    atomic_replace: false,
    durable_sync: false,
    exclusive_lock: false,
    read_only_mapping: false,
  }
}