Add --prune flag for explicit marking and orphan cleanup
This commit is contained in:
@@ -5,8 +5,8 @@ Declarative package manager for Arch Linux that syncs your system with a declare
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Declarative state management — define your desired package list in files or stdin
|
- 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 (with `--prune`)
|
||||||
- Explicit package tracking — marks declared packages as explicit
|
- Smart orphan cleanup — removes packages no longer needed (with `--prune`)
|
||||||
- AUR support — builds and installs AUR packages automatically
|
- AUR support — builds and installs AUR packages automatically
|
||||||
- Machine-readable output — perfect for scripting
|
- Machine-readable output — perfect for scripting
|
||||||
|
|
||||||
@@ -67,8 +67,9 @@ contents are automatically included in the package list.
|
|||||||
| Flag | Alias | Description |
|
| Flag | Alias | Description |
|
||||||
|------|-------|-------------|
|
|------|-------|-------------|
|
||||||
| `--state` | `-s` | State file(s) to read package list from (can be used multiple times) |
|
| `--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 |
|
| `--dry-run` | | Preview changes without applying them |
|
||||||
|
| `--prune` | | Mark packages as explicit and cleanup orphans |
|
||||||
| `--verbose` | `-v` | Enable verbose output |
|
| `--verbose` | `-v` | Enable verbose output |
|
||||||
| `--help` | `-h` | Show help message |
|
| `--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
|
3. **Categorize** — Check if packages are in official repos or AUR
|
||||||
4. **Sync** — Install/update packages via pacman
|
4. **Sync** — Install/update packages via pacman
|
||||||
5. **Build** — Build and install AUR packages via makepkg
|
5. **Build** — Build and install AUR packages via makepkg
|
||||||
6. **Mark** — Mark declared packages as explicit, all others as dependencies
|
6. **Mark** (with `--prune`) — Mark declared packages as explicit, all others as dependencies
|
||||||
7. **Cleanup** — Remove orphaned packages
|
7. **Cleanup** (with `--prune`) — Remove orphaned packages
|
||||||
|
|
||||||
### Database Freshness
|
### Database Freshness
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -19,6 +19,7 @@ type Config struct {
|
|||||||
StateFiles []string
|
StateFiles []string
|
||||||
NoCheck bool
|
NoCheck bool
|
||||||
DryRun bool
|
DryRun bool
|
||||||
|
Prune bool
|
||||||
Verbose bool
|
Verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +46,11 @@ func main() {
|
|||||||
Usage: "Simulate the sync without making changes",
|
Usage: "Simulate the sync without making changes",
|
||||||
Destination: &cfg.DryRun,
|
Destination: &cfg.DryRun,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "prune",
|
||||||
|
Usage: "Mark packages and cleanup orphans",
|
||||||
|
Destination: &cfg.Prune,
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "verbose",
|
Name: "verbose",
|
||||||
Aliases: []string{"v"},
|
Aliases: []string{"v"},
|
||||||
@@ -97,7 +103,7 @@ func run(cfg *Config) error {
|
|||||||
}
|
}
|
||||||
defer log.Close()
|
defer log.Close()
|
||||||
|
|
||||||
result, err := pacman.Sync(merged, cfg.NoCheck)
|
result, err := pacman.Sync(merged, cfg.NoCheck, cfg.Prune)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
return err
|
return err
|
||||||
|
|||||||
+17
-12
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/Riyyi/declpac/pkg/pacman/sync"
|
"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()
|
start := time.Now()
|
||||||
log.Debug("Sync: starting...")
|
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: AUR package %s installed (%.2fs)", pkg, time.Since(start).Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Sync: marking all as deps...")
|
var removed int
|
||||||
markAllAsDeps()
|
if prune {
|
||||||
log.Debug("Sync: all marked as deps (%.2fs)", time.Since(start).Seconds())
|
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...")
|
log.Debug("Sync: marking state packages as explicit...")
|
||||||
if err := sync.MarkAs(packages, "explicit", log.GetLogWriter()); err != nil {
|
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)
|
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: state packages marked as explicit (%.2fs)", time.Since(start).Seconds())
|
||||||
|
|
||||||
removed, err := cleanupOrphans()
|
removed, err = cleanupOrphans()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list, _ = read.List()
|
list, _ = read.List()
|
||||||
|
|||||||
Reference in New Issue
Block a user