Browse Source

Add --prune flag for explicit marking and orphan cleanup

master
AI Bot 1 week ago committed by Riyyi
parent
commit
db4e22a580
  1. 11
      README.md
  2. 8
      cmd/declpac/main.go
  3. 29
      pkg/pacman/pacman.go

11
README.md

@ -5,8 +5,8 @@ Declarative package manager for Arch Linux that syncs your system with a declare
## Features
- Declarative state management — define your desired package list in files or stdin
- Smart orphan cleanup — removes packages no longer needed
- Explicit package tracking — marks declared packages as explicit
- Explicit package tracking — marks declared packages as explicit (with `--prune`)
- Smart orphan cleanup — removes packages no longer needed (with `--prune`)
- AUR support — builds and installs AUR packages automatically
- Machine-readable output — perfect for scripting
@ -67,8 +67,9 @@ contents are automatically included in the package list.
| Flag | Alias | Description |
|------|-------|-------------|
| `--state` | `-s` | State file(s) to read package list from (can be used multiple times) |
| `--nocheck` | | Skip safety check (allow significant package count reductions)
| `--nocheck` | | Skip safety check (allow significant package count reductions) |
| `--dry-run` | | Preview changes without applying them |
| `--prune` | | Mark packages as explicit and cleanup orphans |
| `--verbose` | `-v` | Enable verbose output |
| `--help` | `-h` | Show help message |
@ -79,8 +80,8 @@ contents are automatically included in the package list.
3. **Categorize** — Check if packages are in official repos or AUR
4. **Sync** — Install/update packages via pacman
5. **Build** — Build and install AUR packages via makepkg
6. **Mark** — Mark declared packages as explicit, all others as dependencies
7. **Cleanup** — Remove orphaned packages
6. **Mark** (with `--prune`) — Mark declared packages as explicit, all others as dependencies
7. **Cleanup** (with `--prune`) — Remove orphaned packages
### Database Freshness

8
cmd/declpac/main.go

@ -19,6 +19,7 @@ type Config struct {
StateFiles []string
NoCheck bool
DryRun bool
Prune bool
Verbose bool
}
@ -45,6 +46,11 @@ func main() {
Usage: "Simulate the sync without making changes",
Destination: &cfg.DryRun,
},
&cli.BoolFlag{
Name: "prune",
Usage: "Mark packages and cleanup orphans",
Destination: &cfg.Prune,
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
@ -97,7 +103,7 @@ func run(cfg *Config) error {
}
defer log.Close()
result, err := pacman.Sync(merged, cfg.NoCheck)
result, err := pacman.Sync(merged, cfg.NoCheck, cfg.Prune)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
return err

29
pkg/pacman/pacman.go

@ -13,7 +13,7 @@ import (
"github.com/Riyyi/declpac/pkg/pacman/sync"
)
func Sync(packages []string, noCheck bool) (*output.Result, error) {
func Sync(packages []string, noCheck bool, prune bool) (*output.Result, error) {
start := time.Now()
log.Debug("Sync: starting...")
@ -82,19 +82,24 @@ func Sync(packages []string, noCheck bool) (*output.Result, error) {
log.Debug("Sync: AUR package %s installed (%.2fs)", pkg, time.Since(start).Seconds())
}
log.Debug("Sync: marking all as deps...")
markAllAsDeps()
log.Debug("Sync: all marked as deps (%.2fs)", time.Since(start).Seconds())
var removed int
if prune {
log.Debug("Sync: marking all as deps...")
if err := markAllAsDeps(); err != nil {
return nil, err
}
log.Debug("Sync: all marked as deps (%.2fs)", time.Since(start).Seconds())
log.Debug("Sync: marking state packages as explicit...")
if err := sync.MarkAs(packages, "explicit", log.GetLogWriter()); err != nil {
fmt.Fprintf(os.Stderr, "warning: could not mark state packages as explicit: %v\n", err)
}
log.Debug("Sync: state packages marked as explicit (%.2fs)", time.Since(start).Seconds())
log.Debug("Sync: marking state packages as explicit...")
if err := sync.MarkAs(packages, "explicit", log.GetLogWriter()); err != nil {
fmt.Fprintf(os.Stderr, "warning: could not mark state packages as explicit: %v\n", err)
}
log.Debug("Sync: state packages marked as explicit (%.2fs)", time.Since(start).Seconds())
removed, err := cleanupOrphans()
if err != nil {
return nil, err
removed, err = cleanupOrphans()
if err != nil {
return nil, err
}
}
list, _ = read.List()

Loading…
Cancel
Save