From 2197ce0c1e7f6368a1c4eefceaf7b29841552e27 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 17:04:53 +0000 Subject: [PATCH 1/2] Initial plan From 72b5439b794655ee05733e510642c3e947469020 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 17:07:24 +0000 Subject: [PATCH 2/2] Make VFS locking methods mandatory Co-authored-by: carlsverre <82591+carlsverre@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ examples/memvfs.rs | 5 +++++ src/mock.rs | 20 +++++++++++++++++++- src/vfs.rs | 12 +++--------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e75519b..8c638a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes will be documented in this file. +## 0.7.0 (unreleased) + +- BREAKING: `Vfs::lock`, `Vfs::unlock`, and `Vfs::check_reserved_lock` no longer have default implementations and must be implemented by every `Vfs`. + ## 0.6.0 - 2026-02-19 Added `check_reserved_lock` to Vfs. This method allows you to inform SQLite if any threads or processes currently hold a lock on the specified file. It is recommended to implement this method if you also implement the lock and unlock methods. diff --git a/examples/memvfs.rs b/examples/memvfs.rs index 402a602..7652c39 100644 --- a/examples/memvfs.rs +++ b/examples/memvfs.rs @@ -129,6 +129,11 @@ impl Vfs for MemVfs { Ok(()) } + fn check_reserved_lock(&self, handle: &mut Self::Handle) -> VfsResult { + log::debug!("check_reserved_lock: file={:?}", handle.name); + Ok(false) + } + fn write(&self, handle: &mut Self::Handle, offset: usize, buf: &[u8]) -> VfsResult { log::debug!( "write: file={:?}, offset={}, len={}", diff --git a/src/mock.rs b/src/mock.rs index c2b6f28..c63133c 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -14,7 +14,7 @@ use alloc::format; use alloc::sync::Arc; use parking_lot::{Mutex, MutexGuard}; -use crate::flags::{self, AccessFlags, OpenOpts}; +use crate::flags::{self, AccessFlags, LockLevel, OpenOpts}; use crate::logger::{SqliteLogLevel, SqliteLogger}; use crate::vars; use crate::vfs::{ @@ -257,6 +257,24 @@ impl Vfs for MockVfs { Ok(()) } + fn lock(&self, meta: &mut Self::Handle, level: LockLevel) -> VfsResult<()> { + let state = self.state(); + state.log(format_args!("lock: handle={meta:?} level={level:?}")); + Ok(()) + } + + fn unlock(&self, meta: &mut Self::Handle, level: LockLevel) -> VfsResult<()> { + let state = self.state(); + state.log(format_args!("unlock: handle={meta:?} level={level:?}")); + Ok(()) + } + + fn check_reserved_lock(&self, meta: &mut Self::Handle) -> VfsResult { + let state = self.state(); + state.log(format_args!("check_reserved_lock: handle={meta:?}")); + Ok(false) + } + fn close(&self, meta: Self::Handle) -> VfsResult<()> { let mut state = self.state(); state.log(format_args!("close: handle={meta:?}")); diff --git a/src/vfs.rs b/src/vfs.rs index c47b46b..8a06dc6 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -158,17 +158,11 @@ pub trait Vfs: Send + Sync { fn write(&self, handle: &mut Self::Handle, offset: usize, data: &[u8]) -> VfsResult; fn read(&self, handle: &mut Self::Handle, offset: usize, data: &mut [u8]) -> VfsResult; - fn lock(&self, handle: &mut Self::Handle, level: LockLevel) -> VfsResult<()> { - Ok(()) - } + fn lock(&self, handle: &mut Self::Handle, level: LockLevel) -> VfsResult<()>; - fn unlock(&self, handle: &mut Self::Handle, level: LockLevel) -> VfsResult<()> { - Ok(()) - } + fn unlock(&self, handle: &mut Self::Handle, level: LockLevel) -> VfsResult<()>; - fn check_reserved_lock(&self, handle: &mut Self::Handle) -> VfsResult { - Ok(false) - } + fn check_reserved_lock(&self, handle: &mut Self::Handle) -> VfsResult; fn sync(&self, handle: &mut Self::Handle) -> VfsResult<()> { Ok(())