feat: add clean command to remove temp files, logs, and cached data
Adds `unarr clean` with interactive confirmation, --dry-run, --yes, and --all flags. Safely skips recent usenet resume files (<7 days) to preserve download progress. Includes platform-specific PID detection (Unix signal 0 / Windows heartbeat heuristic), CleanableBytes callback for future heartbeat reporting, and uses shared ui.FormatBytes.
This commit is contained in:
parent
3d6142a62e
commit
35e5298f23
9 changed files with 578 additions and 1 deletions
|
|
@ -39,7 +39,8 @@ type Daemon struct {
|
|||
heartbeatFailures int
|
||||
|
||||
// Callbacks for state tracking (set by cmd/daemon.go)
|
||||
GetActiveCount func() int
|
||||
GetActiveCount func() int
|
||||
GetCleanableBytes func() int64
|
||||
|
||||
// Exposed tickers for hot-reload
|
||||
PollTicker *time.Ticker
|
||||
|
|
|
|||
11
internal/agent/process_unix.go
Normal file
11
internal/agent/process_unix.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//go:build !windows
|
||||
|
||||
package agent
|
||||
|
||||
import "syscall"
|
||||
|
||||
// IsProcessAlive checks if a process with the given PID is running.
|
||||
// On Unix, sends signal 0 which checks existence without affecting the process.
|
||||
func IsProcessAlive(pid int) bool {
|
||||
return syscall.Kill(pid, 0) == nil
|
||||
}
|
||||
25
internal/agent/process_windows.go
Normal file
25
internal/agent/process_windows.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
//go:build windows
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// IsProcessAlive checks if a process with the given PID is running.
|
||||
// On Windows, os.FindProcess + a zero-timeout wait is used since
|
||||
// signal 0 is not supported.
|
||||
func IsProcessAlive(pid int) bool {
|
||||
p, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
// On Windows, FindProcess always succeeds. Use the state file's
|
||||
// last heartbeat as a heuristic: if it's recent, the process is alive.
|
||||
state := ReadState()
|
||||
if state == nil || state.PID != pid {
|
||||
return false
|
||||
}
|
||||
return time.Since(state.LastHeartbeat) < 2*time.Minute
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue