Compare commits

..

No commits in common. 'ccf64ce8678b607913b8bf95f01fed44e4cd7ca1' and 'b1a376dbbeaa03ab7d3cd1c0dec18002675179e9' have entirely different histories.

  1. 376
      .opencode/package-lock.json
  2. 26
      AGENTS.md
  3. 7
      Makefile
  4. 56
      PackageProvides.md
  5. 18
      README.md
  6. 1
      asd
  7. 1
      asd2
  8. 22
      cmd/declpac/main.go
  9. 1659
      command-output
  10. 254
      output
  11. 236
      packages
  12. 115
      pkg/fetch/alpm/alpm.go
  13. 14
      pkg/fetch/aur/aur.go
  14. 36
      pkg/fetch/fetch.go
  15. 71
      pkg/input/input.go
  16. 34
      pkg/log/log.go
  17. 9
      pkg/merge/merge.go
  18. 9
      pkg/output/output.go
  19. 81
      pkg/pacman/pacman.go
  20. 110
      pkg/pacman/read/read.go
  21. 254
      pkg/pacman/sync/sync.go
  22. 142
      scenario-dependencies-renamed

376
.opencode/package-lock.json generated

@ -1,376 +0,0 @@
{
"name": ".opencode",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@opencode-ai/plugin": "1.14.17"
}
},
"node_modules/@msgpackr-extract/msgpackr-extract-darwin-arm64": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.3.tgz",
"integrity": "sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-darwin-x64": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-x64/-/msgpackr-extract-darwin-x64-3.0.3.tgz",
"integrity": "sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-linux-arm": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm/-/msgpackr-extract-linux-arm-3.0.3.tgz",
"integrity": "sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw==",
"cpu": [
"arm"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-linux-arm64": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm64/-/msgpackr-extract-linux-arm64-3.0.3.tgz",
"integrity": "sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-linux-x64": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-3.0.3.tgz",
"integrity": "sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-win32-x64": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-3.0.3.tgz",
"integrity": "sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@opencode-ai/plugin": {
"version": "1.14.17",
"resolved": "https://registry.npmjs.org/@opencode-ai/plugin/-/plugin-1.14.17.tgz",
"integrity": "sha512-duZbNClMsIR1rmYGsrkA92BuGKkH2TsXk1TpPNBASVukVXSSz2jLdhe1UkSeNVXiDg/aGT52yVgitga3rV8qWw==",
"license": "MIT",
"dependencies": {
"@opencode-ai/sdk": "1.14.17",
"effect": "4.0.0-beta.48",
"zod": "4.1.8"
},
"peerDependencies": {
"@opentui/core": ">=0.1.100",
"@opentui/solid": ">=0.1.100"
},
"peerDependenciesMeta": {
"@opentui/core": {
"optional": true
},
"@opentui/solid": {
"optional": true
}
}
},
"node_modules/@opencode-ai/sdk": {
"version": "1.14.17",
"resolved": "https://registry.npmjs.org/@opencode-ai/sdk/-/sdk-1.14.17.tgz",
"integrity": "sha512-Q42C4VsczrPc+8hB76OO18KZ3A3l4cRHy31Vn8if7W/02qHAA1JoQXbbZD9/9fBqHHyYXC6h9dd4H4TaBi53Zw==",
"license": "MIT",
"dependencies": {
"cross-spawn": "7.0.6"
}
},
"node_modules/@standard-schema/spec": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",
"integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==",
"license": "MIT"
},
"node_modules/cross-spawn": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
"license": "MIT",
"dependencies": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
"which": "^2.0.1"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/detect-libc": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
"license": "Apache-2.0",
"optional": true,
"engines": {
"node": ">=8"
}
},
"node_modules/effect": {
"version": "4.0.0-beta.48",
"resolved": "https://registry.npmjs.org/effect/-/effect-4.0.0-beta.48.tgz",
"integrity": "sha512-MMAM/ZabuNdNmgXiin+BAanQXK7qM8mlt7nfXDoJ/Gn9V8i89JlCq+2N0AiWmqFLXjGLA0u3FjiOjSOYQk5uMw==",
"license": "MIT",
"dependencies": {
"@standard-schema/spec": "^1.1.0",
"fast-check": "^4.6.0",
"find-my-way-ts": "^0.1.6",
"ini": "^6.0.0",
"kubernetes-types": "^1.30.0",
"msgpackr": "^1.11.9",
"multipasta": "^0.2.7",
"toml": "^4.1.1",
"uuid": "^13.0.0",
"yaml": "^2.8.3"
}
},
"node_modules/fast-check": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/fast-check/-/fast-check-4.7.0.tgz",
"integrity": "sha512-NsZRtqvSSoCP0HbNjUD+r1JH8zqZalyp6gLY9e7OYs7NK9b6AHOs2baBFeBG7bVNsuoukh89x2Yg3rPsul8ziQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/dubzzz"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fast-check"
}
],
"license": "MIT",
"dependencies": {
"pure-rand": "^8.0.0"
},
"engines": {
"node": ">=12.17.0"
}
},
"node_modules/find-my-way-ts": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/find-my-way-ts/-/find-my-way-ts-0.1.6.tgz",
"integrity": "sha512-a85L9ZoXtNAey3Y6Z+eBWW658kO/MwR7zIafkIUPUMf3isZG0NCs2pjW2wtjxAKuJPxMAsHUIP4ZPGv0o5gyTA==",
"license": "MIT"
},
"node_modules/ini": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/ini/-/ini-6.0.0.tgz",
"integrity": "sha512-IBTdIkzZNOpqm7q3dRqJvMaldXjDHWkEDfrwGEQTs5eaQMWV+djAhR+wahyNNMAa+qpbDUhBMVt4ZKNwpPm7xQ==",
"license": "ISC",
"engines": {
"node": "^20.17.0 || >=22.9.0"
}
},
"node_modules/isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
"license": "ISC"
},
"node_modules/kubernetes-types": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/kubernetes-types/-/kubernetes-types-1.30.0.tgz",
"integrity": "sha512-Dew1okvhM/SQcIa2rcgujNndZwU8VnSapDgdxlYoB84ZlpAD43U6KLAFqYo17ykSFGHNPrg0qry0bP+GJd9v7Q==",
"license": "Apache-2.0"
},
"node_modules/msgpackr": {
"version": "1.11.10",
"resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.11.10.tgz",
"integrity": "sha512-iCZNq+HszvF+fC3anCm4nBmWEnbeIAfpDs6IStAEKhQ2YSgkjzVG2FF9XJqwwQh5bH3N9OUTUt4QwVN6MLMLtA==",
"license": "MIT",
"optionalDependencies": {
"msgpackr-extract": "^3.0.2"
}
},
"node_modules/msgpackr-extract": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/msgpackr-extract/-/msgpackr-extract-3.0.3.tgz",
"integrity": "sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA==",
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"dependencies": {
"node-gyp-build-optional-packages": "5.2.2"
},
"bin": {
"download-msgpackr-prebuilds": "bin/download-prebuilds.js"
},
"optionalDependencies": {
"@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.3",
"@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.3",
"@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.3",
"@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.3",
"@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.3",
"@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.3"
}
},
"node_modules/multipasta": {
"version": "0.2.7",
"resolved": "https://registry.npmjs.org/multipasta/-/multipasta-0.2.7.tgz",
"integrity": "sha512-KPA58d68KgGil15oDqXjkUBEBYc00XvbPj5/X+dyzeo/lWm9Nc25pQRlf1D+gv4OpK7NM0J1odrbu9JNNGvynA==",
"license": "MIT"
},
"node_modules/node-gyp-build-optional-packages": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.2.2.tgz",
"integrity": "sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw==",
"license": "MIT",
"optional": true,
"dependencies": {
"detect-libc": "^2.0.1"
},
"bin": {
"node-gyp-build-optional-packages": "bin.js",
"node-gyp-build-optional-packages-optional": "optional.js",
"node-gyp-build-optional-packages-test": "build-test.js"
}
},
"node_modules/path-key": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/pure-rand": {
"version": "8.4.0",
"resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-8.4.0.tgz",
"integrity": "sha512-IoM8YF/jY0hiugFo/wOWqfmarlE6J0wc6fDK1PhftMk7MGhVZl88sZimmqBBFomLOCSmcCCpsfj7wXASCpvK9A==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/dubzzz"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fast-check"
}
],
"license": "MIT"
},
"node_modules/shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
"license": "MIT",
"dependencies": {
"shebang-regex": "^3.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/shebang-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/toml": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/toml/-/toml-4.1.1.tgz",
"integrity": "sha512-EBJnVBr3dTXdA89WVFoAIPUqkBjxPMwRqsfuo1r240tKFHXv3zgca4+NJib/h6TyvGF7vOawz0jGuryJCdNHrw==",
"license": "MIT",
"engines": {
"node": ">=20"
}
},
"node_modules/uuid": {
"version": "13.0.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-13.0.0.tgz",
"integrity": "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w==",
"funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
"license": "MIT",
"bin": {
"uuid": "dist-node/bin/uuid"
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"license": "ISC",
"dependencies": {
"isexe": "^2.0.0"
},
"bin": {
"node-which": "bin/node-which"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/yaml": {
"version": "2.8.3",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.3.tgz",
"integrity": "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14.6"
},
"funding": {
"url": "https://github.com/sponsors/eemeli"
}
},
"node_modules/zod": {
"version": "4.1.8",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
}
}
}

26
AGENTS.md

@ -2,30 +2,6 @@
## Skills: Always Active ## Skills: Always Active
At the start of every conversation, load the following skills using the `skill` At the start of every conversation, load the following skills using the `skill` tool before responding to the user:
tool before responding to the user:
1. **caveman** — Always use caveman mode (full intensity) for all responses 1. **caveman** — Always use caveman mode (full intensity) for all responses
## Code Organization
### Go: File Structure
- Variables must appear at the top of each file.
- Types must appear after variables.
- Constructors must appear after types.
- Public (exported) functions must appear after constructors.
- Private (unexported) functions must appear at the bottom of each file.
- Within each section, definitions must be sorted alphabetically by name.
- The sections must be separated by exactly these dividers, filling in the section:
// -----------------------------------------
// <section>
### Go: Line Length
Keep Go lines as short as reasonably possible.
- **Hard limit:** 120 characters — never exceed this.
- **Preferred:** 100 characters or fewer in normal cases.
- **Target:** 80 characters if breaking the line produces cleaner, more readable
code (e.g. chained calls, long argument lists, multi-condition `if` statements).

7
Makefile

@ -1,4 +1,4 @@
.PHONY: build fmt fmtcheck vet check githook install uninstall .PHONY: build fmt vet check githook install uninstall
PKG := github.com/Riyyi/declpac PKG := github.com/Riyyi/declpac
BIN := declpac BIN := declpac
@ -15,9 +15,6 @@ build:
go build -o $(BUILD) ./cmd/declpac go build -o $(BUILD) ./cmd/declpac
fmt: fmt:
@gofmt -w cmd pkg
fmtcheck:
@if [ -z "$(STAGED_GO)" ]; then exit 0; fi; \ @if [ -z "$(STAGED_GO)" ]; then exit 0; fi; \
unformatted=$$(gofmt -l $(STAGED_GO)); \ unformatted=$$(gofmt -l $(STAGED_GO)); \
if [ -n "$$unformatted" ]; then \ if [ -n "$$unformatted" ]; then \
@ -29,7 +26,7 @@ vet:
@if [ -z "$(STAGED_GO)" ]; then exit 0; fi; \ @if [ -z "$(STAGED_GO)" ]; then exit 0; fi; \
go vet $(STAGED_PKGS) go vet $(STAGED_PKGS)
check: fmtcheck vet check: fmt vet
githook: githook:
@mkdir -p .git/hooks @mkdir -p .git/hooks

56
PackageProvides.md

@ -1,56 +0,0 @@
# Checking if a Package is Provided by Another Package
## Using FindDBSatisfier
The `FindDBSatisfier` method in the handle finds a package that satisfies a given dependency string across sync databases. It automatically resolves `Provides` relationships.
### Basic Usage
```go
// Given a package name "foo", find which package provides it
h := dyalpm.NewHandle(...)
dbs := h.SyncDBS()
// This finds ANY package that satisfies "foo" - including via Provides
provider := h.FindDBSatisfier(dbs, "foo")
if provider != nil {
// The package "foo" is provided by provider.Name()
}
```
### How It Works
When you search for a package "foo", ALPM will find packages that:
1. Are named "foo"
2. Have `Provides: foo` in their metadata
### Full Example
```go
h, err := dyalpm.NewHandle(rootDir, cacheDir, dyalpm.ArchLinux)
if err != nil {
// handle error
}
syncDBs, err := h.SyncDBS()
if err != nil {
// handle error
}
// Search for "foo" package (may be provided by another package)
targetName := "foo"
provider := h.FindDBSatisfier(syncDBs, targetName)
if provider != nil {
fmt.Printf("%s is provided by: %s\n", targetName, provider.Name())
fmt.Printf("Version: %s\n", provider.Version())
} else {
fmt.Printf("No package found providing: %s\n", targetName)
}
```
## Related Functions
- `FindSatisfier(pkgs []Package, depstring)` - Same concept but for an in-memory package list
- `PackageIterator.FindSatisfier(depstring)` - Works on iterator results from `db.Search()`
- `pkg.Provides() []Depend` - Get what a package provides (see `package.go:144`)

18
README.md

@ -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
- Explicit package tracking — marks declared packages as explicit (with `--prune`) - Smart orphan cleanup — removes packages no longer needed
- Smart orphan cleanup — removes packages no longer needed (with `--prune`) - Explicit package tracking — marks declared packages as explicit
- 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
@ -57,19 +57,12 @@ docker
# this is a comment # this is a comment
``` ```
### Implicit State File
If `$XDG_CONFIG_HOME/declpac` (or `~/.config/declpac` on fallback) exists, its
contents are automatically included in the package list.
### Options ### Options
| 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 to read package list from (can be used multiple times) |
| `--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 |
@ -80,8 +73,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** (with `--prune`) — Mark declared packages as explicit, all others as dependencies 6. **Mark** — Mark declared packages as explicit, all others as dependencies
7. **Cleanup** (with `--prune`) — Remove orphaned packages 7. **Cleanup** — Remove orphaned packages
### Database Freshness ### Database Freshness
@ -121,6 +114,7 @@ declpac/
│ └── main.go # Entry point │ └── main.go # Entry point
├── pkg/ ├── pkg/
│ ├── input/ # State file/stdin reading │ ├── input/ # State file/stdin reading
│ ├── merge/ # Package merging
│ ├── fetch/ # Package resolution │ ├── fetch/ # Package resolution
│ │ ├── aur/ # AUR support │ │ ├── aur/ # AUR support
│ │ └── alpm/ # ALPM support │ │ └── alpm/ # ALPM support

1
asd

@ -1 +0,0 @@
hexchat

1
asd2

@ -1 +0,0 @@
noctalia-shell

22
cmd/declpac/main.go

@ -10,6 +10,7 @@ import (
"github.com/Riyyi/declpac/pkg/input" "github.com/Riyyi/declpac/pkg/input"
"github.com/Riyyi/declpac/pkg/log" "github.com/Riyyi/declpac/pkg/log"
"github.com/Riyyi/declpac/pkg/merge"
"github.com/Riyyi/declpac/pkg/output" "github.com/Riyyi/declpac/pkg/output"
"github.com/Riyyi/declpac/pkg/pacman" "github.com/Riyyi/declpac/pkg/pacman"
"github.com/Riyyi/declpac/pkg/pacman/read" "github.com/Riyyi/declpac/pkg/pacman/read"
@ -17,9 +18,8 @@ import (
type Config struct { type Config struct {
StateFiles []string StateFiles []string
NoCheck bool NoConfirm bool
DryRun bool DryRun bool
Prune bool
Verbose bool Verbose bool
} }
@ -36,21 +36,11 @@ func main() {
Usage: "State file(s) to read package list from", Usage: "State file(s) to read package list from",
Destination: &cfg.StateFiles, Destination: &cfg.StateFiles,
}, },
&cli.BoolFlag{
Name: "nocheck",
Usage: "Skip safety check",
Destination: &cfg.NoCheck,
},
&cli.BoolFlag{ &cli.BoolFlag{
Name: "dry-run", Name: "dry-run",
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"},
@ -80,11 +70,7 @@ func run(cfg *Config) error {
} }
log.Debug("run: packages read (%.2fs)", time.Since(start).Seconds()) log.Debug("run: packages read (%.2fs)", time.Since(start).Seconds())
merged, err := input.Merge(packages) merged := merge.Merge(packages)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
return err
}
if cfg.DryRun { if cfg.DryRun {
result, err := read.DryRun(merged) result, err := read.DryRun(merged)
@ -103,7 +89,7 @@ func run(cfg *Config) error {
} }
defer log.Close() defer log.Close()
result, err := pacman.Sync(merged, cfg.NoCheck, cfg.Prune) result, err := pacman.Sync(merged)
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

1659
command-output

File diff suppressed because it is too large Load Diff

254
output

@ -1,254 +0,0 @@
[debug] run: starting...
[debug] run: packages read (0.00s)
[debug] CheckDBFreshness: starting...
[debug] Sync: starting...
[debug] getInstalledCount: starting...
[debug] getInstalledCount: done (0.01s)
[debug] CheckDBFreshness: starting...
[debug] Sync: database fresh (0.01s)
[debug] Fetcher New: starting...
[debug] registerSyncDBs: starting...
[debug] registerSyncDBs: done (3 dbs)
[debug] Fetcher New: done (0.13s)
[debug] Sync: initialized fetcher (0.13s)
[debug] Sync: categorizing packages...
[debug] categorizePackages: starting...
[debug] Resolve: starting...
[debug] buildLocalPkgMap: starting...
[debug] buildLocalPkgMap: done (0.00s)
[debug] Resolve: local pkgs built (0.00s)
[debug] checkSyncDBs: starting...
[debug] checkSyncDBs: done (0.00s)
[debug] ensureAURCache: starting...
[debug] fetchAURInfo: starting...
[debug] fetchAURInfo: done (0.20s)
[debug] ensureAURCache: done (0.20s)
[debug] Resolve: done (0.21s)
[debug] categorizePackages: done (0.21s)
[debug] Sync: packages categorized (0.34s)
[debug] Sync: syncing 183 pacman packages...
[debug] SyncPackages: starting...
error: pacman sync failed: warning: texlab-5.25.1-1 is up to date -- skipping
warning: wpa_supplicant-2:2.11-5 is up to date -- skipping
warning: kcachegrind-25.12.3-1 is up to date -- skipping
warning: kdenlive-25.12.3-1 is up to date -- skipping
warning: aspell-en-2026.02.25-1 is up to date -- skipping
warning: dialog-1:1.3_20260107-1 is up to date -- skipping
warning: duf-0.9.1-1 is up to date -- skipping
warning: ffmpegthumbnailer-2.3.0-1 is up to date -- skipping
warning: python-certifi-2026.02.25-1 is up to date -- skipping
warning: base-3-3 is up to date -- skipping
warning: hunspell-1.7.2-3 is up to date -- skipping
warning: hunspell-nl-2.20.19-5 is up to date -- skipping
warning: ttf-dejavu-nerd-3.4.0-2 is up to date -- skipping
warning: vim-spell-en-20220628-2 is up to date -- skipping
warning: hunspell-en_us-2026.02.25-1 is up to date -- skipping
warning: pacman-contrib-1.13.1-1 is up to date -- skipping
warning: unzip-6.0-23 is up to date -- skipping
warning: base-devel-1-2 is up to date -- skipping
warning: sysfsutils-2.1.1-2 is up to date -- skipping
warning: imv-5.0.1-1 is up to date -- skipping
warning: otf-font-awesome-7.2.0-1 is up to date -- skipping
warning: python-zstandard-0.25.0-2 is up to date -- skipping
warning: socat-1.8.1.1-1 is up to date -- skipping
warning: wget-1.25.0-3 is up to date -- skipping
warning: zsh-completions-0.36.0-1 is up to date -- skipping
warning: python-adblock-0.6.0-5 is up to date -- skipping
warning: gammastep-2.0.11-2 is up to date -- skipping
warning: nwg-look-1.0.6-1 is up to date -- skipping
warning: man-pages-6.17-1 is up to date -- skipping
warning: inetutils-2.7-2 is up to date -- skipping
warning: kolourpaint-25.12.3-1 is up to date -- skipping
warning: thunar-volman-4.20.0-2 is up to date -- skipping
warning: valgrind-3.25.1-4 is up to date -- skipping
warning: dnsmasq-2.92-1 is up to date -- skipping
warning: evtest-1.36-1 is up to date -- skipping
warning: rtmpdump-1:2.6-1 is up to date -- skipping
warning: man-db-2.13.1-1 is up to date -- skipping
warning: ncdu-2.9.2-1 is up to date -- skipping
warning: jq-1.8.1-1 is up to date -- skipping
warning: qt5ct-1.9-1 is up to date -- skipping
warning: linux-firmware-20260309-1 is up to date -- skipping
warning: mpv-1:0.41.0-3 is up to date -- skipping
warning: waybar-0.15.0-2 is up to date -- skipping
warning: capitaine-cursors-4-3 is up to date -- skipping
warning: exfat-utils-1.4.0-4 is up to date -- skipping
warning: qt5-tools-5.15.18+kde+r3-2 is up to date -- skipping
warning: ydotool-1.0.4-2 is up to date -- skipping
warning: isync-1.5.1-2 is up to date -- skipping
warning: namcap-3.6.0-3 is up to date -- skipping
warning: qt5-serialport-5.15.18-1 is up to date -- skipping
warning: kvantum-qt5-1.1.6-1 is up to date -- skipping
warning: 7zip-26.00-1 is up to date -- skipping
warning: aspell-nl-0.50.2-8 is up to date -- skipping
warning: python-beautifulsoup4-4.14.3-2 is up to date -- skipping
warning: gnome-themes-extra-1:3.28-1 is up to date -- skipping
warning: mesa-demos-9.0.0-7 is up to date -- skipping
warning: mysql-workbench-8.0.46-1 is up to date -- skipping
warning: vim-spell-nl-20220628-2 is up to date -- skipping
warning: xf86-input-wacom-1.2.4-1 is up to date -- skipping
warning: kvantum-1.1.6-1 is up to date -- skipping
warning: efibootmgr-18-3 is up to date -- skipping
warning: ntfs-3g-2022.10.3-2 is up to date -- skipping
warning: tokei-14.0.0-1 is up to date -- skipping
warning: python-pycurl-7.45.7-3 is up to date -- skipping
warning: rofi-2.0.0-1 is up to date -- skipping
warning: r-4.5.3-1 is up to date -- skipping
warning: smartmontools-7.5-1 is up to date -- skipping
warning: acpi-1.8-2 is up to date -- skipping
warning: reflector-2023-5 is up to date -- skipping
warning: tlp-1.9.1-1 is up to date -- skipping
warning: rtkit-0.14-1 is up to date -- skipping
warning: lib32-glibc-2.43+r5+g856c426a7534-1 is up to date -- skipping
warning: mariadb-12.2.2-2 is up to date -- skipping
warning: brightnessctl-0.5.1-3 is up to date -- skipping
warning: usbutils-019-1 is up to date -- skipping
warning: amd-ucode-20260309-1 is up to date -- skipping
warning: lib32-openal-1.25.1-1 is up to date -- skipping
warning: pavucontrol-1:6.2-1 is up to date -- skipping
warning: python-pyusb-1.3.1-2 is up to date -- skipping
warning: aria2-1.37.0-2 is up to date -- skipping
warning: git-2.53.0-1 is up to date -- skipping
warning: python-matplotlib-3.10.8-5 is up to date -- skipping
warning: iw-6.17-1 is up to date -- skipping
warning: ark-25.12.3-1 is up to date -- skipping
warning: grim-1.5.0-2 is up to date -- skipping
warning: python-watchdog-6.0.0-2 is up to date -- skipping
warning: nlohmann-json-3.12.0-2 is up to date -- skipping
warning: netctl-1.29-2 is up to date -- skipping
warning: rsync-3.4.1-2 is up to date -- skipping
warning: sqlitebrowser-3.13.1-3 is up to date -- skipping
warning: tumbler-4.20.1-1 is up to date -- skipping
warning: python-opengl-3.1.10-3 is up to date -- skipping
warning: sshfs-3.7.5-1 is up to date -- skipping
resolving dependencies...
looking for conflicting packages...
error: failed to prepare transaction (could not satisfy dependencies)
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by aquamarine
:: installing libvpx (1.16.0-3) breaks dependency 'libvpx.so=11-64' required by ffmpeg
:: installing gst-plugins-base-libs (1.28.2-1) breaks dependency 'gst-plugins-base-libs=1.28.1-1' required by gst-plugins-bad-libs
:: installing gstreamer (1.28.2-1) breaks dependency 'gstreamer=1.28.1-1' required by gst-plugins-bad-libs
:: installing gst-plugins-base-libs (1.28.2-1) breaks dependency 'gst-plugins-base-libs=1.28.1-1' required by gst-plugins-base
:: installing gstreamer (1.28.2-1) breaks dependency 'gstreamer=1.28.1-1' required by gst-plugins-base
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprgraphics
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprland-guiutils
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprlang
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprtoolkit
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprwire
:: installing libpipewire (1:1.6.3-1) breaks dependency 'libpipewire=1:1.6.1-1' required by pipewire-jack
:: installing pipewire-audio (1:1.6.3-1) breaks dependency 'pipewire-audio=1:1.6.1-1' required by pipewire-jack
:: installing pipewire (1:1.6.3-1) breaks dependency 'pipewire=1:1.6.1-1' required by pipewire-jack
:: installing poppler (26.04.0-1) breaks dependency 'poppler=26.02.0' required by poppler-qt6
error: pacman sync failed: warning: texlab-5.25.1-1 is up to date -- skipping
warning: wpa_supplicant-2:2.11-5 is up to date -- skipping
warning: kcachegrind-25.12.3-1 is up to date -- skipping
warning: kdenlive-25.12.3-1 is up to date -- skipping
warning: aspell-en-2026.02.25-1 is up to date -- skipping
warning: dialog-1:1.3_20260107-1 is up to date -- skipping
warning: duf-0.9.1-1 is up to date -- skipping
warning: ffmpegthumbnailer-2.3.0-1 is up to date -- skipping
warning: python-certifi-2026.02.25-1 is up to date -- skipping
warning: base-3-3 is up to date -- skipping
warning: hunspell-1.7.2-3 is up to date -- skipping
warning: hunspell-nl-2.20.19-5 is up to date -- skipping
warning: ttf-dejavu-nerd-3.4.0-2 is up to date -- skipping
warning: vim-spell-en-20220628-2 is up to date -- skipping
warning: hunspell-en_us-2026.02.25-1 is up to date -- skipping
warning: pacman-contrib-1.13.1-1 is up to date -- skipping
warning: unzip-6.0-23 is up to date -- skipping
warning: base-devel-1-2 is up to date -- skipping
warning: sysfsutils-2.1.1-2 is up to date -- skipping
warning: imv-5.0.1-1 is up to date -- skipping
warning: otf-font-awesome-7.2.0-1 is up to date -- skipping
warning: python-zstandard-0.25.0-2 is up to date -- skipping
warning: socat-1.8.1.1-1 is up to date -- skipping
warning: wget-1.25.0-3 is up to date -- skipping
warning: zsh-completions-0.36.0-1 is up to date -- skipping
warning: python-adblock-0.6.0-5 is up to date -- skipping
warning: gammastep-2.0.11-2 is up to date -- skipping
warning: nwg-look-1.0.6-1 is up to date -- skipping
warning: man-pages-6.17-1 is up to date -- skipping
warning: inetutils-2.7-2 is up to date -- skipping
warning: kolourpaint-25.12.3-1 is up to date -- skipping
warning: thunar-volman-4.20.0-2 is up to date -- skipping
warning: valgrind-3.25.1-4 is up to date -- skipping
warning: dnsmasq-2.92-1 is up to date -- skipping
warning: evtest-1.36-1 is up to date -- skipping
warning: rtmpdump-1:2.6-1 is up to date -- skipping
warning: man-db-2.13.1-1 is up to date -- skipping
warning: ncdu-2.9.2-1 is up to date -- skipping
warning: jq-1.8.1-1 is up to date -- skipping
warning: qt5ct-1.9-1 is up to date -- skipping
warning: linux-firmware-20260309-1 is up to date -- skipping
warning: mpv-1:0.41.0-3 is up to date -- skipping
warning: waybar-0.15.0-2 is up to date -- skipping
warning: capitaine-cursors-4-3 is up to date -- skipping
warning: exfat-utils-1.4.0-4 is up to date -- skipping
warning: qt5-tools-5.15.18+kde+r3-2 is up to date -- skipping
warning: ydotool-1.0.4-2 is up to date -- skipping
warning: isync-1.5.1-2 is up to date -- skipping
warning: namcap-3.6.0-3 is up to date -- skipping
warning: qt5-serialport-5.15.18-1 is up to date -- skipping
warning: kvantum-qt5-1.1.6-1 is up to date -- skipping
warning: 7zip-26.00-1 is up to date -- skipping
warning: aspell-nl-0.50.2-8 is up to date -- skipping
warning: python-beautifulsoup4-4.14.3-2 is up to date -- skipping
warning: gnome-themes-extra-1:3.28-1 is up to date -- skipping
warning: mesa-demos-9.0.0-7 is up to date -- skipping
warning: mysql-workbench-8.0.46-1 is up to date -- skipping
warning: vim-spell-nl-20220628-2 is up to date -- skipping
warning: xf86-input-wacom-1.2.4-1 is up to date -- skipping
warning: kvantum-1.1.6-1 is up to date -- skipping
warning: efibootmgr-18-3 is up to date -- skipping
warning: ntfs-3g-2022.10.3-2 is up to date -- skipping
warning: tokei-14.0.0-1 is up to date -- skipping
warning: python-pycurl-7.45.7-3 is up to date -- skipping
warning: rofi-2.0.0-1 is up to date -- skipping
warning: r-4.5.3-1 is up to date -- skipping
warning: smartmontools-7.5-1 is up to date -- skipping
warning: acpi-1.8-2 is up to date -- skipping
warning: reflector-2023-5 is up to date -- skipping
warning: tlp-1.9.1-1 is up to date -- skipping
warning: rtkit-0.14-1 is up to date -- skipping
warning: lib32-glibc-2.43+r5+g856c426a7534-1 is up to date -- skipping
warning: mariadb-12.2.2-2 is up to date -- skipping
warning: brightnessctl-0.5.1-3 is up to date -- skipping
warning: usbutils-019-1 is up to date -- skipping
warning: amd-ucode-20260309-1 is up to date -- skipping
warning: lib32-openal-1.25.1-1 is up to date -- skipping
warning: pavucontrol-1:6.2-1 is up to date -- skipping
warning: python-pyusb-1.3.1-2 is up to date -- skipping
warning: aria2-1.37.0-2 is up to date -- skipping
warning: git-2.53.0-1 is up to date -- skipping
warning: python-matplotlib-3.10.8-5 is up to date -- skipping
warning: iw-6.17-1 is up to date -- skipping
warning: ark-25.12.3-1 is up to date -- skipping
warning: grim-1.5.0-2 is up to date -- skipping
warning: python-watchdog-6.0.0-2 is up to date -- skipping
warning: nlohmann-json-3.12.0-2 is up to date -- skipping
warning: netctl-1.29-2 is up to date -- skipping
warning: rsync-3.4.1-2 is up to date -- skipping
warning: sqlitebrowser-3.13.1-3 is up to date -- skipping
warning: tumbler-4.20.1-1 is up to date -- skipping
warning: python-opengl-3.1.10-3 is up to date -- skipping
warning: sshfs-3.7.5-1 is up to date -- skipping
resolving dependencies...
looking for conflicting packages...
error: failed to prepare transaction (could not satisfy dependencies)
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by aquamarine
:: installing libvpx (1.16.0-3) breaks dependency 'libvpx.so=11-64' required by ffmpeg
:: installing gst-plugins-base-libs (1.28.2-1) breaks dependency 'gst-plugins-base-libs=1.28.1-1' required by gst-plugins-bad-libs
:: installing gstreamer (1.28.2-1) breaks dependency 'gstreamer=1.28.1-1' required by gst-plugins-bad-libs
:: installing gst-plugins-base-libs (1.28.2-1) breaks dependency 'gst-plugins-base-libs=1.28.1-1' required by gst-plugins-base
:: installing gstreamer (1.28.2-1) breaks dependency 'gstreamer=1.28.1-1' required by gst-plugins-base
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprgraphics
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprland-guiutils
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprlang
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprtoolkit
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprwire
:: installing libpipewire (1:1.6.3-1) breaks dependency 'libpipewire=1:1.6.1-1' required by pipewire-jack
:: installing pipewire-audio (1:1.6.3-1) breaks dependency 'pipewire-audio=1:1.6.1-1' required by pipewire-jack
:: installing pipewire (1:1.6.3-1) breaks dependency 'pipewire=1:1.6.1-1' required by pipewire-jack
:: installing poppler (26.04.0-1) breaks dependency 'poppler=26.02.0' required by poppler-qt6

236
packages

@ -1,236 +0,0 @@
7zip
acpi
adobe-source-han-sans-jp-fonts
adw-gtk-theme
amd-ucode
android-studio
arc-icon-theme
archlinux-keyring
aria2
ark
aspell-en
aspell-nl
base
base-devel
bc
blender
brightnessctl
bun-bin
capitaine-cursors
cbindgen
checkbashisms
chromium
clang
cmake
dbeaver
declpac-git
dhcpcd
dialog
dnsmasq
dos2unix
downgrade
duf
dunst
dxvk-bin
easyeda-pro-bin
efibootmgr
emacs-wayland
evtest
exfat-utils
fastfetch
ffmpegthumbnailer
firefox
freecad
gamescope
gammastep
gdb
gedit
ghostty
git
gnome-calculator
gnome-keyring
gnome-themes-extra
gopls
gparted
grim
gst-plugins-good
gucharmap
gvfs
gvfs-gphoto2
gvfs-mtp
gvim
hexchat
htop
hunspell
hunspell-en_us
hunspell-nl
hypridle
hyprland
hyprlock
hyprpaper
hyprpolkitagent
icu76
imagemagick
imake
imv
inetutils
inkscape
ipfs-desktop-bin
isync
iw
jdownloader2
jq
kcachegrind
kdenlive
keepmenu-git
kolourpaint
krita
kvantum
kvantum-qt5
lib32-glibc
lib32-mesa
lib32-openal
lib32-vkd3d-proton-git
lib32-vulkan-radeon
libvirt
linux
linux-firmware
linux-headers
linux-lts
linux-lts-headers
llvm
man-db
man-pages
manafiles-git
mariadb
mesa-demos
mkvtoolnix-cli
moka-icon-theme-git
mokutil
mpv
mu
mysql-workbench
namcap
nasm
ncdu
neovim
netctl
niri-no-decorations
nix
nixfmt
nlohmann-json
nodejs-intelephense
npm
ns-usbloader
ntfs-3g
nwg-look
ollama-rocm
ollama-vulkan
opencode
openssh
otf-font-awesome
pacman-contrib
pamixer
pavucontrol
pdfjs
picard
pipewire-alsa
pipewire-pulse
platformio-core
playwright
poppler-glib
python-adblock
python-beautifulsoup4
python-certifi
python-filelock
python-flask
python-google-api-python-client
python-google-auth-oauthlib
python-matplotlib
python-opengl
python-pycurl
python-pyqt5
python-pyusb
python-watchdog
python-zstandard
qbittorrent
qt5-declarative
qt5-serialport
qt5-tools
qt5-wayland
qt5ct
qt6ct
r
reflector
rofi
rsync
rtkit
rtmpdump
rust
signal-desktop
slurp
smartmontools
socat
sqlitebrowser
sshfs
steam
streamlink
sunshine-bin
syncthing
sysfsutils
texlab
texlive-bibtexextra
texlive-fontsextra
texlive-formatsextra
texlive-games
texlive-humanities
texlive-latexextra
texlive-mathscience
texlive-music
texlive-pictures
texlive-pstricks
texlive-publishers
thunar
thunar-volman
thunderbird
tibia
tlp
tokei
tree
trizen
ttf-dejavu
ttf-dejavu-nerd
ttf-joypixels
tumbler
tumbler-extra-thumbnailers
unrar
unzip
usbutils
valgrind
ventoy-bin
vim-spell-en
vim-spell-nl
virt-manager
vkd3d-proton-bin
vulkan-radeon
waybar
wget
wine-staging
winetricks
wl-clipboard
wpa_supplicant
x86_energy_perf_policy
xdg-desktop-portal-hyprland
xf86-input-wacom
xfsprogs
xorg-server-xvfb
yasm
ydotool
yt-dlp
yt-dlp-drop-in
zathura
zathura-pdf-mupdf
zip
zsh
zsh-completions
zsh-syntax-highlighting

115
pkg/fetch/alpm/alpm.go

@ -19,67 +19,6 @@ type Handle struct {
syncDBs []dyalpm.Database syncDBs []dyalpm.Database
} }
func (h *Handle) LocalPackages() (map[string]dyalpm.Package, error) {
start := time.Now()
log.Debug("LocalPackages: starting...")
localPkgs := make(map[string]dyalpm.Package)
err := h.localDB.PkgCache().ForEach(func(pkg dyalpm.Package) error {
localPkgs[pkg.Name()] = pkg
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to iterate local package cache: %w", err)
}
log.Debug("LocalPackages: done (%.2fs)", time.Since(start).Seconds())
return localPkgs, nil
}
func (h *Handle) FindProvidingPackage(depName string) (string, bool) {
pkg := h.handle.FindDBSatisfier(h.syncDBs, depName)
if pkg != nil {
return pkg.Name(), true
}
return "", false
}
func (h *Handle) Release() error {
if h.handle != nil {
h.handle.Release()
}
return nil
}
func (h *Handle) SyncPackages(pkgNames []string) (map[string]dyalpm.Package, error) {
start := time.Now()
log.Debug("SyncPackages: starting...")
syncPkgs := make(map[string]dyalpm.Package)
pkgSet := make(map[string]bool)
for _, name := range pkgNames {
pkgSet[name] = true
}
for _, db := range h.syncDBs {
err := db.PkgCache().ForEach(func(pkg dyalpm.Package) error {
if pkgSet[pkg.Name()] {
if _, exists := syncPkgs[pkg.Name()]; !exists {
syncPkgs[pkg.Name()] = pkg
}
}
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to iterate sync database %s: %w", db.Name(), err)
}
}
log.Debug("SyncPackages: done (%.2fs)", time.Since(start).Seconds())
return syncPkgs, nil
}
func New() (*Handle, error) { func New() (*Handle, error) {
start := time.Now() start := time.Now()
log.Debug("alpm.New: starting...") log.Debug("alpm.New: starting...")
@ -117,8 +56,12 @@ func New() (*Handle, error) {
}, nil }, nil
} }
// ----------------------------------------- func (h *Handle) Release() error {
// private if h.handle != nil {
h.handle.Release()
}
return nil
}
func registerSyncDBs(handle dyalpm.Handle) ([]dyalpm.Database, error) { func registerSyncDBs(handle dyalpm.Handle) ([]dyalpm.Database, error) {
log.Debug("registerSyncDBs: starting...") log.Debug("registerSyncDBs: starting...")
@ -146,3 +89,49 @@ func registerSyncDBs(handle dyalpm.Handle) ([]dyalpm.Database, error) {
log.Debug("registerSyncDBs: done (%d dbs)", len(dbs)) log.Debug("registerSyncDBs: done (%d dbs)", len(dbs))
return dbs, nil return dbs, nil
} }
func (h *Handle) LocalPackages() (map[string]dyalpm.Package, error) {
start := time.Now()
log.Debug("LocalPackages: starting...")
localPkgs := make(map[string]dyalpm.Package)
err := h.localDB.PkgCache().ForEach(func(pkg dyalpm.Package) error {
localPkgs[pkg.Name()] = pkg
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to iterate local package cache: %w", err)
}
log.Debug("LocalPackages: done (%.2fs)", time.Since(start).Seconds())
return localPkgs, nil
}
func (h *Handle) SyncPackages(pkgNames []string) (map[string]dyalpm.Package, error) {
start := time.Now()
log.Debug("SyncPackages: starting...")
syncPkgs := make(map[string]dyalpm.Package)
pkgSet := make(map[string]bool)
for _, name := range pkgNames {
pkgSet[name] = true
}
for _, db := range h.syncDBs {
err := db.PkgCache().ForEach(func(pkg dyalpm.Package) error {
if pkgSet[pkg.Name()] {
if _, exists := syncPkgs[pkg.Name()]; !exists {
syncPkgs[pkg.Name()] = pkg
}
}
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to iterate sync database %s: %w", db.Name(), err)
}
}
log.Debug("SyncPackages: done (%.2fs)", time.Since(start).Seconds())
return syncPkgs, nil
}

14
pkg/fetch/aur/aur.go

@ -13,16 +13,10 @@ import (
var AURInfoURL = "https://aur.archlinux.org/rpc?v=5&type=info" var AURInfoURL = "https://aur.archlinux.org/rpc?v=5&type=info"
type Package struct { type Package struct {
Name string `json:"Name"` Name string `json:"Name"`
PackageBase string `json:"PackageBase"` PackageBase string `json:"PackageBase"`
Version string `json:"Version"` Version string `json:"Version"`
URL string `json:"URL"` URL string `json:"URL"`
Depends []string `json:"Depends"`
MakeDepends []string `json:"MakeDepends"`
}
func (p Package) AllDepends() []string {
return append(p.Depends, p.MakeDepends...)
} }
type Response struct { type Response struct {

36
pkg/fetch/fetch.go

@ -14,7 +14,6 @@ type PackageInfo struct {
InAUR bool InAUR bool
Exists bool Exists bool
Installed bool Installed bool
Provided string
AURInfo *aur.Package AURInfo *aur.Package
} }
@ -23,9 +22,6 @@ type Fetcher struct {
aurClient *aur.Client aurClient *aur.Client
} }
// -----------------------------------------
// constructor
func New() (*Fetcher, error) { func New() (*Fetcher, error) {
start := time.Now() start := time.Now()
log.Debug("fetch.Fetcher New: starting...") log.Debug("fetch.Fetcher New: starting...")
@ -44,8 +40,13 @@ func New() (*Fetcher, error) {
}, nil }, nil
} }
// ----------------------------------------- func (f *Fetcher) Close() error {
// public return f.alpmHandle.Release()
}
func (f *Fetcher) GetAURPackage(name string) (aur.Package, bool) {
return f.aurClient.Get(name)
}
func (f *Fetcher) BuildLocalPkgMap() (map[string]interface{}, error) { func (f *Fetcher) BuildLocalPkgMap() (map[string]interface{}, error) {
localPkgs, err := f.alpmHandle.LocalPackages() localPkgs, err := f.alpmHandle.LocalPackages()
@ -59,22 +60,6 @@ func (f *Fetcher) BuildLocalPkgMap() (map[string]interface{}, error) {
return result, nil return result, nil
} }
func (f *Fetcher) Close() error {
return f.alpmHandle.Release()
}
func (f *Fetcher) FetchAur(packages []string) (map[string]aur.Package, error) {
return f.aurClient.Fetch(packages)
}
func (f *Fetcher) FindProvidingPackage(depName string) (string, bool) {
return f.alpmHandle.FindProvidingPackage(depName)
}
func (f *Fetcher) GetAURPackage(name string) (aur.Package, bool) {
return f.aurClient.Get(name)
}
func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) { func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) {
start := time.Now() start := time.Now()
log.Debug("fetch.Resolve: starting...") log.Debug("fetch.Resolve: starting...")
@ -131,13 +116,6 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) {
continue continue
} }
if providedBy, ok := f.FindProvidingPackage(pkg); ok {
log.Debug("fetch.Resolve: %s provided by %s", pkg, providedBy)
info.Provided = providedBy
info.Exists = true
continue
}
return nil, fmt.Errorf("package not found: %s", pkg) return nil, fmt.Errorf("package not found: %s", pkg)
} }
} }

71
pkg/input/input.go

@ -2,41 +2,15 @@ package input
import ( import (
"bufio" "bufio"
"errors"
"os" "os"
"path/filepath"
"strings" "strings"
) )
var ErrEmptyList = errors.New("package list is empty")
// -----------------------------------------
// public
func Merge(packages map[string]bool) ([]string, error) {
result := make([]string, 0, len(packages))
for name := range packages {
result = append(result, name)
}
if len(result) == 0 {
return nil, ErrEmptyList
}
return result, nil
}
func ReadPackages(stateFiles []string) (map[string]bool, error) { func ReadPackages(stateFiles []string) (map[string]bool, error) {
packages := make(map[string]bool) packages := make(map[string]bool)
for _, file := range stateFiles { for _, file := range stateFiles {
expanded := expandPath(file) if err := readStateFile(file, packages); err != nil {
if err := readStateFile(expanded, packages); err != nil {
return nil, err
}
}
implicitStateFile := getImplicitStateFile()
if fileExists(implicitStateFile) {
if err := readStateFile(implicitStateFile, packages); err != nil {
return nil, err return nil, err
} }
} }
@ -48,41 +22,6 @@ func ReadPackages(stateFiles []string) (map[string]bool, error) {
return packages, nil return packages, nil
} }
// -----------------------------------------
// private
func expandPath(path string) string {
if strings.HasPrefix(path, "~/") {
home, err := os.UserHomeDir()
if err != nil {
return path
}
return filepath.Join(home, path[2:])
}
return path
}
func fileExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func getImplicitStateFile() string {
cfgDir, _ := os.UserConfigDir()
if cfgDir == "" {
cfgDir = "~/.config"
}
return filepath.Join(cfgDir, "declpac")
}
func normalizePackageName(name string) string {
name = strings.TrimSpace(name)
if name == "" || strings.HasPrefix(name, "#") {
return ""
}
return name
}
func readStateFile(path string, packages map[string]bool) error { func readStateFile(path string, packages map[string]bool) error {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
@ -121,3 +60,11 @@ func readStdin(packages map[string]bool) error {
return scanner.Err() return scanner.Err()
} }
func normalizePackageName(name string) string {
name = strings.TrimSpace(name)
if name == "" || strings.HasPrefix(name, "#") {
return ""
}
return name
}

34
pkg/log/log.go

@ -4,30 +4,16 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"strings"
"time" "time"
) )
// -----------------------------------------
var logFile *os.File var logFile *os.File
var Verbose bool var Verbose bool
// ----------------------------------------- // -----------------------------------------
// public
func Close() error {
if logFile == nil {
return nil
}
return logFile.Close()
}
func Command(name string, args ...string) *exec.Cmd {
cmdStr := name + " " + strings.Join(args, " ")
fmt.Fprintf(logFile, "[cmd] %s\n", cmdStr)
return exec.Command(name, args...)
}
func Debug(format string, args ...interface{}) { func Debug(format string, args ...interface{}) {
if !Verbose { if !Verbose {
@ -36,9 +22,7 @@ func Debug(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "[debug] "+format+"\n", args...) fmt.Fprintf(os.Stderr, "[debug] "+format+"\n", args...)
} }
func GetLogWriter() io.Writer { // -----------------------------------------
return logFile
}
func OpenLog() error { func OpenLog() error {
logPath := filepath.Join("/var/log", "declpac.log") logPath := filepath.Join("/var/log", "declpac.log")
@ -51,12 +35,22 @@ func OpenLog() error {
return nil return nil
} }
func GetLogWriter() io.Writer {
return logFile
}
func Write(msg []byte) { func Write(msg []byte) {
logFile.Write(msg) logFile.Write(msg)
} }
func Close() error {
if logFile == nil {
return nil
}
return logFile.Close()
}
// ----------------------------------------- // -----------------------------------------
// private
func writeTimestamp() { func writeTimestamp() {
ts := time.Now().Format("2006-01-02 15:04:05") ts := time.Now().Format("2006-01-02 15:04:05")

9
pkg/merge/merge.go

@ -0,0 +1,9 @@
package merge
func Merge(packages map[string]bool) []string {
result := make([]string, 0, len(packages))
for name := range packages {
result = append(result, name)
}
return result
}

9
pkg/output/output.go

@ -12,18 +12,15 @@ type Result struct {
ToRemove []string ToRemove []string
} }
// -----------------------------------------
// public
func Format(r *Result) string { func Format(r *Result) string {
var b strings.Builder var b strings.Builder
b.WriteString(fmt.Sprintf("installed %d packages, removed %d packages", r.Installed, r.Removed)) b.WriteString(fmt.Sprintf("Installed %d packages, removed %d packages", r.Installed, r.Removed))
if len(r.ToInstall) > 0 { if len(r.ToInstall) > 0 {
b.WriteString("\nwould install: ") b.WriteString("\nWould install: ")
b.WriteString(strings.Join(r.ToInstall, ", ")) b.WriteString(strings.Join(r.ToInstall, ", "))
} }
if len(r.ToRemove) > 0 { if len(r.ToRemove) > 0 {
b.WriteString("\nwould remove: ") b.WriteString("\nWould remove: ")
b.WriteString(strings.Join(r.ToRemove, ", ")) b.WriteString(strings.Join(r.ToRemove, ", "))
} }
return b.String() return b.String()

81
pkg/pacman/pacman.go

@ -13,21 +13,10 @@ import (
"github.com/Riyyi/declpac/pkg/pacman/sync" "github.com/Riyyi/declpac/pkg/pacman/sync"
) )
func Sync(packages []string, noCheck bool, prune bool) (*output.Result, error) { func Sync(packages []string) (*output.Result, error) {
start := time.Now() start := time.Now()
log.Debug("Sync: starting...") log.Debug("Sync: starting...")
explicitList, err := read.ExplicitList()
if err != nil {
return nil, err
}
explicitCount := len(explicitList)
if !noCheck && len(packages) < explicitCount/2 {
errMsg := "safety check: state packages (%d) less than half of explicitly installed (%d), override with --nocheck"
return nil, fmt.Errorf(errMsg, len(packages), explicitCount)
}
list, err := read.List() list, err := read.List()
if err != nil { if err != nil {
return nil, err return nil, err
@ -76,30 +65,25 @@ func Sync(packages []string, noCheck bool, prune bool) (*output.Result, error) {
if !ok { if !ok {
return nil, fmt.Errorf("AUR package not found in cache: %s", pkg) return nil, fmt.Errorf("AUR package not found in cache: %s", pkg)
} }
if err := sync.InstallAUR(f, pkg, aurInfo.PackageBase, false, log.GetLogWriter()); err != nil { if err := sync.InstallAUR(pkg, aurInfo.PackageBase, log.GetLogWriter()); err != nil {
return nil, err return nil, err
} }
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())
} }
var removed int log.Debug("Sync: marking all as deps...")
if prune { markAllAsDeps()
log.Debug("Sync: marking all as deps...") log.Debug("Sync: all marked as deps (%.2fs)", time.Since(start).Seconds())
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()
@ -117,9 +101,6 @@ func Sync(packages []string, noCheck bool, prune bool) (*output.Result, error) {
}, nil }, nil
} }
// -----------------------------------------
// private
func categorizePackages(f *fetch.Fetcher, packages []string) (pacmanPkgs, aurPkgs []string, err error) { func categorizePackages(f *fetch.Fetcher, packages []string) (pacmanPkgs, aurPkgs []string, err error) {
start := time.Now() start := time.Now()
log.Debug("categorizePackages: starting...") log.Debug("categorizePackages: starting...")
@ -146,6 +127,24 @@ func categorizePackages(f *fetch.Fetcher, packages []string) (pacmanPkgs, aurPkg
return pacmanPkgs, aurPkgs, nil return pacmanPkgs, aurPkgs, nil
} }
func markAllAsDeps() error {
start := time.Now()
log.Debug("markAllAsDeps: starting...")
packages, err := read.List()
if err != nil || len(packages) == 0 {
return fmt.Errorf("failed to list packages: %w", err)
}
if err := sync.MarkAs(packages, "deps", log.GetLogWriter()); err != nil {
log.Write([]byte(fmt.Sprintf("error: %v\n", err)))
return err
}
log.Debug("markAllAsDeps: done (%.2fs)", time.Since(start).Seconds())
return nil
}
func cleanupOrphans() (int, error) { func cleanupOrphans() (int, error) {
start := time.Now() start := time.Now()
log.Debug("cleanupOrphans: starting...") log.Debug("cleanupOrphans: starting...")
@ -165,21 +164,3 @@ func cleanupOrphans() (int, error) {
log.Debug("cleanupOrphans: done (%.2fs)", time.Since(start).Seconds()) log.Debug("cleanupOrphans: done (%.2fs)", time.Since(start).Seconds())
return removed, nil return removed, nil
} }
func markAllAsDeps() error {
start := time.Now()
log.Debug("markAllAsDeps: starting...")
packages, err := read.List()
if err != nil || len(packages) == 0 {
return fmt.Errorf("failed to list packages: %w", err)
}
if err := sync.MarkAs(packages, "deps", log.GetLogWriter()); err != nil {
log.Write([]byte(fmt.Sprintf("error: %v\n", err)))
return err
}
log.Debug("markAllAsDeps: done (%.2fs)", time.Since(start).Seconds())
return nil
}

110
pkg/pacman/read/read.go

@ -16,6 +16,52 @@ import (
var LockFile = "/var/lib/pacman/db.lock" var LockFile = "/var/lib/pacman/db.lock"
func List() ([]string, error) {
start := time.Now()
log.Debug("List: starting...")
cmd := exec.Command("pacman", "-Qq")
output, err := cmd.Output()
if err != nil {
return nil, err
}
list := strings.Split(strings.TrimSpace(string(output)), "\n")
if list[0] == "" {
list = nil
}
log.Debug("List: done (%.2fs)", time.Since(start).Seconds())
return list, nil
}
func ListOrphans() ([]string, error) {
start := time.Now()
log.Debug("ListOrphans: starting...")
cmd := exec.Command("pacman", "-Qdtq")
var stderr bytes.Buffer
cmd.Stderr = &stderr
output, err := cmd.Output()
if err != nil {
// pacman -Qdtq exits 1 when there are no orphans, this isnt an error
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 && stderr.Len() == 0 {
return nil, nil
}
return nil, err
}
orphans := strings.Split(strings.TrimSpace(string(output)), "\n")
if len(orphans) > 0 && orphans[0] == "" {
orphans = orphans[1:]
}
log.Debug("ListOrphans: done (%.2fs)", time.Since(start).Seconds())
return orphans, nil
}
func DBFreshness() (bool, error) { func DBFreshness() (bool, error) {
info, err := os.Stat(LockFile) info, err := os.Stat(LockFile)
if err != nil { if err != nil {
@ -83,67 +129,3 @@ func DryRun(packages []string) (*output.Result, error) {
ToRemove: toRemove, ToRemove: toRemove,
}, nil }, nil
} }
func ExplicitList() ([]string, error) {
start := time.Now()
log.Debug("ExplicitList: starting...")
cmd := exec.Command("pacman", "-Qqe")
output, err := cmd.Output()
if err != nil {
return nil, err
}
list := strings.Split(strings.TrimSpace(string(output)), "\n")
if len(list) > 0 && list[0] == "" {
list = nil
}
log.Debug("ExplicitList: done (%.2fs)", time.Since(start).Seconds())
return list, nil
}
func List() ([]string, error) {
start := time.Now()
log.Debug("List: starting...")
cmd := exec.Command("pacman", "-Qq")
output, err := cmd.Output()
if err != nil {
return nil, err
}
list := strings.Split(strings.TrimSpace(string(output)), "\n")
if list[0] == "" {
list = nil
}
log.Debug("List: done (%.2fs)", time.Since(start).Seconds())
return list, nil
}
func ListOrphans() ([]string, error) {
start := time.Now()
log.Debug("ListOrphans: starting...")
cmd := exec.Command("pacman", "-Qdtq")
var stderr bytes.Buffer
cmd.Stderr = &stderr
output, err := cmd.Output()
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 && stderr.Len() == 0 {
return nil, nil
}
return nil, err
}
orphans := strings.Split(strings.TrimSpace(string(output)), "\n")
if len(orphans) > 0 && orphans[0] == "" {
orphans = orphans[1:]
}
log.Debug("ListOrphans: done (%.2fs)", time.Since(start).Seconds())
return orphans, nil
}

254
pkg/pacman/sync/sync.go

@ -4,66 +4,58 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/exec"
"strings" "strings"
"sync"
"time" "time"
"github.com/Riyyi/declpac/pkg/fetch"
"github.com/Riyyi/declpac/pkg/fetch/aur"
"github.com/Riyyi/declpac/pkg/log" "github.com/Riyyi/declpac/pkg/log"
) )
var sudoUser string
var sudoUserOnce sync.Once
type Result struct { type Result struct {
Installed int Installed int
Removed int Removed int
} }
// ----------------------------------------- func SyncPackages(packages []string, logWriter io.Writer) error {
// public
func InstallAUR(f *fetch.Fetcher, pkgName string, packageBase string, asDeps bool, logWriter io.Writer) error {
start := time.Now() start := time.Now()
log.Debug("InstallAUR: starting...") log.Debug("SyncPackages: starting...")
if logWriter == nil { if logWriter == nil {
logWriter = os.Stderr logWriter = os.Stderr
} }
aurInfo := getAURInfo(f, pkgName, packageBase) args := append([]string{"-S", "--needed", "--noconfirm"}, packages...)
if err := resolveAndInstallDeps(f, aurInfo, logWriter); err != nil { cmdStr := "pacman " + strings.Join(args, " ")
return err fmt.Fprintf(logWriter, "[cmd] %s\n", cmdStr)
} cmd := exec.Command("pacman", args...)
cmd.Stdout = logWriter
sudoUser := getSudoUser() cmd.Stderr = logWriter
tmpDir := "/tmp/declpac/" + pkgName err := cmd.Run()
if err := createTempDir(sudoUser, tmpDir); err != nil { if err != nil {
return err return fmt.Errorf("pacman sync failed: %w", err)
} }
defer os.RemoveAll(tmpDir)
if err := cloneRepo(sudoUser, packageBase, tmpDir, logWriter); err != nil { log.Debug("SyncPackages: done (%.2fs)", time.Since(start).Seconds())
return err return nil
} }
log.Debug("InstallAUR: cloned (%.2fs)", time.Since(start).Seconds())
if err := buildPackage(sudoUser, tmpDir, asDeps, logWriter); err != nil { func RefreshDB(logWriter io.Writer) error {
return err start := time.Now()
} log.Debug("RefreshDB: starting...")
log.Debug("InstallAUR: built (%.2fs)", time.Since(start).Seconds())
pkgFile, err := findPKGFile(pkgName, tmpDir) if logWriter == nil {
if err != nil { logWriter = os.Stderr
return fmt.Errorf("failed to find built package: %w", err)
} }
if err := installBuiltPackage(pkgFile, logWriter); err != nil { fmt.Fprintf(logWriter, "[cmd] pacman -Syy\n")
return err cmd := exec.Command("pacman", "-Syy")
cmd.Stdout = logWriter
cmd.Stderr = logWriter
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to refresh pacman database: %w", err)
} }
log.Debug("InstallAUR: done (%.2fs)", time.Since(start).Seconds())
log.Debug("RefreshDB: done (%.2fs)", time.Since(start).Seconds())
return nil return nil
} }
@ -80,7 +72,9 @@ func MarkAs(packages []string, flag string, logWriter io.Writer) error {
} }
args := append([]string{"-D", "--" + flagName}, packages...) args := append([]string{"-D", "--" + flagName}, packages...)
cmd := log.Command("pacman", args...) cmdStr := "pacman " + strings.Join(args, " ")
fmt.Fprintf(logWriter, "[cmd] %s\n", cmdStr)
cmd := exec.Command("pacman", args...)
cmd.Stdout = logWriter cmd.Stdout = logWriter
cmd.Stderr = logWriter cmd.Stderr = logWriter
err := cmd.Run() err := cmd.Run()
@ -92,25 +86,6 @@ func MarkAs(packages []string, flag string, logWriter io.Writer) error {
return nil return nil
} }
func RefreshDB(logWriter io.Writer) error {
start := time.Now()
log.Debug("RefreshDB: starting...")
if logWriter == nil {
logWriter = os.Stderr
}
cmd := log.Command("pacman", "-Syy")
cmd.Stdout = logWriter
cmd.Stderr = logWriter
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to refresh pacman database: %w", err)
}
log.Debug("RefreshDB: done (%.2fs)", time.Since(start).Seconds())
return nil
}
func RemoveOrphans(orphans []string, logWriter io.Writer) (int, error) { func RemoveOrphans(orphans []string, logWriter io.Writer) (int, error) {
start := time.Now() start := time.Now()
log.Debug("RemoveOrphans: starting...") log.Debug("RemoveOrphans: starting...")
@ -127,7 +102,9 @@ func RemoveOrphans(orphans []string, logWriter io.Writer) (int, error) {
args := make([]string, 0, 3+len(orphans)) args := make([]string, 0, 3+len(orphans))
args = append(args, "pacman", "-Rns", "--noconfirm") args = append(args, "pacman", "-Rns", "--noconfirm")
args = append(args, orphans...) args = append(args, orphans...)
removeCmd := log.Command(args[0], args[1:]...) cmdStr := strings.Join(args, " ")
fmt.Fprintf(logWriter, "[cmd] %s\n", cmdStr)
removeCmd := exec.Command(args[0], args[1:]...)
removeCmd.Stdout = logWriter removeCmd.Stdout = logWriter
removeCmd.Stderr = logWriter removeCmd.Stderr = logWriter
err := removeCmd.Run() err := removeCmd.Run()
@ -141,161 +118,80 @@ func RemoveOrphans(orphans []string, logWriter io.Writer) (int, error) {
return count, nil return count, nil
} }
func SyncPackages(packages []string, logWriter io.Writer) error { func InstallAUR(pkgName string, packageBase string, logWriter io.Writer) error {
start := time.Now() start := time.Now()
log.Debug("SyncPackages: starting...") log.Debug("InstallAUR: starting...")
if logWriter == nil { if logWriter == nil {
logWriter = os.Stderr logWriter = os.Stderr
} }
args := append([]string{"-S", "--needed", "--noconfirm"}, packages...) sudoUser := os.Getenv("SUDO_USER")
cmd := log.Command("pacman", args...) if sudoUser == "" {
cmd.Stdout = logWriter sudoUser = os.Getenv("USER")
cmd.Stderr = logWriter if sudoUser == "" {
err := cmd.Run() sudoUser = "root"
if err != nil { }
return fmt.Errorf("pacman sync failed: %w", err)
} }
log.Debug("SyncPackages: done (%.2fs)", time.Since(start).Seconds()) tmpDir := "/tmp/declpac-aur-" + pkgName
return nil mkdirCmdStr := "su - " + sudoUser + " -c 'rm -rf " + tmpDir + " && mkdir -p " + tmpDir + "'"
} fmt.Fprintf(logWriter, "[cmd] %s\n", mkdirCmdStr)
mkdirCmd := exec.Command("su", "-", sudoUser, "-c", "rm -rf "+tmpDir+" && mkdir -p "+tmpDir)
// ----------------------------------------- if err := mkdirCmd.Run(); err != nil {
// private return fmt.Errorf("failed to create temp directory: %w", err)
func buildPackage(sudoUser string, tmpDir string, asDeps bool, logWriter io.Writer) error {
makepkgArgs := []string{"makepkg", "-s", "--noconfirm"}
if asDeps {
makepkgArgs = append(makepkgArgs, "--asdeps")
}
makepkgCmd := log.Command("su", "-", sudoUser, "-c", "cd "+tmpDir+" && "+strings.Join(makepkgArgs, " "))
makepkgCmd.Stdout = logWriter
makepkgCmd.Stderr = logWriter
if err := makepkgCmd.Run(); err != nil {
return fmt.Errorf("makepkg failed to build AUR package: %w", err)
} }
return nil defer os.RemoveAll(tmpDir)
}
func cloneRepo(sudoUser string, packageBase string, tmpDir string, logWriter io.Writer) error {
cloneURL := "https://aur.archlinux.org/" + packageBase + ".git" cloneURL := "https://aur.archlinux.org/" + packageBase + ".git"
cloneCmd := log.Command("su", "-", sudoUser, "-c", "git clone "+cloneURL+" "+tmpDir) cloneCmdStr := "su - " + sudoUser + " -c 'git clone " + cloneURL + " " + tmpDir + "'"
fmt.Fprintf(logWriter, "[cmd] %s\n", cloneCmdStr)
cloneCmd := exec.Command("su", "-", sudoUser, "-c", "git clone "+cloneURL+" "+tmpDir)
cloneCmd.Stdout = logWriter cloneCmd.Stdout = logWriter
cloneCmd.Stderr = logWriter cloneCmd.Stderr = logWriter
if err := cloneCmd.Run(); err != nil { if err := cloneCmd.Run(); err != nil {
return fmt.Errorf("failed to clone AUR repo: %w", err) return fmt.Errorf("failed to clone AUR repo: %w", err)
} }
return nil log.Debug("InstallAUR: cloned (%.2fs)", time.Since(start).Seconds())
}
func createTempDir(sudoUser string, tmpDir string) error { makepkgCmdStr := "su - " + sudoUser + " -c 'cd " + tmpDir + " && makepkg -s --noconfirm'"
mkdirCmd := log.Command("su", "-", sudoUser, "-c", "rm -rf "+tmpDir+" && mkdir -p "+tmpDir) fmt.Fprintf(logWriter, "[cmd] %s\n", makepkgCmdStr)
if err := mkdirCmd.Run(); err != nil { makepkgCmd := exec.Command("su", "-", sudoUser, "-c", "cd "+tmpDir+" && makepkg -s --noconfirm")
return fmt.Errorf("failed to create temp directory: %w", err) makepkgCmd.Stdout = logWriter
makepkgCmd.Stderr = logWriter
if err := makepkgCmd.Run(); err != nil {
return fmt.Errorf("makepkg failed to build AUR package: %w", err)
} }
return nil log.Debug("InstallAUR: built (%.2fs)", time.Since(start).Seconds())
}
func findPKGFile(pkgName string, dir string) (string, error) { pkgFile, err := findPKGFile(tmpDir)
entries, err := os.ReadDir(dir)
if err != nil { if err != nil {
return "", err return fmt.Errorf("failed to find built package: %w", err)
}
for _, entry := range entries {
name := entry.Name()
if !strings.HasSuffix(name, ".pkg.tar.zst") && !strings.HasSuffix(name, ".pkg.tar.gz") {
continue
}
if strings.HasPrefix(name, pkgName+"-debug") {
continue
}
return strings.Join([]string{dir, name}, "/"), nil
}
return "", fmt.Errorf("no package file found in %s", dir)
}
func getAURInfo(f *fetch.Fetcher, pkgName string, packageBase string) *aur.Package {
if packageBase == "" {
return nil
}
info, ok := f.GetAURPackage(pkgName)
if !ok {
return nil
} }
return &info
}
func getSudoUser() string { installCmdStr := "pacman -U --noconfirm " + pkgFile
sudoUserOnce.Do(func() { fmt.Fprintf(logWriter, "[cmd] %s\n", installCmdStr)
sudoUser = os.Getenv("SUDO_USER") installCmd := exec.Command("pacman", "-U", "--noconfirm", pkgFile)
if sudoUser == "" {
sudoUser = os.Getenv("USER")
if sudoUser == "" {
sudoUser = "root"
}
}
})
return sudoUser
}
func installBuiltPackage(pkgFile string, logWriter io.Writer) error {
installCmd := log.Command("pacman", "-U", "--noconfirm", pkgFile)
installCmd.Stdout = logWriter installCmd.Stdout = logWriter
installCmd.Stderr = logWriter installCmd.Stderr = logWriter
if err := installCmd.Run(); err != nil { if err := installCmd.Run(); err != nil {
return fmt.Errorf("failed to install package: %w", err) return fmt.Errorf("failed to install package: %w", err)
} }
log.Debug("InstallAUR: done (%.2fs)", time.Since(start).Seconds())
return nil return nil
} }
func resolveAndInstallDeps(f *fetch.Fetcher, aurInfo *aur.Package, logWriter io.Writer) error { func findPKGFile(dir string) (string, error) {
if aurInfo == nil { entries, err := os.ReadDir(dir)
return nil
}
depends := aurInfo.AllDepends()
if len(depends) == 0 {
return nil
}
resolved, err := f.Resolve(depends)
if err != nil {
return fmt.Errorf("failed to resolve dependencies: %w", err)
}
var aurDeps []string
for _, dep := range depends {
info := resolved[dep]
if info.Installed {
continue
}
if info.Exists {
continue
}
if info.InAUR {
aurDeps = append(aurDeps, dep)
}
}
if len(aurDeps) == 0 {
return nil
}
fetched, err := f.FetchAur(aurDeps)
if err != nil { if err != nil {
log.Debug("sync.resolveAndInstallDeps: aur fetch error: %v", err) return "", err
} }
for _, dep := range aurDeps { for _, entry := range entries {
depInfo, ok := fetched[dep] name := entry.Name()
if !ok { if strings.HasSuffix(name, ".pkg.tar.zst") || strings.HasSuffix(name, ".pkg.tar.gz") {
continue return strings.Join([]string{dir, name}, "/"), nil
}
if err := InstallAUR(f, dep, depInfo.PackageBase, true, logWriter); err != nil {
return err
} }
} }
return "", fmt.Errorf("no package file found in %s", dir)
return nil
} }

142
scenario-dependencies-renamed

@ -1,142 +0,0 @@
[debug] run: starting...
[debug] run: packages read (0.00s)
[debug] CheckDBFreshness: starting...
[debug] Sync: starting...
[debug] getInstalledCount: starting...
[debug] getInstalledCount: done (0.01s)
[debug] CheckDBFreshness: starting...
[debug] Sync: database fresh (0.01s)
[debug] Fetcher New: starting...
[debug] registerSyncDBs: starting...
[debug] registerSyncDBs: done (3 dbs)
[debug] Fetcher New: done (0.15s)
[debug] Sync: initialized fetcher (0.15s)
[debug] Sync: categorizing packages...
[debug] categorizePackages: starting...
[debug] Resolve: starting...
[debug] buildLocalPkgMap: starting...
[debug] buildLocalPkgMap: done (0.00s)
[debug] Resolve: local pkgs built (0.00s)
[debug] checkSyncDBs: starting...
[debug] checkSyncDBs: done (0.00s)
[debug] ensureAURCache: starting...
[debug] fetchAURInfo: starting...
[debug] fetchAURInfo: done (0.19s)
[debug] ensureAURCache: done (0.19s)
[debug] Resolve: done (0.20s)
[debug] categorizePackages: done (0.20s)
[debug] Sync: packages categorized (0.36s)
[debug] Sync: syncing 183 pacman packages...
[debug] SyncPackages: starting...
error: pacman sync failed: warning: imv-5.0.1-1 is up to date -- skipping
warning: jq-1.8.1-1 is up to date -- skipping
warning: ntfs-3g-2022.10.3-2 is up to date -- skipping
warning: python-pycurl-7.45.7-3 is up to date -- skipping
warning: usbutils-019-1 is up to date -- skipping
warning: smartmontools-7.5-1 is up to date -- skipping
warning: rsync-3.4.1-2 is up to date -- skipping
warning: linux-firmware-20260309-1 is up to date -- skipping
warning: wget-1.25.0-3 is up to date -- skipping
warning: kvantum-1.1.6-1 is up to date -- skipping
warning: mpv-1:0.41.0-3 is up to date -- skipping
warning: unzip-6.0-23 is up to date -- skipping
warning: ark-25.12.3-1 is up to date -- skipping
warning: brightnessctl-0.5.1-3 is up to date -- skipping
warning: gnome-themes-extra-1:3.28-1 is up to date -- skipping
warning: kolourpaint-25.12.3-1 is up to date -- skipping
warning: rtkit-0.14-1 is up to date -- skipping
warning: isync-1.5.1-2 is up to date -- skipping
warning: qt5-serialport-5.15.18-1 is up to date -- skipping
warning: tlp-1.9.1-1 is up to date -- skipping
warning: amd-ucode-20260309-1 is up to date -- skipping
warning: aria2-1.37.0-2 is up to date -- skipping
warning: lib32-glibc-2.43+r5+g856c426a7534-1 is up to date -- skipping
warning: r-4.5.3-1 is up to date -- skipping
warning: 7zip-26.00-1 is up to date -- skipping
warning: base-devel-1-2 is up to date -- skipping
warning: pacman-contrib-1.13.1-1 is up to date -- skipping
warning: ydotool-1.0.4-2 is up to date -- skipping
warning: sysfsutils-2.1.1-2 is up to date -- skipping
warning: tumbler-4.20.1-1 is up to date -- skipping
warning: efibootmgr-18-3 is up to date -- skipping
warning: exfat-utils-1.4.0-4 is up to date -- skipping
warning: mysql-workbench-8.0.46-1 is up to date -- skipping
warning: python-matplotlib-3.10.8-5 is up to date -- skipping
warning: rofi-2.0.0-1 is up to date -- skipping
warning: inetutils-2.7-2 is up to date -- skipping
warning: thunar-volman-4.20.0-2 is up to date -- skipping
warning: valgrind-3.25.1-4 is up to date -- skipping
warning: python-certifi-2026.02.25-1 is up to date -- skipping
warning: python-opengl-3.1.10-3 is up to date -- skipping
warning: qt5-tools-5.15.18+kde+r3-2 is up to date -- skipping
warning: nwg-look-1.0.6-1 is up to date -- skipping
warning: python-zstandard-0.25.0-2 is up to date -- skipping
warning: sshfs-3.7.5-1 is up to date -- skipping
warning: waybar-0.15.0-2 is up to date -- skipping
warning: base-3-3 is up to date -- skipping
warning: kdenlive-25.12.3-1 is up to date -- skipping
warning: pavucontrol-1:6.2-1 is up to date -- skipping
warning: python-adblock-0.6.0-5 is up to date -- skipping
warning: qt5ct-1.9-1 is up to date -- skipping
warning: wpa_supplicant-2:2.11-5 is up to date -- skipping
warning: aspell-en-2026.02.25-1 is up to date -- skipping
warning: aspell-nl-0.50.2-8 is up to date -- skipping
warning: lib32-openal-1.25.1-1 is up to date -- skipping
warning: ncdu-2.9.2-1 is up to date -- skipping
warning: otf-font-awesome-7.2.0-1 is up to date -- skipping
warning: hunspell-nl-2.20.19-5 is up to date -- skipping
warning: git-2.53.0-1 is up to date -- skipping
warning: nlohmann-json-3.12.0-2 is up to date -- skipping
warning: zsh-completions-0.36.0-1 is up to date -- skipping
warning: man-db-2.13.1-1 is up to date -- skipping
warning: grim-1.5.0-2 is up to date -- skipping
warning: dnsmasq-2.92-1 is up to date -- skipping
warning: kvantum-qt5-1.1.6-1 is up to date -- skipping
warning: iw-6.17-1 is up to date -- skipping
warning: man-pages-6.17-1 is up to date -- skipping
warning: namcap-3.6.0-3 is up to date -- skipping
warning: mesa-demos-9.0.0-7 is up to date -- skipping
warning: reflector-2023-5 is up to date -- skipping
warning: tokei-14.0.0-1 is up to date -- skipping
warning: gammastep-2.0.11-2 is up to date -- skipping
warning: dialog-1:1.3_20260107-1 is up to date -- skipping
warning: mariadb-12.2.2-2 is up to date -- skipping
warning: ttf-dejavu-nerd-3.4.0-2 is up to date -- skipping
warning: vim-spell-nl-20220628-2 is up to date -- skipping
warning: python-pyusb-1.3.1-2 is up to date -- skipping
warning: socat-1.8.1.1-1 is up to date -- skipping
warning: duf-0.9.1-1 is up to date -- skipping
warning: evtest-1.36-1 is up to date -- skipping
warning: rtmpdump-1:2.6-1 is up to date -- skipping
warning: hunspell-1.7.2-3 is up to date -- skipping
warning: kcachegrind-25.12.3-1 is up to date -- skipping
warning: python-watchdog-6.0.0-2 is up to date -- skipping
warning: texlab-5.25.1-1 is up to date -- skipping
warning: sqlitebrowser-3.13.1-3 is up to date -- skipping
warning: acpi-1.8-2 is up to date -- skipping
warning: netctl-1.29-2 is up to date -- skipping
warning: python-beautifulsoup4-4.14.3-2 is up to date -- skipping
warning: vim-spell-en-20220628-2 is up to date -- skipping
warning: xf86-input-wacom-1.2.4-1 is up to date -- skipping
warning: capitaine-cursors-4-3 is up to date -- skipping
warning: ffmpegthumbnailer-2.3.0-1 is up to date -- skipping
warning: hunspell-en_us-2026.02.25-1 is up to date -- skipping
resolving dependencies...
looking for conflicting packages...
error: failed to prepare transaction (could not satisfy dependencies)
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by aquamarine
:: installing libvpx (1.16.0-3) breaks dependency 'libvpx.so=11-64' required by ffmpeg
:: installing gst-plugins-base-libs (1.28.2-1) breaks dependency 'gst-plugins-base-libs=1.28.1-1' required by gst-plugins-bad-libs
:: installing gstreamer (1.28.2-1) breaks dependency 'gstreamer=1.28.1-1' required by gst-plugins-bad-libs
:: installing gst-plugins-base-libs (1.28.2-1) breaks dependency 'gst-plugins-base-libs=1.28.1-1' required by gst-plugins-base
:: installing gstreamer (1.28.2-1) breaks dependency 'gstreamer=1.28.1-1' required by gst-plugins-base
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprgraphics
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprland-guiutils
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprlang
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprtoolkit
:: installing hyprutils (0.12.0-1) breaks dependency 'libhyprutils.so=10-64' required by hyprwire
:: installing libpipewire (1:1.6.3-1) breaks dependency 'libpipewire=1:1.6.1-1' required by pipewire-jack
:: installing pipewire-audio (1:1.6.3-1) breaks dependency 'pipewire-audio=1:1.6.1-1' required by pipewire-jack
:: installing pipewire (1:1.6.3-1) breaks dependency 'pipewire=1:1.6.1-1' required by pipewire-jack
:: installing poppler (26.04.0-1) breaks dependency 'poppler=26.02.0' required by poppler-qt6
Loading…
Cancel
Save