From a56207db0bc78299000d61d3e5c237cb08faa132 Mon Sep 17 00:00:00 2001 From: Warren Date: Sun, 21 Jun 2026 18:24:44 +0800 Subject: [PATCH] P3: Quota enforcement - check before write in flush() - Check VfsBackend quota before writing buffered data - Return FsError::InsufficientStorage (507) if limit exceeded - Log warning with current/adding/limit values Tests: 289 passed, 0 failed --- markbase-core/src/webdav.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/markbase-core/src/webdav.rs b/markbase-core/src/webdav.rs index d12f340..52429e8 100644 --- a/markbase-core/src/webdav.rs +++ b/markbase-core/src/webdav.rs @@ -510,6 +510,30 @@ impl DavFile for VfsDavFile { return Box::pin(std::future::ready(Ok(()))); } + // Quota check before write + if !self.data.is_empty() { + if let Some(vfs) = &self.vfs { + if let Some(path) = &self.path { + let usage = vfs.get_quota_usage(path); + let quota = vfs.get_quota(path); + if let (Ok(usage), Ok(quota)) = (usage, quota) { + if quota.space_limit > 0 { + let new_size = usage.space_used + self.data.len() as u64; + if new_size > quota.space_limit { + log::warn!( + "Quota exceeded: current={}, adding={}, limit={}", + usage.space_used, + self.data.len(), + quota.space_limit + ); + return Box::pin(std::future::ready(Err(FsError::InsufficientStorage))); + } + } + } + } + } + } + // Phase 1: Flush to storage if let Some(vfs_file_mutex) = &self.vfs_file { match vfs_file_mutex.lock() {