feat(engine): auto-free disk space with retention + hard cap#2
Merged
Conversation
Disk mode never fills up now: content that is no longer needed is removed, and the download folder is bounded by a configurable cap (the disk analogue of the RAM ring-buffer). Policy (internal/engine/janitor.go): - retire(): a torrent no longer needed. Private torrents are deleted immediately (their tracker ratio/time already served as the retention window); public torrents are dropped from the active set but kept on disk and marked PendingDeleteAt = now + grace, so a returning viewer resumes instantly. - janitor loop: deletes pending content once its grace window elapses; if the dir exceeds Disk.MaxGB, evicts the oldest inactive content first (the hard cap overrides the grace window). - Never touches content being watched (readers>0) or seeding toward a live target. Triggers wired: - seed ratio/time target met -> retire (was: drop, leaving files) [deleteAfterSeed] - end of playback / idle timeout in disk mode -> retire [deleteAfterPlayback] - re-adding a pending torrent clears the flag (rescue from retained files). Safety guards for automatic deletion: reject empty names and path traversal via crafted torrent names (safeDataPath), delete only disk-mode records, and route manual delete-with-files through the same guard. Settings (config.Disk, editable in the UI, not env): maxGB, graceMinutes, deleteAfterSeed, deleteAfterPlayback. TorrentRecord gains PendingDeleteAt. Tests: safeDataPath guards, dirSize, evictKey ordering, deleteRecordFiles. Docs: README "Disk cleanup" section. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bj3G2zzqEaALFa8ufbkDJ
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.
Qué hace
En modo disco, el espacio ya no se llena: lo que deja de ser necesario se borra, y la carpeta de descargas queda acotada por un tope configurable (el análogo en disco del ring buffer de RAM).
Política (
internal/engine/janitor.go)retire()— torrent que ya no se necesita:PendingDeleteAt = ahora + gracia; si el espectador vuelve, reanuda al instante desde los archivos retenidos.Disk.MaxGB, desaloja lo más viejo primero (el tope duro manda sobre la gracia).readers>0) ni lo que seedea hacia un objetivo vivo.Disparadores conectados
Drop(dejaba archivo)retire(deleteAfterSeed)Drop(dejaba archivo)retire(deleteAfterPlayback)Guardas de seguridad (borrado automático)
safeDataPath).Ajustes (en Settings, editables en la UI — no env)
disk.maxGB,disk.graceMinutes,disk.deleteAfterSeed,disk.deleteAfterPlayback.TorrentRecordganaPendingDeleteAt.Verificación
safeDataPath(rechaza../../etcy vacío),dirSize, orden deevictKey,deleteRecordFiles. Backendgo build+vet+testen verde; frontendtsc+vite buildOK.GET/PUT /api/settingsexponen y persisten el bloquedisk,maxGB=-3normaliza a0, sin panics, janitor corriendo.Nota de garantía
Con esto: se conserva solo lo activo o con seed vivo; lo demás se limpia (con colchón de gracia para reanudar sin re-descargar); y el disco nunca supera
disk.maxGB.🤖 Generated with Claude Code