/ veet / internal / detector / systemlogs.go
swadhinbiswas feat: initial release of VEET (Universal Linux App Uninstaller & Deep-Clean Residual Purger) · 8/15/2026
5e0888a
79 lines · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package detector

import (
	"context"
	"os"
	"path/filepath"
	"strings"

	"github.com/swadhinbiswas/veet/internal/model"
)

type systemLogsDetector struct{}

// NewSystemLogsDetector surfaces systemd journal logs and rotated log archives.
func NewSystemLogsDetector() Detector {
	return &systemLogsDetector{}
}

func (d *systemLogsDetector) Source() string  { return "system" }
func (d *systemLogsDetector) Available() bool { return true }

func (d *systemLogsDetector) Detect(ctx context.Context) ([]model.AppInfo, error) {
	var apps []model.AppInfo

	// Check /var/log/journal
	journalPath := "/var/log/journal"
	if size, err := dirSizeKB(journalPath); err == nil && size > 1024 {
		rem := model.RemovableFiles{
			Paths:    []string{journalPath},
			Elevated: []string{journalPath},
			LogKB:    size,
		}
		apps = append(apps, model.AppInfo{
			Name:          "systemd-journal-logs",
			Version:       "-",
			Source:        "system",
			InstallSizeKB: size,
			Status:        "Installed",
			Removable:     rem,
		})
	}

	// Check rotated archived logs in /var/log
	if entries, err := os.ReadDir("/var/log"); err == nil {
		var archivePaths []string
		var totalKB int64
		for _, e := range entries {
			if e.IsDir() {
				continue
			}
			name := e.Name()
			if strings.HasSuffix(name, ".gz") || strings.HasSuffix(name, ".old") || strings.HasSuffix(name, ".1") {
				p := filepath.Join("/var/log", name)
				if fi, err := e.Info(); err == nil {
					totalKB += fi.Size() / 1024
					archivePaths = append(archivePaths, p)
				}
			}
		}
		if totalKB > 512 && len(archivePaths) > 0 {
			rem := model.RemovableFiles{
				Paths:    archivePaths,
				Elevated: archivePaths,
				LogKB:    totalKB,
			}
			apps = append(apps, model.AppInfo{
				Name:          "system-log-archives",
				Version:       "-",
				Source:        "system",
				InstallSizeKB: totalKB,
				Status:        "Installed",
				Removable:     rem,
			})
		}
	}

	return apps, nil
}