P3: Quota enforcement - check before write in flush()
Some checks failed
Test / build (push) Has been cancelled
Test / test (push) Has been cancelled

- 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
This commit is contained in:
Warren
2026-06-21 18:24:44 +08:00
parent 12ec190831
commit a56207db0b

View File

@@ -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() {