fix(webdav): 删除文件/目录时按引用计数回收共享缩略图 - #87
Merged
Merged
Conversation
缩略图按内容摘要寻址并被内容相同的文件共享,原删除逻辑从不清理 _$flaredrive$/thumbnails/,孤儿缩略图无限累积。每个引用文件现在在 _$flaredrive$/thumbnails/refs/<digest>/<path> 保留不可变 marker 对象: - PUT / 分片创建 / COPY 先写 marker 再写引用对象,并发删除不会误收 还在上传中的缩略图;PUT 后校验缩略图本体存在,缺失时 409 让客户端重试 - DELETE(文件/目录)先移除 marker,引用清零才回收缩略图;目录删除按 digest 去重回收;全删(DELETE /webdav/)连带清空 internal 缩略图子树 - 覆盖写入(fd-thumbnail 变化)释放旧引用;MOVE 先补目标引用再释放源引用 - fd-thumbnail 头按 hex 摘要格式校验后才进入 R2 key 兼容性:历史缩略图无 marker 时保守保留(宁可多留不误删);未带 fd-thumbnail 的覆盖仍保留原 customMetadata(Davflare 既有语义)。 同步上游修复 longern/FlareDrive#43,测试 11 项(webdavThumbnailGc), 全量 918 测试通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
对应上游 issue longern/FlareDrive#16(已在 上游认领 并提交 上游 PR longern/FlareDrive#43),本 PR 将同一修复移植到 Davflare 的
functions/webdav/protocol.ts。问题
缩略图按内容摘要寻址(
_$flaredrive$/thumbnails/<digest>.png)并被内容相同的文件共享,而handleDelete/deleteAll从不清理缩略图 → 删除图片后缩略图永远残留。本地代码与上游存在同样的问题。方案:per-path 引用 marker(无计数器、无读改写)
每个引用文件在
_$flaredrive$/thumbnails/refs/<digest>/<path>保留一个不可变 marker 对象,引用清零才回收缩略图。所有操作都是单对象 PUT/DELETE,无读改写竞争:并发删除最坏只会多留(与现状一致的良性泄漏),不会误删仍在使用的缩略图。/webdav/(全删)deleteAll本身会跳过 internal 前缀)另外
fd-thumbnail头现在按 hex 摘要格式(16–128 位)校验后才进入 R2 key。兼容性
测试
src/app/__tests__/webdavThumbnailGc.test.ts:11 项场景(建引用/共享/最后引用回收/覆盖释放/保留语义/目录删除/全删/COPY/MOVE/分片/非法头防护)webdavProtocol.test.ts的 PUT 覆盖用例改用合法 hex 摘要并补齐缩略图本体 seed(对齐真实客户端时序)tsc --noEmit干净