mirror of
https://github.com/Jguer/yay.git
synced 2025-06-25 00:03:32 -04:00
Compare commits
No commits in common. "next" and "v8.1139" have entirely different histories.
@ -1,26 +0,0 @@
|
||||
# Use the jguer/yay-builder image as a parent image with archlinux
|
||||
FROM docker.io/jguer/yay-builder
|
||||
|
||||
# Install extra packages (pacman-contrib and fish)
|
||||
RUN sudo pacman -Syu --noconfirm pacman-contrib fish git-delta openssh bat go
|
||||
|
||||
# Set passwordless sudo for the docker user
|
||||
RUN echo "docker ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/docker
|
||||
|
||||
# Create a non-root user and switch to it
|
||||
USER docker
|
||||
|
||||
# Install xgotext
|
||||
RUN go install github.com/leonelquinteros/gotext/cli/xgotext@latest
|
||||
|
||||
# Add /app/bin to the PATH
|
||||
ENV PATH="/app/bin:$PATH"
|
||||
|
||||
# add /home/docker/go/bin to the PATH
|
||||
ENV PATH="/home/docker/go/bin:$PATH"
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /workspace
|
||||
|
||||
# Command to run when starting the container
|
||||
CMD ["bash"]
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"name": "Existing Dockerfile",
|
||||
"build": {
|
||||
"context": "..",
|
||||
"dockerfile": "../.devcontainer/Dockerfile"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"golang.go"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
*
|
||||
!*.go
|
||||
!pkg
|
||||
!go.mod
|
||||
!go.sum
|
||||
!Makefile
|
||||
!po
|
||||
!doc
|
||||
!completions
|
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -1 +0,0 @@
|
||||
* @Jguer
|
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@ -1 +0,0 @@
|
||||
github: [Jguer]
|
44
.github/ISSUE_TEMPLATE/bug_report.md
vendored
44
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,44 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a malfunction to help us improve
|
||||
title: ""
|
||||
labels: "Status: Triage, Type: Bug"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
### Affected Version
|
||||
|
||||
<!-- Please ensure you are using the latest yay-git package
|
||||
Use `yay -V` to get installed version
|
||||
Example: `yay v8.1139.r0.g9ac4ab6 - libalpm v11.0.1` -->
|
||||
|
||||
### Describe the bug
|
||||
|
||||
<!-- A clear and concise description of the bug. -->
|
||||
|
||||
### Reproduction Steps
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
### Expected behavior
|
||||
|
||||
<!-- A clear and concise description of what you expected to happen. -->
|
||||
|
||||
### Output
|
||||
|
||||
<!--
|
||||
Include the FULL output of any relevant commands/configs
|
||||
The current yay config can be printed with `yay -Pg`
|
||||
Paste services are only needed for excessive output (>500 lines)
|
||||
Use --debug to add pacman and yay debug logs
|
||||
or add the following key to your ~/.config/yay/config.json to only get yay debug logs
|
||||
{
|
||||
"debug": true
|
||||
}
|
||||
-->
|
||||
|
||||
```sh
|
||||
|
||||
```
|
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,23 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ""
|
||||
labels: "Type: Feature Request, Status: Discussion Open"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
### Is your feature request related to a problem? Please describe.
|
||||
|
||||
<!-- A clear and concise description of the problem, e.g. I'm always frustrated when ... -->
|
||||
|
||||
### Describe the solution you'd like
|
||||
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
### Describe alternatives you've considered
|
||||
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
### Additional context
|
||||
|
||||
<!-- Add any other context or screenshots about the feature request here. -->
|
15
.github/dependabot.yml
vendored
15
.github/dependabot.yml
vendored
@ -1,15 +0,0 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gomod" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
groups:
|
||||
go-all:
|
||||
patterns:
|
||||
- '*'
|
20
.github/stale.yml
vendored
20
.github/stale.yml
vendored
@ -1,20 +0,0 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 120
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 40
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- "Status: In Progress"
|
||||
- "Status: Confirmed"
|
||||
- "Status: Approved"
|
||||
- "Status: Triage"
|
||||
- "Type: Bug"
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
143
.github/workflows/builder-image.yml
vendored
143
.github/workflows/builder-image.yml
vendored
@ -1,143 +0,0 @@
|
||||
name: Builder Image
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 3 * * 1" # Every Monday at 3 AM
|
||||
push:
|
||||
paths:
|
||||
- "ci.Dockerfile"
|
||||
- ".github/workflows/builder-image.yml"
|
||||
|
||||
env:
|
||||
REGISTRY_IMAGE: jguer/yay-builder
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
platform:
|
||||
- linux/amd64
|
||||
- linux/arm/v7
|
||||
- linux/arm64
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ env.REGISTRY_IMAGE }}
|
||||
ghcr.io/${{ env.REGISTRY_IMAGE }}
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=sha,format=long
|
||||
|
||||
- name: Build and push by digest
|
||||
id: build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ci.Dockerfile
|
||||
platforms: ${{ matrix.platform }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
||||
|
||||
- name: Export digest
|
||||
run: |
|
||||
mkdir -p /tmp/digests
|
||||
digest="${{ steps.build.outputs.digest }}"
|
||||
echo -n "$digest" > "/tmp/digests/$(echo "${{ matrix.platform }}" | tr '/' '_')"
|
||||
|
||||
- name: Upload digest
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: digest-${{ matrix.platform == 'linux/amd64' && 'amd64' || matrix.platform == 'linux/arm/v7' && 'armv7' || 'arm64' }}
|
||||
path: /tmp/digests/*
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
merge:
|
||||
needs: [build]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: digest-*
|
||||
merge-multiple: true
|
||||
path: /tmp/digests
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ env.REGISTRY_IMAGE }}
|
||||
ghcr.io/${{ env.REGISTRY_IMAGE }}
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=sha,format=short
|
||||
|
||||
- name: Create and push manifest list
|
||||
env:
|
||||
DOCKER_CLI_EXPERIMENTAL: enabled
|
||||
run: |
|
||||
# Extract Docker Hub tags
|
||||
DH_TAGS=$(echo '${{ steps.meta.outputs.tags }}' | grep -v "^ghcr.io" | xargs -I {} echo "-t {}")
|
||||
|
||||
# Extract GitHub Container Registry tags
|
||||
GHCR_TAGS=$(echo '${{ steps.meta.outputs.tags }}' | grep "^ghcr.io" | xargs -I {} echo "-t {}")
|
||||
|
||||
# Create a manifest list using the image digests from /tmp/digests/*
|
||||
DIGESTS=$(for file in /tmp/digests/*; do
|
||||
echo -n "${{ env.REGISTRY_IMAGE }}@$(cat $file) "
|
||||
done)
|
||||
|
||||
# Create the manifest list for Docker Hub
|
||||
docker buildx imagetools create $DH_TAGS $DIGESTS
|
||||
|
||||
# Create the manifest list for GitHub Container Registry
|
||||
docker buildx imagetools create $GHCR_TAGS $DIGESTS
|
||||
|
||||
- name: Inspect image
|
||||
run: |
|
||||
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:latest
|
93
.github/workflows/multiarch-build.yml
vendored
93
.github/workflows/multiarch-build.yml
vendored
@ -1,93 +0,0 @@
|
||||
name: Build Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
build-releases:
|
||||
strategy:
|
||||
matrix:
|
||||
arch: ["linux/amd64 x86_64", "linux/arm/v7 armv7h", "linux/arm64 aarch64"]
|
||||
name: Build ${{ matrix.arch }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Read info
|
||||
id: tags
|
||||
run: |
|
||||
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
arch="${{ matrix.arch }}"
|
||||
echo "PLATFORM=${arch%% *}" >> $GITHUB_OUTPUT
|
||||
echo "ARCH=${arch##* }" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build ${{ matrix.arch }} release
|
||||
run: |
|
||||
mkdir artifacts
|
||||
docker buildx build --platform ${{ steps.tags.outputs.platform }} \
|
||||
--build-arg VERSION=${{ steps.tags.outputs.version }} \
|
||||
--build-arg ARCH=${{ steps.tags.outputs.arch }} \
|
||||
--build-arg PREFIX="/usr" \
|
||||
-t yay:${{ steps.tags.outputs.arch }} . --load
|
||||
make docker-release ARCH=${{ steps.tags.outputs.arch }} VERSION=${{ steps.tags.outputs.version }} PREFIX="/usr"
|
||||
mv *.tar.gz artifacts
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: yay_${{ steps.tags.outputs.arch }}
|
||||
path: artifacts
|
||||
|
||||
create_release:
|
||||
name: Create release from this build
|
||||
needs: [build-releases]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Read info
|
||||
id: tags
|
||||
run: |
|
||||
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: yay_*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Create Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create ${{ steps.tags.outputs.tag }} \
|
||||
--title "${{ steps.tags.outputs.tag }}" \
|
||||
--generate-notes \
|
||||
./yay_${{ steps.tags.outputs.version }}_*.tar.gz
|
||||
|
||||
- name: Release Notary Action
|
||||
uses: docker://aevea/release-notary:latest
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
39
.github/workflows/testing-git.yml
vendored
39
.github/workflows/testing-git.yml
vendored
@ -1,39 +0,0 @@
|
||||
name: Test against pacman-git
|
||||
on:
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- "doc/**"
|
||||
- "**/*.po"
|
||||
- "README.md"
|
||||
- ".gitignore"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Lint and test yay (-git)
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/jguer/yay-builder:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: /home/runner/work/yay/yay/pacman-git
|
||||
key: ${{ runner.os }}-pacman-${{ hashFiles('/home/runner/work/yay/yay/pacman-git/PKGBUILD') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pacman-
|
||||
- name: checkout pacman-git
|
||||
run: |
|
||||
git -C ./pacman-git pull || git clone https://aur.archlinux.org/pacman-git
|
||||
useradd github
|
||||
echo 'github ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
||||
chmod -R 777 pacman-git
|
||||
su github -c 'cd pacman-git; yes | makepkg -i --nocheck'
|
||||
- name: Run Build and Tests with pacman-git
|
||||
run: |
|
||||
make test
|
44
.github/workflows/testing.yml
vendored
44
.github/workflows/testing.yml
vendored
@ -1,44 +0,0 @@
|
||||
name: Test against pacman
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Lint and test yay
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/jguer/yay-builder:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
- name: Lint
|
||||
env:
|
||||
GOFLAGS: -buildvcs=false -tags=next
|
||||
run: /app/bin/golangci-lint run -v ./...
|
||||
- name: Run Build and Tests
|
||||
run: make test
|
||||
|
||||
- name: Run Integration Tests
|
||||
continue-on-error: true
|
||||
run: |
|
||||
useradd -m yay &&
|
||||
chown -R yay:yay . &&
|
||||
cp -r ~/go/ /home/yay/go/ &&
|
||||
chown -R yay:yay /home/yay/go/ &&
|
||||
su yay -c "make test-integration"
|
||||
- name: Build yay Artifact
|
||||
env:
|
||||
GOFLAGS: -buildvcs=false -tags=next
|
||||
run: make
|
||||
- name: Upload yay Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: yay
|
||||
path: ./yay
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
17
.gitignore
vendored
17
.gitignore
vendored
@ -6,7 +6,10 @@
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
.vscode
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
@ -20,15 +23,3 @@ _cgo_export.*
|
||||
yay
|
||||
yay_*/
|
||||
*.tar.gz
|
||||
qemu-*
|
||||
.go
|
||||
|
||||
# Locale
|
||||
*.mo
|
||||
*.pot
|
||||
*.po~
|
||||
*.pprof
|
||||
|
||||
node_modules/
|
||||
xgotext
|
||||
.devcontainer/
|
@ -1,94 +0,0 @@
|
||||
version: "2"
|
||||
run:
|
||||
go: "1.20"
|
||||
linters:
|
||||
default: none
|
||||
enable:
|
||||
- bodyclose
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- errorlint
|
||||
- gochecknoinits
|
||||
- gocritic
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- govet
|
||||
- ineffassign
|
||||
- lll
|
||||
- misspell
|
||||
- nakedret
|
||||
- noctx
|
||||
- nolintlint
|
||||
- staticcheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- whitespace
|
||||
settings:
|
||||
dupl:
|
||||
threshold: 100
|
||||
funlen:
|
||||
lines: 100
|
||||
statements: 50
|
||||
goconst:
|
||||
min-len: 3
|
||||
min-occurrences: 4
|
||||
gocritic:
|
||||
enabled-tags:
|
||||
- diagnostic
|
||||
- experimental
|
||||
- opinionated
|
||||
- performance
|
||||
- style
|
||||
gocyclo:
|
||||
min-complexity: 15
|
||||
lll:
|
||||
line-length: 140
|
||||
misspell:
|
||||
locale: US
|
||||
nolintlint:
|
||||
require-explanation: false
|
||||
require-specific: false
|
||||
allow-unused: false
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
rules:
|
||||
- linters:
|
||||
- dupl
|
||||
- errcheck
|
||||
- errorlint
|
||||
- gochecknoinits
|
||||
- gocritic
|
||||
- godot
|
||||
- govet
|
||||
- lll
|
||||
- revive
|
||||
- staticcheck
|
||||
- wsl
|
||||
path: (.+)_test.go
|
||||
- path: (.+)\.go$
|
||||
text: G204
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
- goimports
|
||||
settings:
|
||||
goimports:
|
||||
local-prefixes:
|
||||
- github.com/Jguer/yay/v12
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
@ -1,29 +0,0 @@
|
||||
default_stages: [commit]
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/dnephin/pre-commit-golang
|
||||
rev: v0.5.1
|
||||
hooks:
|
||||
- id: go-fmt
|
||||
- id: golangci-lint
|
||||
- id: go-unit-tests
|
||||
- id: go-build
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
rev: v4.0.0-alpha.8 # Use the sha or tag you want to point at
|
||||
hooks:
|
||||
- id: prettier
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.5.0 # Use the ref you want to point at
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: check-json
|
||||
- id: check-yaml
|
||||
- id: check-added-large-files
|
||||
|
||||
- repo: https://github.com/commitizen-tools/commitizen
|
||||
rev: v3.15.0
|
||||
hooks:
|
||||
- id: commitizen
|
||||
stages: [commit-msg]
|
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -1,7 +0,0 @@
|
||||
{
|
||||
"go.lintTool": "golangci-lint",
|
||||
"gopls": {
|
||||
"formatting.gofumpt": true,
|
||||
"formatting.local": "github.com/Jguer/yay/v12"
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
# Contributing to yay
|
||||
|
||||
## Translation
|
||||
|
||||
[Transifex](https://www.transifex.com/yay-1/yay/)
|
||||
|
||||
## Quality Assurance
|
||||
|
||||
```sh
|
||||
pacman -S --needed git base-devel
|
||||
git clone https://aur.archlinux.org/yay-git.git
|
||||
cd yay-git
|
||||
makepkg -si
|
||||
```
|
||||
|
||||
Installing `yay-git` and using issues to help determine what's broken is already
|
||||
a very big help.
|
||||
|
||||
## Development
|
||||
|
||||
Contributors are always welcome!
|
||||
|
||||
If you plan to make any large changes or changes that may not be 100% agreed
|
||||
on, we suggest opening an issue detailing your ideas first.
|
||||
|
||||
Otherwise send us a pull request and we will be happy to review it.
|
||||
|
||||
### Vision
|
||||
|
||||
Yay is based on the design of [yaourt](https://github.com/archlinuxfr/yaourt), [apacman](https://github.com/oshazard/apacman) and [pacaur](https://github.com/rmarquis/pacaur). It is developed with these objectives in mind:
|
||||
|
||||
- Provide an interface for pacman
|
||||
- Yaourt-style interactive search/install
|
||||
- Minimal dependencies
|
||||
- Minimize user input
|
||||
|
||||
### Dependencies
|
||||
|
||||
Yay depends on:
|
||||
|
||||
- go (make only)
|
||||
- git
|
||||
- base-devel
|
||||
- pacman
|
||||
|
||||
Note: Yay also depends on a few other projects, these are pulled as go modules.
|
||||
|
||||
### Building
|
||||
|
||||
Run `make` to build Yay. This command will generate a binary called `yay` in
|
||||
the same directory as the Makefile.
|
||||
|
||||
#### Docker Release
|
||||
|
||||
`make docker-release` will build the release packages for `aarch64` and for `x86_64`.
|
||||
|
||||
For `aarch64` to run on a `x86_64` platform `qemu-user-static(-bin)` must be
|
||||
installed.
|
||||
|
||||
```
|
||||
docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
||||
```
|
||||
|
||||
will register QEMU in the build agent. ARM builds tend to crash sometimes but
|
||||
repeated runs tend to succeed.
|
||||
|
||||
### Code Style
|
||||
|
||||
All code should be formatted through `go fmt`. This tool will automatically
|
||||
format code for you. We recommend, however, that you write code in the proper
|
||||
style and use `go fmt` only to catch mistakes.
|
||||
|
||||
Use [pre-commit](https://pre-commit.com/) to validate your commits against the various
|
||||
linters configured for this repository.
|
||||
|
||||
### Testing
|
||||
|
||||
Run `make test` to test Yay. This command will verify that the code is
|
||||
formatted correctly, run the code through `go vet`, and run unit tests.
|
12
Dockerfile
12
Dockerfile
@ -1,12 +0,0 @@
|
||||
FROM ghcr.io/jguer/yay-builder:latest
|
||||
LABEL maintainer="Jguer,docker@jguer.space"
|
||||
|
||||
ARG VERSION
|
||||
ARG PREFIX
|
||||
ARG ARCH
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN make release VERSION=${VERSION} PREFIX=${PREFIX} ARCH=${ARCH}
|
49
Gopkg.lock
generated
Normal file
49
Gopkg.lock
generated
Normal file
@ -0,0 +1,49 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:4e8f84eb856dd3ed05982f065caf7866a4995be9cc3718614dcecbd57e26c260"
|
||||
name = "github.com/Morganamilo/go-pacmanconf"
|
||||
packages = [
|
||||
".",
|
||||
"ini",
|
||||
]
|
||||
pruneopts = "NUT"
|
||||
revision = "9c5265e1b14f7e21dafabbad9ccf801d3815d707"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:5f709618dc8a0ff9221d3685c95d69ed7d80ca94e58f3483f5d9bdefb4e6bb25"
|
||||
name = "github.com/Morganamilo/go-srcinfo"
|
||||
packages = ["."]
|
||||
pruneopts = "NUT"
|
||||
revision = "368edc79b2c53cd9c065818fd4e65843ef3e9e11"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:6eef31522b3a2349e9399c903ffa76c084c7fb9ef9d17a4e3da420649b0f5d17"
|
||||
name = "github.com/jguer/go-alpm"
|
||||
packages = ["."]
|
||||
pruneopts = "NUT"
|
||||
revision = "643c287316a5456348cc689e1f2c980410e17d47"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:07c508c49b9c13cf582c2b986635d0acd11e113e0535fa4b147026e15bc64185"
|
||||
name = "github.com/mikkeloscar/aur"
|
||||
packages = ["."]
|
||||
pruneopts = "NUT"
|
||||
revision = "f998dbf94dc47ef839c76740efeb673d3459be1f"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/Morganamilo/go-pacmanconf",
|
||||
"github.com/Morganamilo/go-srcinfo",
|
||||
"github.com/jguer/go-alpm",
|
||||
"github.com/mikkeloscar/aur",
|
||||
]
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
20
Gopkg.toml
Normal file
20
Gopkg.toml
Normal file
@ -0,0 +1,20 @@
|
||||
[prune]
|
||||
non-go = true
|
||||
unused-packages = true
|
||||
go-tests = true
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/jguer/go-alpm"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/mikkeloscar/aur"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/Morganamilo/go-srcinfo"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/Morganamilo/go-pacmanconf"
|
12
ISSUE_TEMPLATE.md
Normal file
12
ISSUE_TEMPLATE.md
Normal file
@ -0,0 +1,12 @@
|
||||
#### Affected Version
|
||||
<!-- Please ensure you are using the latest yay-git package -->
|
||||
<!-- Use `yay -V` to get installed version -->
|
||||
<!-- Example: `yay v3.373` -->
|
||||
|
||||
#### Issue
|
||||
|
||||
#### Steps to reproduce
|
||||
<!-- Exact commands are useful -->
|
||||
1.
|
||||
2.
|
||||
3.
|
146
Makefile
146
Makefile
@ -1,134 +1,58 @@
|
||||
export GO111MODULE=on
|
||||
GOPROXY ?= https://proxy.golang.org,direct
|
||||
export GOPROXY
|
||||
.PHONY: all default install uninstall test build release clean package
|
||||
|
||||
BUILD_TAG = devel
|
||||
ARCH ?= $(shell uname -m)
|
||||
BIN := yay
|
||||
PREFIX := /usr
|
||||
DESTDIR :=
|
||||
GO ?= go
|
||||
|
||||
MAJORVERSION := 8
|
||||
MINORVERSION ?= $(shell git rev-list --count master)
|
||||
VERSION ?= ${MAJORVERSION}.${MINORVERSION}
|
||||
|
||||
LDFLAGS := -ldflags '-s -w -X main.version=${VERSION}'
|
||||
ARCH := $(shell uname -m)
|
||||
PKGNAME := yay
|
||||
PREFIX := /usr/local
|
||||
BINNAME := yay
|
||||
PACKAGE := ${PKGNAME}_${VERSION}_${ARCH}
|
||||
|
||||
MAJORVERSION := 12
|
||||
MINORVERSION := 0
|
||||
PATCHVERSION := 0
|
||||
VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
|
||||
export GOPATH=$(shell pwd)/.go
|
||||
|
||||
LOCALEDIR := po
|
||||
SYSTEMLOCALEPATH := $(PREFIX)/share/locale/
|
||||
|
||||
# ls -1 po | sed -e 's/\.po$//' | paste -sd " "
|
||||
LANGS := ca cs de en es eu fr_FR he id it_IT ja ko pl_PL pt_BR pt ru_RU ru sv tr uk zh_CN zh_TW
|
||||
POTFILE := default.pot
|
||||
POFILES := $(addprefix $(LOCALEDIR)/,$(addsuffix .po,$(LANGS)))
|
||||
MOFILES := $(POFILES:.po=.mo)
|
||||
|
||||
FLAGS ?= -trimpath -mod=readonly -modcacherw
|
||||
EXTRA_FLAGS ?= -buildmode=pie
|
||||
LDFLAGS := -X "main.yayVersion=${VERSION}" -X "main.localePath=${SYSTEMLOCALEPATH}" -linkmode=external -compressdwarf=false
|
||||
|
||||
RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
|
||||
PACKAGE := $(RELEASE_DIR).tar.gz
|
||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
|
||||
.PRECIOUS: ${LOCALEDIR}/%.po
|
||||
|
||||
.PHONY: default
|
||||
default: build
|
||||
|
||||
.PHONY: all
|
||||
all: | clean release
|
||||
all: | clean package
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(GO) clean $(FLAGS) -i ./...
|
||||
rm -rf $(BIN) $(PKGNAME)_*
|
||||
|
||||
.PHONY: test_lint
|
||||
test_lint: test lint
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(GO) test -race -covermode=atomic $(FLAGS) ./...
|
||||
|
||||
.PHONY: test-integration
|
||||
test-integration:
|
||||
$(GO) test -tags=integration $(FLAGS) ./...
|
||||
|
||||
.PHONY: build
|
||||
build: $(BIN)
|
||||
|
||||
.PHONY: release
|
||||
release: $(PACKAGE)
|
||||
|
||||
.PHONY: docker-release-all
|
||||
docker-release-all:
|
||||
make docker-release-armv7h ARCH=armv7h
|
||||
make docker-release-x86_64 ARCH=x86_64
|
||||
make docker-release-aarch64 ARCH=aarch64
|
||||
|
||||
docker-release:
|
||||
docker create --name yay-$(ARCH) yay:${ARCH} /bin/sh
|
||||
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
|
||||
docker container rm yay-$(ARCH)
|
||||
|
||||
.PHONY: docker-build
|
||||
docker-build:
|
||||
docker build -t yay-$(ARCH):${VERSION} .
|
||||
docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make build VERSION=${VERSION} PREFIX=${PREFIX}
|
||||
docker cp yay-$(ARCH):/app/${BIN} $(BIN)
|
||||
docker container rm yay-$(ARCH)
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
GOFLAGS="$(FLAGS)" golangci-lint run ./...
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
.PHONY: install
|
||||
install: build ${MOFILES}
|
||||
install -Dm755 ${BIN} $(DESTDIR)$(PREFIX)/bin/${BIN}
|
||||
install:
|
||||
install -Dm755 ${BINNAME} $(DESTDIR)$(PREFIX)/bin/${BINNAME}
|
||||
install -Dm644 doc/${PKGNAME}.8 $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
|
||||
install -Dm644 completions/bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
|
||||
install -Dm644 completions/zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
|
||||
install -Dm644 completions/fish $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
|
||||
for lang in ${LANGS}; do \
|
||||
install -Dm644 ${LOCALEDIR}/$${lang}.mo $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/${PKGNAME}.mo; \
|
||||
done
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/${BIN}
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/${BINNAME}
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
|
||||
for lang in ${LANGS}; do \
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/${PKGNAME}.mo; \
|
||||
done
|
||||
|
||||
$(BIN): $(SOURCES)
|
||||
$(GO) build $(FLAGS) -ldflags '$(LDFLAGS)' $(EXTRA_FLAGS) -o $@
|
||||
test:
|
||||
gofmt -l *.go
|
||||
@test -z "$$(gofmt -l *.go)" || (echo "Files need to be linted" && false)
|
||||
go vet
|
||||
go test -v
|
||||
|
||||
$(RELEASE_DIR):
|
||||
mkdir $(RELEASE_DIR)
|
||||
build:
|
||||
go build -v ${LDFLAGS} -o ${BINNAME}
|
||||
|
||||
$(PACKAGE): $(BIN) $(RELEASE_DIR) ${MOFILES}
|
||||
strip ${BIN}
|
||||
cp -t $(RELEASE_DIR) ${BIN} doc/${PKGNAME}.8 completions/* ${MOFILES}
|
||||
tar -czvf $(PACKAGE) $(RELEASE_DIR)
|
||||
release: | test build
|
||||
mkdir ${PACKAGE}
|
||||
cp ./${BINNAME} ${PACKAGE}/
|
||||
cp ./doc/${PKGNAME}.8 ${PACKAGE}/
|
||||
cp ./completions/zsh ${PACKAGE}/
|
||||
cp ./completions/fish ${PACKAGE}/
|
||||
cp ./completions/bash ${PACKAGE}/
|
||||
|
||||
locale:
|
||||
xgotext -in . -out po
|
||||
mv po/default.pot po/en.po
|
||||
for lang in ${LANGS}; do \
|
||||
test -f po/$$lang.po || msginit --no-translator -l po/$$lang.po -i po/${POTFILE} -o po/$$lang.po; \
|
||||
msgmerge -U po/$$lang.po po/${POTFILE}; \
|
||||
touch po/$$lang.po; \
|
||||
done
|
||||
package: release
|
||||
tar -czvf ${PACKAGE}.tar.gz ${PACKAGE}
|
||||
clean:
|
||||
rm -rf ${PKGNAME}_*
|
||||
rm -f ${BINNAME}
|
||||
|
||||
${LOCALEDIR}/%.mo: ${LOCALEDIR}/%.po
|
||||
msgfmt $< -o $@
|
||||
|
293
README.md
293
README.md
@ -1,162 +1,47 @@
|
||||
[](https://aur.archlinux.org/packages/yay/)
|
||||
[](https://aur.archlinux.org/packages/yay-bin/)
|
||||
[](https://aur.archlinux.org/packages/yay-git/)
|
||||

|
||||
[](https://github.com/Jguer/yay/blob/master/LICENSE)
|
||||
|
||||
# Yay
|
||||
|
||||
Yet Another Yogurt - An AUR Helper Written in Go
|
||||
|
||||
### Help translate yay: [Transifex](https://www.transifex.com/yay-1/yay/)
|
||||
#### Packages
|
||||
|
||||
[](https://aur.archlinux.org/packages/yay/) [](https://aur.archlinux.org/packages/yay-bin/) [](https://aur.archlinux.org/packages/yay-git/) [](https://github.com/Jguer/yay/blob/master/LICENSE)
|
||||
|
||||
## Objectives
|
||||
|
||||
There's a point in everyone's life when you feel the need to write an AUR helper because there are only about 20 of them.
|
||||
So say hi to 20+1.
|
||||
|
||||
Yay is based on the design of [yaourt](https://github.com/archlinuxfr/yaourt), [apacman](https://github.com/oshazard/apacman) and [pacaur](https://github.com/rmarquis/pacaur). It is developed with these objectives in mind:
|
||||
|
||||
* Provide an interface for pacman
|
||||
* Yaourt-style interactive search/install
|
||||
* Minimal dependencies
|
||||
* Minimize user input
|
||||
* Know when git packages are due for upgrades
|
||||
|
||||
## Features
|
||||
|
||||
- Advanced dependency solving
|
||||
- PKGBUILD downloading from ABS or AUR
|
||||
- Completions for AUR packages
|
||||
- Query user up-front for all input (prior to starting builds)
|
||||
- Narrow search (`yay linux header` will first search `linux` and then narrow on `header`)
|
||||
- Find matching package providers during search and allow selection
|
||||
- Remove make dependencies at the end of the build process
|
||||
- Build local PKGBUILDs with AUR dependencies
|
||||
- Un/Vote for packages
|
||||
|
||||
[](https://asciinema.org/a/399431)
|
||||
|
||||
[](https://asciinema.org/a/399433)
|
||||
* Perform advanced dependency solving
|
||||
* Download PKGBUILDs from ABS or AUR
|
||||
* Tab-complete the AUR
|
||||
* Query user up-front for all input (prior to starting builds)
|
||||
* Narrow search terms (`yay linux header` will first search `linux` and then narrow on `header`)
|
||||
* Find matching package providers during search and allow selection
|
||||
* Remove make dependencies at the end of the build process
|
||||
* Run without sourcing PKGBUILD
|
||||
|
||||
## Installation
|
||||
|
||||
If you are migrating from another AUR helper, you can simply install Yay with that helper.
|
||||
|
||||
> [!WARNING]
|
||||
> We are using `sudo` in these examples, you can switch that out for a different privilege escalation tool.
|
||||
|
||||
### Source
|
||||
|
||||
The initial installation of Yay can be done by cloning the PKGBUILD and
|
||||
Alternatively, the initial installation of Yay can be done by cloning the PKGBUILD and
|
||||
building with makepkg:
|
||||
|
||||
We make sure we have the `base-devel` package group installed.
|
||||
|
||||
```sh
|
||||
sudo pacman -S --needed git base-devel
|
||||
git clone https://aur.archlinux.org/yay.git
|
||||
cd yay
|
||||
makepkg -si
|
||||
```
|
||||
|
||||
If you want to do all of this at once, we can chain the commands like so:
|
||||
|
||||
```sh
|
||||
sudo pacman -S --needed git base-devel && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si
|
||||
```
|
||||
|
||||
### Binary
|
||||
|
||||
If you do not want to compile yay yourself you can use the builds generated by
|
||||
GitHub Actions.
|
||||
|
||||
```sh
|
||||
sudo pacman -S --needed git base-devel
|
||||
git clone https://aur.archlinux.org/yay-bin.git
|
||||
cd yay-bin
|
||||
makepkg -si
|
||||
```
|
||||
|
||||
If you want to do all of this at once, we can chain the commands like so:
|
||||
|
||||
```sh
|
||||
sudo pacman -S --needed git base-devel && git clone https://aur.archlinux.org/yay-bin.git && cd yay-bin && makepkg -si
|
||||
```
|
||||
|
||||
### Other distributions
|
||||
|
||||
If you're using Manjaro or [another distribution that packages `yay`](https://repology.org/project/yay/versions)
|
||||
you can simply install yay using pacman (as root):
|
||||
|
||||
```sh
|
||||
pacman -S --needed git base-devel yay
|
||||
```
|
||||
> [!WARNING]
|
||||
> distributions sometimes lag updating yay on their repositories.
|
||||
|
||||
## First Use
|
||||
|
||||
#### Development packages upgrade
|
||||
|
||||
- Use `yay -Y --gendb` to generate a development package database for `*-git`
|
||||
packages that were installed without yay.
|
||||
This command should only be run once.
|
||||
|
||||
- `yay -Syu --devel` will then check for development package updates
|
||||
|
||||
- Use `yay -Y --devel --save` to make development package updates permanently
|
||||
enabled (`yay` and `yay -Syu` will then always check dev packages)
|
||||
|
||||
## Examples of Custom Operations
|
||||
|
||||
| Command | Description |
|
||||
| --------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
||||
| `yay` | Alias to `yay -Syu`. |
|
||||
| `yay <Search Term>` | Present package-installation selection menu. |
|
||||
| `yay -Bi <dir>` | Install dependencies and build a local PKGBUILD. |
|
||||
| `yay -G <AUR Package>` | Download PKGBUILD from ABS or AUR. (yay v12.0+) |
|
||||
| `yay -Gp <AUR Package>` | Print to stdout PKGBUILD from ABS or AUR. |
|
||||
| `yay -Ps` | Print system statistics. |
|
||||
| `yay -Syu --devel` | Perform system upgrade, but also check for development package updates. |
|
||||
| `yay -Syu --timeupdate` | Perform system upgrade and use PKGBUILD modification time (not version number) to determine update. |
|
||||
| `yay -Wu <AUR Package>` | Unvote for package (Requires setting `AUR_USERNAME` and `AUR_PASSWORD` environment variables) (yay v11.3+) |
|
||||
| `yay -Wv <AUR Package>` | Vote for package (Requires setting `AUR_USERNAME` and `AUR_PASSWORD` environment variables). (yay v11.3+) |
|
||||
| `yay -Y --combinedupgrade --save` | Make combined upgrade the default mode. |
|
||||
| `yay -Y --gendb` | Generate development package database used for devel update. |
|
||||
| `yay -Yc` | Clean unneeded dependencies. |
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
- **Yay does not display colored output. How do I fix it?**
|
||||
|
||||
Make sure you have the `Color` option in your `/etc/pacman.conf`
|
||||
(see issue [#123](https://github.com/Jguer/yay/issues/123)).
|
||||
|
||||
- **Sometimes diffs are printed to the terminal, and other times they are paged via less. How do I fix this?**
|
||||
|
||||
Yay uses `git diff` to display diffs, which by default tells less not to
|
||||
page if the output can fit into one terminal length. This behavior can be
|
||||
overridden by exporting your own flags (`export LESS=SRX`).
|
||||
|
||||
- **Yay is not asking me to edit PKGBUILDS, and I don't like the diff menu! What can I do?**
|
||||
|
||||
`yay --editmenu --diffmenu=false --save`
|
||||
|
||||
- **How can I tell Yay to act only on AUR packages, or only on repo packages?**
|
||||
|
||||
`yay -{OPERATION} --aur`
|
||||
`yay -{OPERATION} --repo`
|
||||
|
||||
- **A `Flagged Out Of Date AUR Packages` message is displayed. Why doesn't Yay update them?**
|
||||
|
||||
This message does not mean that updated AUR packages are available. It means
|
||||
the packages have been flagged out of date on the AUR, but
|
||||
their maintainers have not yet updated the `PKGBUILD`s
|
||||
(see [outdated AUR packages](https://wiki.archlinux.org/index.php/Arch_User_Repository#Foo_in_the_AUR_is_outdated.3B_what_should_I_do.3F)).
|
||||
|
||||
- **Yay doesn't install dependencies added to a PKGBUILD during installation.**
|
||||
|
||||
Yay resolves all dependencies ahead of time. You are free to edit the
|
||||
PKGBUILD in any way, but any problems you cause are your own and should not be
|
||||
reported unless they can be reproduced with the original PKGBUILD.
|
||||
|
||||
- **I know my `-git` package has updates but yay doesn't offer to update it**
|
||||
|
||||
Yay uses a hash cache for development packages. Normally it is updated at the end of the package install with the message `Found git repo`.
|
||||
If you transition between aur helpers and did not install the devel package using yay at some point, it is possible it never got added to the cache. `yay -Y --gendb` will fix the current version of every devel package and start checking from there.
|
||||
|
||||
- **I want to help out!**
|
||||
|
||||
Check [CONTRIBUTING.md](./CONTRIBUTING.md) for more information.
|
||||
|
||||
## Support
|
||||
|
||||
All support related to Yay should be requested via GitHub issues. Since Yay is not
|
||||
@ -165,25 +50,121 @@ forums, AUR comments or other official channels.
|
||||
|
||||
A broken AUR package should be reported as a comment on the package's AUR page.
|
||||
A package may only be considered broken if it fails to build with makepkg.
|
||||
|
||||
Reports should be made using makepkg and include the full output as well as any
|
||||
other relevant information. Never make reports using Yay or any other external
|
||||
tools.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributors are always welcome!
|
||||
|
||||
If you plan to make any large changes or changes that may not be 100% agreed
|
||||
on, we suggest opening an issue detailing your ideas first.
|
||||
|
||||
Otherwise send us a pull request and we will be happy to review it.
|
||||
|
||||
### Dependencies
|
||||
|
||||
Yay depends on:
|
||||
|
||||
* go (make only)
|
||||
* git
|
||||
* base-devel
|
||||
|
||||
Note: Yay also depends on a few other projects (as vendored dependencies). These
|
||||
projects are stored in `vendor/`, are built into yay at build time, and do not
|
||||
need to be installed separately. These files are managed by
|
||||
[dep](https://github.com/golang/dep) and should not be modified manually.
|
||||
|
||||
Following are the dependencies managed under dep:
|
||||
|
||||
* https://github.com/Jguer/go-alpm
|
||||
* https://github.com/Morganamilo/go-srcinfo
|
||||
* https://github.com/mikkeloscar/aur
|
||||
|
||||
### Building
|
||||
|
||||
Run `make` to build Yay. This command will generate a binary called `yay` in
|
||||
the same directory as the Makefile.
|
||||
|
||||
Note: Yay's Makefile automatically sets the `GOPATH` to `$PWD/.go`. This path will
|
||||
ensure dependencies in `vendor/` are built. Running manual go commands such as
|
||||
`go build` will require that you either set the `GOPATH` manually or `go get`
|
||||
the vendored dependencies into your own `GOPATH`.
|
||||
|
||||
### Code Style
|
||||
|
||||
All code should be formatted through `go fmt`. This tool will automatically
|
||||
format code for you. We recommend, however, that you write code in the proper
|
||||
style and use `go fmt` only to catch mistakes.
|
||||
|
||||
### Testing
|
||||
|
||||
Run `make test` to test Yay. This command will verify that the code is
|
||||
formatted correctly, run the code through `go vet`, and run unit tests.
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
#### Yay does not display colored output. How do I fix it?
|
||||
Make sure you have the `Color` option in your `/etc/pacman.conf`
|
||||
(see issue [#123](https://github.com/Jguer/yay/issues/123)).
|
||||
|
||||
#### Yay is not prompting to skip packages during system upgrade.
|
||||
The default behavior was changed after
|
||||
[v8.918](https://github.com/Jguer/yay/releases/tag/v8.918)
|
||||
(see [3bdb534](https://github.com/Jguer/yay/commit/3bdb5343218d99d40f8a449b887348611f6bdbfc)
|
||||
and issue [#554](https://github.com/Jguer/yay/issues/554)).
|
||||
To restore the package-skip behavior use `--combinedupgrade` (make
|
||||
it permanent by appending `--save`). Note: skipping packages will leave your
|
||||
system in a
|
||||
[partially-upgraded state](https://wiki.archlinux.org/index.php/System_maintenance#Partial_upgrades_are_unsupported).
|
||||
|
||||
#### Sometimes diffs are printed to the terminal, and other times they are paged via less. How do I fix this?
|
||||
Yay uses `git diff` to display diffs, which by default tells less not to
|
||||
page if the output can fit into one terminal length. This behavior can be
|
||||
overridden by exporting your own flags (`export LESS=SRX`).
|
||||
|
||||
#### Yay is not asking me to edit PKGBUILDS, and I don't like the diff menu! What can I do?
|
||||
`yay --editmenu --nodiffmenu --save`
|
||||
|
||||
#### How can I tell Yay to act only on AUR packages, or only on repo packages?
|
||||
`yay -{OPERATION} --aur`
|
||||
`yay -{OPERATION} --repo`
|
||||
|
||||
#### An `Out Of Date AUR Packages` message is displayed. Why doesn't Yay update them?
|
||||
This message does not mean that updated AUR packages are available. It means
|
||||
the packages have been flagged out of date on the AUR, but
|
||||
their maintainers have not yet updated the `PKGBUILD`s
|
||||
(see [outdated AUR packages](https://wiki.archlinux.org/index.php/Arch_User_Repository#Foo_in_the_AUR_is_outdated.3B_what_should_I_do.3F)).
|
||||
|
||||
#### Yay doesn't install dependencies added to a PKGBUILD during installation.
|
||||
Yay resolves all dependencies ahead of time. You are free to edit the
|
||||
PKGBUILD in any way, but any problems you cause are your own and should not be
|
||||
reported unless they can be reproduced with the original PKGBUILD.
|
||||
|
||||
## Examples of Custom Operations
|
||||
|
||||
`yay <Search Term>`
|
||||
Present package-installation selection menu.
|
||||
|
||||
`yay -Ps`
|
||||
Print system statistics.
|
||||
|
||||
`yay -Yc`
|
||||
Clean unneeded dependencies.
|
||||
|
||||
`yay -G <AUR Package>`
|
||||
Download PKGBUILD from ABS or AUR.
|
||||
|
||||
`yay -Y --gendb`
|
||||
Generate development package database used for devel update.
|
||||
|
||||
`yay -Syu --devel --timeupdate`
|
||||
Perform system upgrade, but also check for development package updates and use
|
||||
PKGBUILD modification time (not version number) to determine update.
|
||||
|
||||
## Images
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/Jguer/jguer.github.io/refs/heads/master/yay/yay.png" width="42%">
|
||||
<img src="https://raw.githubusercontent.com/Jguer/jguer.github.io/refs/heads/master/yay/yay-s.png" width="42%">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/Jguer/jguer.github.io/refs/heads/master/yay/yay-y.png" width="42%">
|
||||
<img src="https://raw.githubusercontent.com/Jguer/jguer.github.io/refs/heads/master/yay/yay-ps.png" width="42%">
|
||||
</p>
|
||||
|
||||
### Other AUR helpers/tools
|
||||
|
||||
- [paru](https://github.com/morganamilo/paru)
|
||||
- [aurutils](https://github.com/AladW/aurutils)
|
||||
- [pikaur](https://github.com/actionless/pikaur)
|
||||
<img src="https://cdn.rawgit.com/Jguer/jguer.github.io/5412b8d6/yay/yay-ps.png" width="450">
|
||||
<img src="https://cdn.rawgit.com/Jguer/jguer.github.io/5412b8d6/yay/yayupgrade.png" width="450">
|
||||
<img src="https://cdn.rawgit.com/Jguer/jguer.github.io/5412b8d6/yay/yaysearch.png" width="450">
|
||||
|
13
SECURITY.md
13
SECURITY.md
@ -1,13 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
Thank you for helping keep yay secure!
|
||||
|
||||
## Supported Versions
|
||||
|
||||
We only provide security updates and support for the latest released version of yay. Please ensure you are using the most up-to-date version before reporting vulnerabilities.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you discover a security vulnerability, please email us at [security@jguer.space](mailto:security@jguer.space). We will respond as quickly as possible and coordinate a fix.
|
||||
|
||||
We appreciate responsible disclosure and your help in making this project safe for everyone.
|
97
callbacks.go
Normal file
97
callbacks.go
Normal file
@ -0,0 +1,97 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
func questionCallback(question alpm.QuestionAny) {
|
||||
if qi, err := question.QuestionInstallIgnorepkg(); err == nil {
|
||||
qi.SetInstall(true)
|
||||
}
|
||||
|
||||
qp, err := question.QuestionSelectProvider()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
size := 0
|
||||
|
||||
qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
|
||||
size++
|
||||
return nil
|
||||
})
|
||||
|
||||
fmt.Print(bold(cyan(":: ")))
|
||||
str := bold(fmt.Sprintf(bold("There are %d providers available for %s:"), size, qp.Dep()))
|
||||
|
||||
size = 1
|
||||
var db string
|
||||
|
||||
qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
|
||||
thisDb := pkg.DB().Name()
|
||||
|
||||
if db != thisDb {
|
||||
db = thisDb
|
||||
str += bold(cyan("\n:: ")) + bold("Repository "+db+"\n ")
|
||||
}
|
||||
str += fmt.Sprintf("%d) %s ", size, pkg.Name())
|
||||
size++
|
||||
return nil
|
||||
})
|
||||
|
||||
fmt.Println(str)
|
||||
|
||||
for {
|
||||
fmt.Print("\nEnter a number (default=1): ")
|
||||
|
||||
if config.NoConfirm {
|
||||
fmt.Println()
|
||||
break
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
numberBuf, overflow, err := reader.ReadLine()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
break
|
||||
}
|
||||
|
||||
if overflow {
|
||||
fmt.Println("Input too long")
|
||||
continue
|
||||
}
|
||||
|
||||
if string(numberBuf) == "" {
|
||||
break
|
||||
}
|
||||
|
||||
num, err := strconv.Atoi(string(numberBuf))
|
||||
if err != nil {
|
||||
fmt.Printf("%s invalid number: %s\n", red("error:"), string(numberBuf))
|
||||
continue
|
||||
}
|
||||
|
||||
if num < 1 || num > size {
|
||||
fmt.Printf("%s invalid value: %d is not between %d and %d\n", red("error:"), num, 1, size)
|
||||
continue
|
||||
}
|
||||
|
||||
qp.SetUseIndex(num - 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func logCallback(level alpm.LogLevel, str string) {
|
||||
switch level {
|
||||
case alpm.LogWarning:
|
||||
fmt.Print(bold(yellow(smallArrow)), " ", str)
|
||||
case alpm.LogError:
|
||||
fmt.Print(bold(red(smallArrow)), " ", str)
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
FROM docker.io/ljmf00/archlinux:devel
|
||||
LABEL maintainer="Jguer,docker@jguer.space"
|
||||
|
||||
ENV GO111MODULE=on
|
||||
WORKDIR /app
|
||||
|
||||
RUN sed -i '/^\[community\]/,/^\[/ s/^/#/' /etc/pacman.conf
|
||||
|
||||
COPY go.mod .
|
||||
|
||||
RUN pacman-key --init && pacman -Sy && pacman -S --overwrite=* --noconfirm archlinux-keyring && \
|
||||
pacman -Su --overwrite=* --needed --noconfirm pacman doxygen meson asciidoc go git gcc make sudo base-devel && \
|
||||
rm -rfv /var/cache/pacman/* /var/lib/pacman/sync/* && \
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.1.5 && \
|
||||
go mod download
|
168
clean.go
168
clean.go
@ -1,122 +1,123 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
)
|
||||
|
||||
// CleanDependencies removes all dangling dependencies in system.
|
||||
func cleanDependencies(ctx context.Context, cfg *settings.Configuration,
|
||||
cmdBuilder exe.ICmdBuilder, cmdArgs *parser.Arguments, dbExecutor db.Executor,
|
||||
removeOptional bool,
|
||||
) error {
|
||||
hanging := hangingPackages(removeOptional, dbExecutor)
|
||||
// GetPkgbuild gets the pkgbuild of the package 'pkg' trying the ABS first and then the AUR trying the ABS first and then the AUR.
|
||||
|
||||
// RemovePackage removes package from VCS information
|
||||
func removeVCSPackage(pkgs []string) {
|
||||
updated := false
|
||||
|
||||
for _, pkgName := range pkgs {
|
||||
if _, ok := savedInfo[pkgName]; ok {
|
||||
delete(savedInfo, pkgName)
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
|
||||
if updated {
|
||||
saveVCSInfo()
|
||||
}
|
||||
}
|
||||
|
||||
// CleanDependencies removes all dangling dependencies in system
|
||||
func cleanDependencies(removeOptional bool) error {
|
||||
hanging, err := hangingPackages(removeOptional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(hanging) != 0 {
|
||||
return cleanRemove(ctx, cfg, cmdBuilder, cmdArgs, hanging)
|
||||
return cleanRemove(hanging)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanRemove sends a full removal command to pacman with the pkgName slice.
|
||||
func cleanRemove(ctx context.Context, cfg *settings.Configuration,
|
||||
cmdBuilder exe.ICmdBuilder, cmdArgs *parser.Arguments, pkgNames []string,
|
||||
) error {
|
||||
// CleanRemove sends a full removal command to pacman with the pkgName slice
|
||||
func cleanRemove(pkgNames []string) (err error) {
|
||||
if len(pkgNames) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arguments := cmdArgs.CopyGlobal()
|
||||
if err := arguments.AddArg("R", "s", "u"); err != nil {
|
||||
return err
|
||||
}
|
||||
arguments.AddTarget(pkgNames...)
|
||||
arguments := makeArguments()
|
||||
arguments.addArg("R")
|
||||
arguments.addTarget(pkgNames...)
|
||||
|
||||
return cmdBuilder.Show(
|
||||
cmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, cfg.Mode, settings.NoConfirm))
|
||||
return show(passToPacman(arguments))
|
||||
}
|
||||
|
||||
func syncClean(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
func syncClean(parser *arguments) error {
|
||||
var err error
|
||||
keepInstalled := false
|
||||
keepCurrent := false
|
||||
|
||||
_, removeAll, _ := cmdArgs.GetArg("c", "clean")
|
||||
_, removeAll, _ := parser.getArg("c", "clean")
|
||||
|
||||
for _, v := range run.PacmanConf.CleanMethod {
|
||||
switch v {
|
||||
case "KeepInstalled":
|
||||
for _, v := range pacmanConf.CleanMethod {
|
||||
if v == "KeepInstalled" {
|
||||
keepInstalled = true
|
||||
case "KeepCurrent":
|
||||
} else if v == "KeepCurrent" {
|
||||
keepCurrent = true
|
||||
}
|
||||
}
|
||||
|
||||
if run.Cfg.Mode.AtLeastRepo() {
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm)); err != nil {
|
||||
if mode == ModeRepo || mode == ModeAny {
|
||||
if err = show(passToPacman(parser)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !run.Cfg.Mode.AtLeastAUR() {
|
||||
if !(mode == ModeAUR || mode == ModeAny) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var question string
|
||||
if removeAll {
|
||||
question = gotext.Get("Do you want to remove ALL AUR packages from cache?")
|
||||
question = "Do you want to remove ALL AUR packages from cache?"
|
||||
} else {
|
||||
question = gotext.Get("Do you want to remove all other AUR packages from cache?")
|
||||
question = "Do you want to remove all other AUR packages from cache?"
|
||||
}
|
||||
|
||||
run.Logger.Println(gotext.Get("\nBuild directory:"), run.Cfg.BuildDir)
|
||||
fmt.Printf("\nBuild directory: %s\n", config.BuildDir)
|
||||
|
||||
if run.Logger.ContinueTask(question, true, settings.NoConfirm) {
|
||||
if err := cleanAUR(ctx, run, keepInstalled, keepCurrent, removeAll, dbExecutor); err != nil {
|
||||
return err
|
||||
}
|
||||
if continueTask(question, true) {
|
||||
err = cleanAUR(keepInstalled, keepCurrent, removeAll)
|
||||
}
|
||||
|
||||
if removeAll {
|
||||
return nil
|
||||
if err != nil || removeAll {
|
||||
return err
|
||||
}
|
||||
|
||||
if run.Logger.ContinueTask(gotext.Get("Do you want to remove ALL untracked AUR files?"), true, settings.NoConfirm) {
|
||||
return cleanUntracked(ctx, run)
|
||||
if continueTask("Do you want to remove ALL untracked AUR files?", true) {
|
||||
return cleanUntracked()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanAUR(ctx context.Context, run *runtime.Runtime,
|
||||
keepInstalled, keepCurrent, removeAll bool, dbExecutor db.Executor,
|
||||
) error {
|
||||
run.Logger.Println(gotext.Get("removing AUR packages from cache..."))
|
||||
func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
|
||||
fmt.Println("removing AUR packages from cache...")
|
||||
|
||||
installedBases := mapset.NewThreadUnsafeSet[string]()
|
||||
inAURBases := mapset.NewThreadUnsafeSet[string]()
|
||||
installedBases := make(stringSet)
|
||||
inAURBases := make(stringSet)
|
||||
|
||||
remotePackages := dbExecutor.InstalledRemotePackages()
|
||||
_, remotePackages, _, _, err := filterPackages()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(run.Cfg.BuildDir)
|
||||
files, err := ioutil.ReadDir(config.BuildDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cachedPackages := make([]string, 0, len(files))
|
||||
|
||||
for _, file := range files {
|
||||
if !file.IsDir() {
|
||||
continue
|
||||
@ -130,23 +131,21 @@ func cleanAUR(ctx context.Context, run *runtime.Runtime,
|
||||
// Querying the AUR is slow and needs internet so don't do it if we
|
||||
// don't need to.
|
||||
if keepCurrent {
|
||||
info, errInfo := run.AURClient.Get(ctx, &aur.Query{
|
||||
Needles: cachedPackages,
|
||||
})
|
||||
if errInfo != nil {
|
||||
return errInfo
|
||||
info, err := aurInfo(cachedPackages, &aurWarnings{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range info {
|
||||
inAURBases.Add(info[i].PackageBase)
|
||||
for _, pkg := range info {
|
||||
inAURBases.set(pkg.PackageBase)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range remotePackages {
|
||||
if pkg.Base() != "" {
|
||||
installedBases.Add(pkg.Base())
|
||||
installedBases.set(pkg.Base())
|
||||
} else {
|
||||
installedBases.Add(pkg.Name())
|
||||
installedBases.set(pkg.Name())
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,29 +155,28 @@ func cleanAUR(ctx context.Context, run *runtime.Runtime,
|
||||
}
|
||||
|
||||
if !removeAll {
|
||||
if keepInstalled && installedBases.Contains(file.Name()) {
|
||||
if keepInstalled && installedBases.get(file.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if keepCurrent && inAURBases.Contains(file.Name()) {
|
||||
if keepCurrent && inAURBases.get(file.Name()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
dir := filepath.Join(run.Cfg.BuildDir, file.Name())
|
||||
run.Logger.Debugln("removing", dir)
|
||||
if err = os.RemoveAll(dir); err != nil {
|
||||
run.Logger.Warnln(gotext.Get("Unable to remove %s: %s", dir, err))
|
||||
err = os.RemoveAll(filepath.Join(config.BuildDir, file.Name()))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanUntracked(ctx context.Context, run *runtime.Runtime) error {
|
||||
run.Logger.Println(gotext.Get("removing untracked AUR files from cache..."))
|
||||
func cleanUntracked() error {
|
||||
fmt.Println("removing Untracked AUR files from cache...")
|
||||
|
||||
files, err := os.ReadDir(run.Cfg.BuildDir)
|
||||
files, err := ioutil.ReadDir(config.BuildDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -188,11 +186,10 @@ func cleanUntracked(ctx context.Context, run *runtime.Runtime) error {
|
||||
continue
|
||||
}
|
||||
|
||||
dir := filepath.Join(run.Cfg.BuildDir, file.Name())
|
||||
run.Logger.Debugln("cleaning", dir)
|
||||
if isGitRepository(dir) {
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildGitCmd(ctx, dir, "clean", "-fx")); err != nil {
|
||||
run.Logger.Warnln(gotext.Get("Unable to clean:"), dir)
|
||||
dir := filepath.Join(config.BuildDir, file.Name())
|
||||
|
||||
if shouldUseGit(dir) {
|
||||
if err = show(passToGit(dir, "clean", "-fx")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -200,8 +197,3 @@ func cleanUntracked(ctx context.Context, run *runtime.Runtime) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func isGitRepository(dir string) bool {
|
||||
_, err := os.Stat(filepath.Join(dir, ".git"))
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
116
clean_test.go
116
clean_test.go
@ -1,116 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
)
|
||||
|
||||
func TestCleanHanging(t *testing.T) {
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
wantShow []string
|
||||
}{
|
||||
{
|
||||
name: "clean",
|
||||
args: []string{"Y", "c"},
|
||||
wantShow: []string{"pacman", "-R", "-s", "-u", "--config", "/etc/pacman.conf", "--", "lsp-plugins"},
|
||||
},
|
||||
{
|
||||
name: "clean double",
|
||||
args: []string{"Y", "c", "c"},
|
||||
wantShow: []string{"pacman", "-R", "-s", "-u", "--config", "/etc/pacman.conf", "--", "lsp-plugins", "linux-headers"},
|
||||
},
|
||||
}
|
||||
|
||||
dbExc := &mock.DBExecutor{
|
||||
PackageOptionalDependsFn: func(i alpm.IPackage) []alpm.Depend {
|
||||
if i.Name() == "linux" {
|
||||
return []alpm.Depend{
|
||||
{
|
||||
Name: "linux-headers",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return []alpm.Depend{}
|
||||
},
|
||||
PackageProvidesFn: func(p alpm.IPackage) []alpm.Depend { return []alpm.Depend{} },
|
||||
PackageDependsFn: func(p alpm.IPackage) []alpm.Depend { return []alpm.Depend{} },
|
||||
LocalPackagesFn: func() []mock.IPackage {
|
||||
return []mock.IPackage{
|
||||
&mock.Package{
|
||||
PReason: alpm.PkgReasonExplicit,
|
||||
PName: "linux",
|
||||
},
|
||||
&mock.Package{
|
||||
PReason: alpm.PkgReasonDepend,
|
||||
PName: "lsp-plugins",
|
||||
},
|
||||
&mock.Package{
|
||||
PReason: alpm.PkgReasonDepend,
|
||||
PName: "linux-headers",
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
mockRunner := &exe.MockRunner{
|
||||
CaptureFn: func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return "", "", nil
|
||||
},
|
||||
ShowFn: func(cmd *exec.Cmd) error { return nil },
|
||||
}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
PacmanConfigPath: "/etc/pacman.conf",
|
||||
GitBin: "git",
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
run := &runtime.Runtime{CmdBuilder: cmdBuilder, Cfg: &settings.Configuration{}}
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddArg(tc.args...)
|
||||
|
||||
err := handleCmd(context.Background(),
|
||||
run, cmdArgs, dbExc,
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, call := range mockRunner.ShowCalls {
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
|
||||
// options are in a different order on different systems and on CI root user is used
|
||||
assert.Subset(t, strings.Split(show, " "),
|
||||
strings.Split(tc.wantShow[i], " "),
|
||||
fmt.Sprintf("%d - %s", i, show))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
589
cmd.go
589
cmd.go
@ -2,32 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"os"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/completion"
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/download"
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
"github.com/Jguer/yay/v12/pkg/news"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
"github.com/Jguer/yay/v12/pkg/upgrade"
|
||||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
func usage(logger *text.Logger) {
|
||||
logger.Println(`Usage:
|
||||
var cmdArgs = makeArguments()
|
||||
|
||||
func usage() {
|
||||
fmt.Println(`Usage:
|
||||
yay
|
||||
yay <operation> [...]
|
||||
yay <package(s)>
|
||||
@ -44,17 +28,12 @@ operations:
|
||||
yay {-U --upgrade} [options] <file(s)>
|
||||
|
||||
New operations:
|
||||
yay {-B --build} [options] [dir]
|
||||
yay {-G --getpkgbuild} [options] [package(s)]
|
||||
yay {-P --show} [options]
|
||||
yay {-W --web} [options] [package(s)]
|
||||
yay {-Y --yay} [options] [package(s)]
|
||||
|
||||
If no operation is specified 'yay -Syu' will be performed
|
||||
If no operation is specified and targets are provided -Y will be assumed
|
||||
yay {-P --show} [options]
|
||||
yay {-G --getpkgbuild} [package(s)]
|
||||
|
||||
New options:
|
||||
-N --repo Assume targets are from the repositories
|
||||
--repo Assume targets are from the repositories
|
||||
-a --aur Assume targets are from the AUR
|
||||
|
||||
Permanent configuration options:
|
||||
@ -62,13 +41,13 @@ Permanent configuration options:
|
||||
config file when used
|
||||
|
||||
--aururl <url> Set an alternative AUR URL
|
||||
--aurrpcurl <url> Set an alternative URL for the AUR /rpc endpoint
|
||||
--builddir <dir> Directory used to download and run PKGBUILDS
|
||||
--builddir <dir> Directory used to download and run PKBUILDS
|
||||
--editor <file> Editor to use when editing PKGBUILDs
|
||||
--editorflags <flags> Pass arguments to editor
|
||||
--makepkg <file> makepkg command to use
|
||||
--mflags <flags> Pass arguments to makepkg
|
||||
--pacman <file> pacman command to use
|
||||
--tar <file> bsdtar command to use
|
||||
--git <file> git command to use
|
||||
--gitflags <flags> Pass arguments to git
|
||||
--gpg <file> gpg command to use
|
||||
@ -78,9 +57,8 @@ Permanent configuration options:
|
||||
--nomakepkgconf Use the default makepkg.conf
|
||||
|
||||
--requestsplitn <n> Max amount of packages to query per AUR request
|
||||
--completioninterval <n> Time in days to refresh completion cache
|
||||
--completioninterval <n> Time in days to to refresh completion cache
|
||||
--sortby <field> Sort AUR results by a specific field during search
|
||||
--searchby <field> Search for packages using a specified field
|
||||
--answerclean <a> Set a predetermined answer for the clean build menu
|
||||
--answerdiff <a> Set a predetermined answer for the diff menu
|
||||
--answeredit <a> Set a predetermined answer for the edit pkgbuild menu
|
||||
@ -92,19 +70,24 @@ Permanent configuration options:
|
||||
--cleanmenu Give the option to clean build PKGBUILDS
|
||||
--diffmenu Give the option to show diffs for build files
|
||||
--editmenu Give the option to edit/view PKGBUILDS
|
||||
--upgrademenu Show a detailed list of updates with the option to skip any
|
||||
--nocleanmenu Don't clean build PKGBUILDS
|
||||
--nodiffmenu Don't show diffs for build files
|
||||
--noeditmenu Don't edit/view PKGBUILDS
|
||||
--noupgrademenu Don't show the upgrade menu
|
||||
--askremovemake Ask to remove makedepends after install
|
||||
--askyesremovemake Ask to remove makedepends after install("Y" as default)
|
||||
--removemake Remove makedepends after install
|
||||
--noremovemake Don't remove makedepends after install
|
||||
|
||||
--cleanafter Remove package sources after successful install
|
||||
--keepsrc Keep pkg/ and src/ after building packages
|
||||
--afterclean Remove package sources after successful install
|
||||
--noafterclean Do not remove package sources after successful build
|
||||
--bottomup Shows AUR's packages first and then repository's
|
||||
--topdown Shows repository's packages first and then AUR's
|
||||
--singlelineresults List each search result on its own line
|
||||
--doublelineresults List each search result on two lines, like pacman
|
||||
|
||||
--devel Check development packages during sysupgrade
|
||||
--nodevel Do not check development packages
|
||||
--gitclone Use git clone for PKGBUILD retrieval
|
||||
--nogitclone Never use git clone for PKGBUILD retrieval
|
||||
--rebuild Always build target packages
|
||||
--rebuildall Always build all AUR packages
|
||||
--norebuild Skip package build if in cache and up to date
|
||||
@ -112,15 +95,20 @@ Permanent configuration options:
|
||||
--redownload Always download pkgbuilds of targets
|
||||
--noredownload Skip pkgbuild download if in cache and up to date
|
||||
--redownloadall Always download pkgbuilds of all AUR packages
|
||||
--provides Look for matching providers when searching for packages
|
||||
--provides Look for matching provders when searching for packages
|
||||
--noprovides Just look for packages by pkgname
|
||||
--pgpfetch Prompt to import PGP keys from PKGBUILDs
|
||||
--nopgpfetch Don't prompt to import PGP keys
|
||||
--useask Automatically resolve conflicts using pacman's ask flag
|
||||
--nouseask Confirm conflicts manually during the install
|
||||
--combinedupgrade Refresh then perform the repo and AUR upgrade together
|
||||
--nocombinedupgrade Perform the repo upgrade and AUR upgrade separately
|
||||
|
||||
--sudo <file> sudo command to use
|
||||
--sudoflags <flags> Pass arguments to sudo
|
||||
--sudoloop Loop sudo calls in the background to avoid timeout
|
||||
--nosudoloop Do not loop sudo calls in the background
|
||||
|
||||
--timeupdate Check packages' AUR page for changes during sysupgrade
|
||||
--notimeupdate Do not check packages' AUR page for changes
|
||||
|
||||
show specific options:
|
||||
-c --complete Used for completions
|
||||
@ -130,338 +118,271 @@ show specific options:
|
||||
-w --news Print arch news
|
||||
|
||||
yay specific options:
|
||||
-c --clean Remove unneeded dependencies (-cc to ignore optdepends)
|
||||
-c --clean Remove unneeded dependencies
|
||||
--gendb Generates development package DB used for updating
|
||||
|
||||
getpkgbuild specific options:
|
||||
-f --force Force download for existing ABS packages
|
||||
-p --print Print pkgbuild of packages`)
|
||||
-f --force Force download for existing tar packages
|
||||
|
||||
If no arguments are provided 'yay -Syu' will be performed
|
||||
If no operation is provided -Y will be assumed`)
|
||||
}
|
||||
|
||||
func handleCmd(ctx context.Context, run *runtime.Runtime,
|
||||
cmdArgs *parser.Arguments, dbExecutor db.Executor,
|
||||
) error {
|
||||
if cmdArgs.ExistsArg("h", "help") {
|
||||
return handleHelp(ctx, run, cmdArgs)
|
||||
func handleCmd() (err error) {
|
||||
if cmdArgs.existsArg("h", "help") {
|
||||
err = handleHelp()
|
||||
return
|
||||
}
|
||||
|
||||
if run.Cfg.SudoLoop && cmdArgs.NeedRoot(run.Cfg.Mode) {
|
||||
run.CmdBuilder.SudoLoop()
|
||||
if config.SudoLoop && cmdArgs.needRoot() {
|
||||
sudoLoopBackground()
|
||||
}
|
||||
|
||||
switch cmdArgs.Op {
|
||||
switch cmdArgs.op {
|
||||
case "V", "version":
|
||||
handleVersion(run.Logger)
|
||||
return nil
|
||||
handleVersion()
|
||||
case "D", "database":
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
err = show(passToPacman(cmdArgs))
|
||||
case "F", "files":
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
err = show(passToPacman(cmdArgs))
|
||||
case "Q", "query":
|
||||
return handleQuery(ctx, run, cmdArgs, dbExecutor)
|
||||
err = handleQuery()
|
||||
case "R", "remove":
|
||||
return handleRemove(ctx, run, cmdArgs, run.VCSStore)
|
||||
err = handleRemove()
|
||||
case "S", "sync":
|
||||
return handleSync(ctx, run, cmdArgs, dbExecutor)
|
||||
err = handleSync()
|
||||
case "T", "deptest":
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
err = show(passToPacman(cmdArgs))
|
||||
case "U", "upgrade":
|
||||
return handleUpgrade(ctx, run, cmdArgs)
|
||||
case "B", "build":
|
||||
return handleBuild(ctx, run, dbExecutor, cmdArgs)
|
||||
err = show(passToPacman(cmdArgs))
|
||||
case "G", "getpkgbuild":
|
||||
return handleGetpkgbuild(ctx, run, cmdArgs, dbExecutor)
|
||||
err = handleGetpkgbuild()
|
||||
case "P", "show":
|
||||
return handlePrint(ctx, run, cmdArgs, dbExecutor)
|
||||
case "Y", "yay":
|
||||
return handleYay(ctx, run, cmdArgs, run.CmdBuilder,
|
||||
dbExecutor, run.QueryBuilder)
|
||||
case "W", "web":
|
||||
return handleWeb(ctx, run, cmdArgs)
|
||||
err = handlePrint()
|
||||
case "Y", "--yay":
|
||||
err = handleYay()
|
||||
default:
|
||||
//this means we allowed an op but not implement it
|
||||
//if this happens it an error in the code and not the usage
|
||||
err = fmt.Errorf("unhandled operation")
|
||||
}
|
||||
|
||||
return errors.New(gotext.Get("unhandled operation"))
|
||||
return
|
||||
}
|
||||
|
||||
// getFilter returns filter function which can keep packages which were only
|
||||
// explicitly installed or ones installed as dependencies for showing available
|
||||
// updates or their count.
|
||||
func getFilter(cmdArgs *parser.Arguments) (upgrade.Filter, error) {
|
||||
deps, explicit := cmdArgs.ExistsArg("d", "deps"), cmdArgs.ExistsArg("e", "explicit")
|
||||
|
||||
switch {
|
||||
case deps && explicit:
|
||||
return nil, errors.New(gotext.Get("invalid option: '--deps' and '--explicit' may not be used together"))
|
||||
case deps:
|
||||
return func(pkg *upgrade.Upgrade) bool {
|
||||
return pkg.Reason == alpm.PkgReasonDepend
|
||||
}, nil
|
||||
case explicit:
|
||||
return func(pkg *upgrade.Upgrade) bool {
|
||||
return pkg.Reason == alpm.PkgReasonExplicit
|
||||
}, nil
|
||||
func handleQuery() error {
|
||||
if cmdArgs.existsArg("u", "upgrades") {
|
||||
return printUpdateList(cmdArgs)
|
||||
}
|
||||
|
||||
return func(pkg *upgrade.Upgrade) bool {
|
||||
return true
|
||||
}, nil
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
|
||||
func handleQuery(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
if cmdArgs.ExistsArg("u", "upgrades") {
|
||||
filter, err := getFilter(cmdArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return printUpdateList(ctx, run, cmdArgs, dbExecutor,
|
||||
cmdArgs.ExistsDouble("u", "sysupgrade"), filter)
|
||||
}
|
||||
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm)); err != nil {
|
||||
if str := err.Error(); strings.Contains(str, "exit status") {
|
||||
// yay -Qdt should not output anything in case of error
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleHelp(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments) error {
|
||||
usage(run.Logger)
|
||||
switch cmdArgs.Op {
|
||||
case "Y", "yay", "G", "getpkgbuild", "P", "show", "W", "web", "B", "build":
|
||||
func handleHelp() error {
|
||||
if cmdArgs.op == "Y" || cmdArgs.op == "yay" {
|
||||
usage()
|
||||
return nil
|
||||
}
|
||||
|
||||
run.Logger.Println("\npacman operation specific options:")
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
|
||||
func handleVersion(logger *text.Logger) {
|
||||
logger.Printf("yay v%s - libalpm v%s\n", yayVersion, alpm.Version())
|
||||
func handleVersion() {
|
||||
fmt.Printf("yay v%s - libalpm v%s\n", version, alpm.Version())
|
||||
}
|
||||
|
||||
func handlePrint(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
func handlePrint() (err error) {
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("d", "defaultconfig"):
|
||||
tmpConfig := settings.DefaultConfig(yayVersion)
|
||||
run.Logger.Printf("%v", tmpConfig)
|
||||
|
||||
return nil
|
||||
case cmdArgs.ExistsArg("g", "currentconfig"):
|
||||
run.Logger.Printf("%v", run.Cfg)
|
||||
|
||||
return nil
|
||||
case cmdArgs.ExistsArg("w", "news"):
|
||||
double := cmdArgs.ExistsDouble("w", "news")
|
||||
quiet := cmdArgs.ExistsArg("q", "quiet")
|
||||
|
||||
return news.PrintNewsFeed(ctx, run.HTTPClient, run.Logger,
|
||||
dbExecutor.LastBuildTime(), run.Cfg.BottomUp, double, quiet)
|
||||
case cmdArgs.ExistsArg("c", "complete"):
|
||||
return completion.Show(ctx, run.HTTPClient, dbExecutor,
|
||||
run.Cfg.AURURL, run.Cfg.CompletionPath, run.Cfg.CompletionInterval, cmdArgs.ExistsDouble("c", "complete"))
|
||||
case cmdArgs.ExistsArg("s", "stats"):
|
||||
return localStatistics(ctx, run, dbExecutor)
|
||||
case cmdArgs.existsArg("d", "defaultconfig"):
|
||||
var tmpConfig Configuration
|
||||
tmpConfig.defaultSettings()
|
||||
tmpConfig.expandEnv()
|
||||
fmt.Printf("%v", tmpConfig)
|
||||
case cmdArgs.existsArg("g", "currentconfig"):
|
||||
fmt.Printf("%v", config)
|
||||
case cmdArgs.existsArg("n", "numberupgrades"):
|
||||
err = printNumberOfUpdates()
|
||||
case cmdArgs.existsArg("u", "upgrades"):
|
||||
err = printUpdateList(cmdArgs)
|
||||
case cmdArgs.existsArg("w", "news"):
|
||||
err = printNewsFeed()
|
||||
case cmdArgs.existsDouble("c", "complete"):
|
||||
complete(true)
|
||||
case cmdArgs.existsArg("c", "complete"):
|
||||
complete(false)
|
||||
case cmdArgs.existsArg("s", "stats"):
|
||||
err = localStatistics()
|
||||
default:
|
||||
err = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleYay(ctx context.Context, run *runtime.Runtime,
|
||||
cmdArgs *parser.Arguments, cmdBuilder exe.ICmdBuilder,
|
||||
dbExecutor db.Executor, queryBuilder query.Builder,
|
||||
) error {
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("gendb"):
|
||||
return createDevelDB(ctx, run, dbExecutor)
|
||||
case cmdArgs.ExistsDouble("c"):
|
||||
return cleanDependencies(ctx, run.Cfg, cmdBuilder, cmdArgs, dbExecutor, true)
|
||||
case cmdArgs.ExistsArg("c", "clean"):
|
||||
return cleanDependencies(ctx, run.Cfg, cmdBuilder, cmdArgs, dbExecutor, false)
|
||||
case len(cmdArgs.Targets) > 0:
|
||||
return displayNumberMenu(ctx, run, cmdArgs.Targets, dbExecutor, queryBuilder, cmdArgs)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleWeb(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments) error {
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("v", "vote"):
|
||||
return handlePackageVote(ctx, cmdArgs.Targets, run.AURClient, run.Logger,
|
||||
run.VoteClient, true)
|
||||
case cmdArgs.ExistsArg("u", "unvote"):
|
||||
return handlePackageVote(ctx, cmdArgs.Targets, run.AURClient, run.Logger,
|
||||
run.VoteClient, false)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleGetpkgbuild(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor download.DBSearcher) error {
|
||||
if cmdArgs.ExistsArg("p", "print") {
|
||||
return printPkgbuilds(dbExecutor, run.AURClient,
|
||||
run.HTTPClient, run.Logger, cmdArgs.Targets, run.Cfg.Mode, run.Cfg.AURURL)
|
||||
}
|
||||
|
||||
return getPkgbuilds(ctx, dbExecutor, run.AURClient, run,
|
||||
cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
|
||||
}
|
||||
|
||||
func handleUpgrade(ctx context.Context,
|
||||
run *runtime.Runtime, cmdArgs *parser.Arguments,
|
||||
) error {
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
// -B* options
|
||||
func handleBuild(ctx context.Context,
|
||||
run *runtime.Runtime, dbExecutor db.Executor, cmdArgs *parser.Arguments,
|
||||
) error {
|
||||
if cmdArgs.ExistsArg("i", "install") {
|
||||
return installLocalPKGBUILD(ctx, run, cmdArgs, dbExecutor)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSync(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
targets := cmdArgs.Targets
|
||||
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("s", "search"):
|
||||
return syncSearch(ctx, targets, dbExecutor, run.QueryBuilder, !cmdArgs.ExistsArg("q", "quiet"))
|
||||
case cmdArgs.ExistsArg("p", "print", "print-format"):
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case cmdArgs.ExistsArg("c", "clean"):
|
||||
return syncClean(ctx, run, cmdArgs, dbExecutor)
|
||||
case cmdArgs.ExistsArg("l", "list"):
|
||||
return syncList(ctx, run, run.HTTPClient, cmdArgs, dbExecutor)
|
||||
case cmdArgs.ExistsArg("g", "groups"):
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case cmdArgs.ExistsArg("i", "info"):
|
||||
return syncInfo(ctx, run, cmdArgs, targets, dbExecutor)
|
||||
case cmdArgs.ExistsArg("u", "sysupgrade") || len(cmdArgs.Targets) > 0:
|
||||
return syncInstall(ctx, run, cmdArgs, dbExecutor)
|
||||
case cmdArgs.ExistsArg("y", "refresh"):
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRemove(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, localCache vcs.Store) error {
|
||||
err := run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
if err == nil {
|
||||
localCache.RemovePackages(cmdArgs.Targets)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NumberMenu presents a CLI for selecting packages to install.
|
||||
func displayNumberMenu(ctx context.Context, run *runtime.Runtime, pkgS []string, dbExecutor db.Executor,
|
||||
queryBuilder query.Builder, cmdArgs *parser.Arguments,
|
||||
) error {
|
||||
queryBuilder.Execute(ctx, dbExecutor, pkgS)
|
||||
|
||||
if err := queryBuilder.Results(dbExecutor, query.NumberMenu); err != nil {
|
||||
return err
|
||||
func handleYay() error {
|
||||
//_, options, targets := cmdArgs.formatArgs()
|
||||
if cmdArgs.existsArg("gendb") {
|
||||
return createDevelDB()
|
||||
}
|
||||
|
||||
if queryBuilder.Len() == 0 {
|
||||
// no results were found
|
||||
return nil
|
||||
if cmdArgs.existsDouble("c") {
|
||||
return cleanDependencies(true)
|
||||
}
|
||||
|
||||
run.Logger.Infoln(gotext.Get("Packages to install (eg: 1 2 3, 1-3 or ^4)"))
|
||||
|
||||
numberBuf, err := run.Logger.GetInput("", false)
|
||||
if err != nil {
|
||||
return err
|
||||
if cmdArgs.existsArg("c", "clean") {
|
||||
return cleanDependencies(false)
|
||||
}
|
||||
|
||||
include, exclude, _, otherExclude := intrange.ParseNumberMenu(numberBuf)
|
||||
|
||||
targets, err := queryBuilder.GetTargets(include, exclude, otherExclude)
|
||||
if err != nil {
|
||||
return err
|
||||
if len(cmdArgs.targets) > 0 {
|
||||
return handleYogurt()
|
||||
}
|
||||
|
||||
// modify the arguments to pass for the install
|
||||
cmdArgs.Targets = targets
|
||||
|
||||
if len(cmdArgs.Targets) == 0 {
|
||||
run.Logger.Println(gotext.Get(" there is nothing to do"))
|
||||
return nil
|
||||
}
|
||||
|
||||
return syncInstall(ctx, run, cmdArgs, dbExecutor)
|
||||
}
|
||||
|
||||
func syncList(ctx context.Context, run *runtime.Runtime,
|
||||
httpClient *http.Client, cmdArgs *parser.Arguments, dbExecutor db.Executor,
|
||||
) error {
|
||||
aur := false
|
||||
|
||||
for i := len(cmdArgs.Targets) - 1; i >= 0; i-- {
|
||||
if cmdArgs.Targets[i] == "aur" && run.Cfg.Mode.AtLeastAUR() {
|
||||
cmdArgs.Targets = append(cmdArgs.Targets[:i], cmdArgs.Targets[i+1:]...)
|
||||
aur = true
|
||||
}
|
||||
}
|
||||
|
||||
if run.Cfg.Mode.AtLeastAUR() && (len(cmdArgs.Targets) == 0 || aur) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, run.Cfg.AURURL+"/packages.gz", http.NoBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
|
||||
scanner.Scan()
|
||||
|
||||
for scanner.Scan() {
|
||||
name := scanner.Text()
|
||||
if cmdArgs.ExistsArg("q", "quiet") {
|
||||
run.Logger.Println(name)
|
||||
} else {
|
||||
run.Logger.Printf("%s %s %s", text.Magenta("aur"), text.Bold(name), text.Bold(text.Green(gotext.Get("unknown-version"))))
|
||||
|
||||
if dbExecutor.LocalPackage(name) != nil {
|
||||
run.Logger.Print(text.Bold(text.Blue(gotext.Get(" [Installed]"))))
|
||||
}
|
||||
|
||||
run.Logger.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if run.Cfg.Mode.AtLeastRepo() && (len(cmdArgs.Targets) != 0 || !aur) {
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleGetpkgbuild() error {
|
||||
return getPkgbuilds(cmdArgs.targets)
|
||||
}
|
||||
|
||||
func handleYogurt() error {
|
||||
config.SearchMode = NumberMenu
|
||||
return numberMenu(cmdArgs.targets)
|
||||
}
|
||||
|
||||
func handleSync() error {
|
||||
targets := cmdArgs.targets
|
||||
|
||||
if cmdArgs.existsArg("s", "search") {
|
||||
if cmdArgs.existsArg("q", "quiet") {
|
||||
config.SearchMode = Minimal
|
||||
} else {
|
||||
config.SearchMode = Detailed
|
||||
}
|
||||
return syncSearch(targets)
|
||||
}
|
||||
if cmdArgs.existsArg("p", "print", "print-format") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
if cmdArgs.existsArg("c", "clean") {
|
||||
return syncClean(cmdArgs)
|
||||
}
|
||||
if cmdArgs.existsArg("l", "list") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
if cmdArgs.existsArg("g", "groups") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
if cmdArgs.existsArg("i", "info") {
|
||||
return syncInfo(targets)
|
||||
}
|
||||
if cmdArgs.existsArg("u", "sysupgrade") {
|
||||
return install(cmdArgs)
|
||||
}
|
||||
if len(cmdArgs.targets) > 0 {
|
||||
return install(cmdArgs)
|
||||
}
|
||||
if cmdArgs.existsArg("y", "refresh") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRemove() error {
|
||||
removeVCSPackage(cmdArgs.targets)
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
|
||||
// NumberMenu presents a CLI for selecting packages to install.
|
||||
func numberMenu(pkgS []string) (err error) {
|
||||
var (
|
||||
aurErr, repoErr error
|
||||
aq aurQuery
|
||||
pq repoQuery
|
||||
lenaq, lenpq int
|
||||
)
|
||||
|
||||
pkgS = removeInvalidTargets(pkgS)
|
||||
|
||||
if mode == ModeAUR || mode == ModeAny {
|
||||
aq, aurErr = narrowSearch(pkgS, true)
|
||||
lenaq = len(aq)
|
||||
}
|
||||
if mode == ModeRepo || mode == ModeAny {
|
||||
pq, repoErr = queryRepo(pkgS)
|
||||
lenpq = len(pq)
|
||||
if repoErr != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if lenpq == 0 && lenaq == 0 {
|
||||
return fmt.Errorf("No packages match search")
|
||||
}
|
||||
|
||||
if config.SortMode == BottomUp {
|
||||
if mode == ModeAUR || mode == ModeAny {
|
||||
aq.printSearch(lenpq + 1)
|
||||
}
|
||||
if mode == ModeRepo || mode == ModeAny {
|
||||
pq.printSearch()
|
||||
}
|
||||
} else {
|
||||
if mode == ModeRepo || mode == ModeAny {
|
||||
pq.printSearch()
|
||||
}
|
||||
if mode == ModeAUR || mode == ModeAny {
|
||||
aq.printSearch(lenpq + 1)
|
||||
}
|
||||
}
|
||||
|
||||
if aurErr != nil {
|
||||
fmt.Printf("Error during AUR search: %s\n", aurErr)
|
||||
fmt.Println("Showing repo packages only")
|
||||
}
|
||||
|
||||
fmt.Println(bold(green(arrow + " Packages to install (eg: 1 2 3, 1-3 or ^4)")))
|
||||
fmt.Print(bold(green(arrow + " ")))
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
numberBuf, overflow, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if overflow {
|
||||
return fmt.Errorf("Input too long")
|
||||
}
|
||||
|
||||
include, exclude, _, otherExclude := parseNumberMenu(string(numberBuf))
|
||||
arguments := makeArguments()
|
||||
|
||||
isInclude := len(exclude) == 0 && len(otherExclude) == 0
|
||||
|
||||
for i, pkg := range pq {
|
||||
target := len(pq) - i
|
||||
if config.SortMode == TopDown {
|
||||
target = i + 1
|
||||
}
|
||||
|
||||
if (isInclude && include.get(target)) || (!isInclude && !exclude.get(target)) {
|
||||
arguments.addTarget(pkg.DB().Name() + "/" + pkg.Name())
|
||||
}
|
||||
}
|
||||
|
||||
for i, pkg := range aq {
|
||||
target := len(aq) - i + len(pq)
|
||||
if config.SortMode == TopDown {
|
||||
target = i + 1 + len(pq)
|
||||
}
|
||||
|
||||
if (isInclude && include.get(target)) || (!isInclude && !exclude.get(target)) {
|
||||
arguments.addTarget("aur/" + pkg.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if len(arguments.targets) == 0 {
|
||||
fmt.Println("There is nothing to do")
|
||||
return nil
|
||||
}
|
||||
|
||||
if config.SudoLoop {
|
||||
sudoLoopBackground()
|
||||
}
|
||||
|
||||
err = install(arguments)
|
||||
|
||||
return err
|
||||
}
|
||||
|
140
cmd_test.go
140
cmd_test.go
@ -1,140 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
)
|
||||
|
||||
func TestYogurtMenuAURDB(t *testing.T) {
|
||||
t.Skip("skip until Operation service is an interface")
|
||||
t.Parallel()
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
gitBin := t.TempDir() + "/git"
|
||||
f, err := os.OpenFile(makepkgBin, os.O_RDONLY|os.O_CREATE, 0o755)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
f, err = os.OpenFile(pacmanBin, os.O_RDONLY|os.O_CREATE, 0o755)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
f, err = os.OpenFile(gitBin, os.O_RDONLY|os.O_CREATE, 0o755)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return "", "", nil
|
||||
}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
MakepkgBin: makepkgBin,
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
PacmanConfigPath: "/etc/pacman.conf",
|
||||
GitBin: "git",
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddArg("Y")
|
||||
cmdArgs.AddTarget("yay")
|
||||
|
||||
db := &mock.DBExecutor{
|
||||
AlpmArchitecturesFn: func() ([]string, error) {
|
||||
return []string{"x86_64"}, nil
|
||||
},
|
||||
RefreshHandleFn: func() error {
|
||||
return nil
|
||||
},
|
||||
ReposFn: func() []string {
|
||||
return []string{"aur"}
|
||||
},
|
||||
SyncPackagesFn: func(s ...string) []mock.IPackage {
|
||||
return []mock.IPackage{
|
||||
&mock.Package{
|
||||
PName: "yay",
|
||||
PBase: "yay",
|
||||
PVersion: "10.0.0",
|
||||
PDB: mock.NewDB("aur"),
|
||||
},
|
||||
}
|
||||
},
|
||||
LocalPackageFn: func(s string) mock.IPackage {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
aurCache := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{
|
||||
{
|
||||
Name: "yay",
|
||||
PackageBase: "yay",
|
||||
Version: "10.0.0",
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
logger := text.NewLogger(io.Discard, os.Stderr, strings.NewReader("1\n"), true, "test")
|
||||
|
||||
run := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
},
|
||||
Logger: logger,
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
QueryBuilder: query.NewSourceQueryBuilder(aurCache, logger, "votes", parser.ModeAny, "name",
|
||||
true, false, true),
|
||||
AURClient: aurCache,
|
||||
}
|
||||
err = handleCmd(context.Background(), run, cmdArgs, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
wantCapture := []string{}
|
||||
wantShow := []string{
|
||||
"pacman -S -y --config /etc/pacman.conf --",
|
||||
"pacman -S -y -u --config /etc/pacman.conf --",
|
||||
}
|
||||
|
||||
require.Len(t, mockRunner.ShowCalls, len(wantShow))
|
||||
require.Len(t, mockRunner.CaptureCalls, len(wantCapture))
|
||||
|
||||
for i, call := range mockRunner.ShowCalls {
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, makepkgBin, "makepkg")
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
show = strings.ReplaceAll(show, gitBin, "pacman")
|
||||
|
||||
// options are in a different order on different systems and on CI root user is used
|
||||
assert.Subset(t, strings.Split(show, " "), strings.Split(wantShow[i], " "), fmt.Sprintf("%d - %s", i, show))
|
||||
}
|
||||
}
|
91
completions.go
Normal file
91
completions.go
Normal file
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
//CreateAURList creates a new completion file
|
||||
func createAURList(out *os.File) (err error) {
|
||||
resp, err := http.Get(config.AURURL + "/packages.gz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
|
||||
scanner.Scan()
|
||||
for scanner.Scan() {
|
||||
out.WriteString(scanner.Text())
|
||||
out.WriteString("\tAUR\n")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//CreatePackageList appends Repo packages to completion cache
|
||||
func createRepoList(out *os.File) (err error) {
|
||||
dbList, err := alpmHandle.SyncDbs()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_ = dbList.ForEach(func(db alpm.Db) error {
|
||||
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||
out.WriteString(pkg.Name())
|
||||
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateCompletion(force bool) error {
|
||||
path := filepath.Join(cacheHome, "completion.cache")
|
||||
info, err := os.Stat(path)
|
||||
|
||||
if os.IsNotExist(err) || (config.CompletionInterval != -1 && time.Since(info.ModTime()).Hours() >= float64(config.CompletionInterval*24)) || force {
|
||||
os.MkdirAll(filepath.Dir(path), 0755)
|
||||
out, errf := os.Create(path)
|
||||
if errf != nil {
|
||||
return errf
|
||||
}
|
||||
|
||||
if createAURList(out) != nil {
|
||||
defer os.Remove(path)
|
||||
}
|
||||
erra := createRepoList(out)
|
||||
|
||||
out.Close()
|
||||
return erra
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Complete provides completion info for shells
|
||||
func complete(force bool) error {
|
||||
path := filepath.Join(cacheHome, "completion.cache")
|
||||
|
||||
err := updateCompletion(force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
_, err = io.Copy(os.Stdout, in)
|
||||
return err
|
||||
}
|
109
completions/bash
109
completions/bash
@ -3,11 +3,10 @@
|
||||
_arch_compgen() {
|
||||
local i r
|
||||
COMPREPLY=($(compgen -W '$*' -- "$cur"))
|
||||
for ((i = 1; i < ${#COMP_WORDS[@]} - 1; i++)); do
|
||||
for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do
|
||||
for r in ${!COMPREPLY[@]}; do
|
||||
if [[ ${COMP_WORDS[i]} == ${COMPREPLY[r]} ]]; then
|
||||
unset 'COMPREPLY[r]'
|
||||
break
|
||||
if [[ ${COMP_WORDS[i]} = ${COMPREPLY[r]} ]]; then
|
||||
unset 'COMPREPLY[r]'; break
|
||||
fi
|
||||
done
|
||||
done
|
||||
@ -25,8 +24,7 @@ _arch_ptr2comp() {
|
||||
}
|
||||
|
||||
_arch_incomp() {
|
||||
local r="[[:space:]]-(-${1#* }[[:space:]]|[[:alnum:]_]*${1% *})"
|
||||
[[ $COMP_LINE =~ $r ]]
|
||||
local r="\s-(-${1#* }\s|\w*${1% *})"; [[ $COMP_LINE =~ $r ]]
|
||||
}
|
||||
|
||||
_pacman_pkg() {
|
||||
@ -40,7 +38,7 @@ _pacman_pkg() {
|
||||
}
|
||||
|
||||
_yay_pkg() {
|
||||
[ -z "$cur" ] && _pacman_pkg Slq && return
|
||||
[ -z "$cur" ] && return
|
||||
_arch_compgen "$(yay -Pc)"
|
||||
}
|
||||
|
||||
@ -49,90 +47,73 @@ _pacman_repo_list() {
|
||||
}
|
||||
|
||||
_yay() {
|
||||
compopt -o default
|
||||
local common core cur database files prev query remove sync upgrade o
|
||||
local yays show getpkgbuild web
|
||||
local cur prev words cword
|
||||
|
||||
_init_completion || return
|
||||
local yays show getpkgbuild
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref cur prev
|
||||
database=('asdeps asexplicit')
|
||||
files=('list machinereadable refresh regex' 'l x y')
|
||||
files=('list machinereadable owns search refresh regex' 'l o s x y')
|
||||
query=('changelog check deps explicit file foreign groups info list native owns
|
||||
search unrequired upgrades' 'c e g i k l m n o p s t u')
|
||||
remove=('cascade dbonly nodeps assume-installed nosave print recursive unneeded' 'c n p s u')
|
||||
sync=('asdeps asexplicit clean dbonly downloadonly overwrite groups ignore ignoregroup
|
||||
info list needed nodeps assume-installed print refresh recursive search sysupgrade aur repo'
|
||||
'c g i l p s u w y a N')
|
||||
upgrade=('asdeps asexplicit overwrite needed nodeps assume-installed print recursive' 'p')
|
||||
sync=('asdeps asexplicit clean dbonly downloadonly force groups ignore ignoregroup
|
||||
info list needed nodeps assume-installed print refresh recursive search sysupgrade'
|
||||
'c g i l p s u w y')
|
||||
upgrade=('asdeps asexplicit force needed nodeps assume-installed print recursive' 'p')
|
||||
common=('arch cachedir color config confirm dbpath debug gpgdir help hookdir logfile
|
||||
noconfirm noprogressbar noscriptlet quiet root verbose
|
||||
#yay stuff
|
||||
makepkg pacman tar git gpg gpgflags config requestsplitn sudoloop nosudoloop
|
||||
redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild
|
||||
sortby answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff
|
||||
noansweredit noanswerupgrade cleanmenu diffmenu editmenu upgrademenu
|
||||
nocleanmenu nodiffmenu noupgrademenu provides noprovides pgpfetch nopgpfetch
|
||||
useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf
|
||||
nomakepkgconf askremovemake removemake noremovemake completioninterval aururl'
|
||||
'b d h q r v')
|
||||
core=('database files help query remove sync upgrade version' 'D F Q R S U V h')
|
||||
|
||||
##yay stuff
|
||||
common=('arch cachedir color config confirm dbpath debug gpgdir help hookdir logfile
|
||||
noconfirm noprogressbar noscriptlet quiet root verbose
|
||||
makepkg pacman git gpg gpgflags config requestsplitn sudoloop
|
||||
redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild sortby
|
||||
singlelineresults doublelineresults answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff
|
||||
noansweredit noanswerupgrade cleanmenu diffmenu editmenu cleanafter keepsrc
|
||||
provides pgpfetch
|
||||
useask combinedupgrade aur repo makepkgconf
|
||||
nomakepkgconf askremovemake askyesremovemake removemake noremovemake completioninterval aururl aurrpcurl
|
||||
searchby batchinstall'
|
||||
'b d h q r v')
|
||||
yays=('clean gendb' 'c')
|
||||
show=('complete defaultconfig currentconfig stats news' 'c d g s w')
|
||||
getpkgbuild=('force print' 'f p')
|
||||
web=('vote unvote' 'v u')
|
||||
show=('complete defaultconfig currentconfig stats news' 'c d g s w')
|
||||
getpkgbuild=('force' 'f')
|
||||
|
||||
for o in 'D database' 'F files' 'Q query' 'R remove' 'S sync' 'U upgrade' 'Y yays' 'P show' 'G getpkgbuild' 'W web'; do
|
||||
for o in 'D database' 'F files' 'Q query' 'R remove' 'S sync' 'U upgrade' 'Y yays' 'P show' 'G getpkgbuild'; do
|
||||
_arch_incomp "$o" && break
|
||||
done
|
||||
|
||||
if [[ $? != 0 ]]; then
|
||||
_arch_ptr2comp core
|
||||
elif [[ ! $prev =~ ^-[[:alnum:]_]*[Vbhr] && ! $prev == --@(cachedir|color|config|dbpath|help|hookdir|gpgdir|logfile|root|version) ]]; then
|
||||
[[ $cur == -* ]] && _arch_ptr2comp ${o#* } common ||
|
||||
elif [[ ! $prev =~ ^-\w*[Vbhr] &&
|
||||
! $prev = --@(cachedir|color|config|dbpath|help|hookdir|gpgdir|logfile|root|version) ]]
|
||||
then
|
||||
[[ $cur = -* ]] && _arch_ptr2comp ${o#* } common ||
|
||||
case ${o% *} in
|
||||
D | R)
|
||||
_pacman_pkg Qq
|
||||
;;
|
||||
D|R)
|
||||
_pacman_pkg Qq;;
|
||||
F)
|
||||
{ _arch_incomp 'l list' && _pacman_pkg Slq; } ||
|
||||
_arch_incomp 'o owns' ||
|
||||
compopt +o default
|
||||
;;
|
||||
_arch_incomp 'l list' && _pacman_pkg Slq;
|
||||
;;
|
||||
Q)
|
||||
{ _arch_incomp 'g groups' && _pacman_pkg Qg sort; } ||
|
||||
{ _arch_incomp 'p file' && _pacman_file; } ||
|
||||
{ _arch_incomp 's search' && compopt +o default; } ||
|
||||
{ _arch_incomp 'u upgrades' && compopt +o default; } ||
|
||||
_arch_incomp 'o owns' ||
|
||||
_pacman_pkg Qq
|
||||
;;
|
||||
{ _arch_incomp 'g groups' && _pacman_pkg Qg sort; } ||
|
||||
{ _arch_incomp 'p file' && _pacman_file; } ||
|
||||
_arch_incomp 'o owns' || _arch_incomp 'u upgrades' ||
|
||||
_pacman_pkg Qq;;
|
||||
S)
|
||||
{ _arch_incomp 'g groups' && _pacman_pkg Sg; } ||
|
||||
{ _arch_incomp 'l list' && _pacman_repo_list; } ||
|
||||
{ _arch_incomp 's search' && compopt +o default; } ||
|
||||
_yay_pkg
|
||||
;;
|
||||
{ _arch_incomp 'g groups' && _pacman_pkg Sg; } ||
|
||||
{ _arch_incomp 'l list' && _pacman_repo_list; } ||
|
||||
_yay_pkg;;
|
||||
U)
|
||||
_pacman_file
|
||||
;;
|
||||
G)
|
||||
_yay_pkg
|
||||
;;
|
||||
W)
|
||||
_yay_pkg
|
||||
;;
|
||||
_pacman_file;;
|
||||
esac
|
||||
fi
|
||||
true
|
||||
}
|
||||
|
||||
_pacman_file() {
|
||||
compopt -o filenames
|
||||
_filedir 'pkg.*'
|
||||
compopt -o filenames; _filedir 'pkg.tar*'
|
||||
}
|
||||
|
||||
complete -F _yay yay
|
||||
complete -F _yay -o default yay
|
||||
|
||||
# ex:et ts=2 sw=2 ft=sh
|
||||
|
399
completions/fish
399
completions/fish
@ -3,194 +3,77 @@
|
||||
# Updated for yay by jguer
|
||||
|
||||
set -l progname yay
|
||||
complete -e -c $progname
|
||||
complete -c $progname -f
|
||||
|
||||
# Yay constants
|
||||
set -l listall "(yay -Pc)"
|
||||
set -l listpacman "(__fish_print_packages)"
|
||||
set -l yayspecific '__fish_contains_opt -s Y yay'
|
||||
set -l webspecific '__fish_contains_opt -s W web'
|
||||
set -l show '__fish_contains_opt -s P show'
|
||||
set -l getpkgbuild '__fish_contains_opt -s G getpkgbuild'
|
||||
|
||||
# Pacman constants
|
||||
set -l listinstalled "(pacman -Q | string replace ' ' \t)"
|
||||
# This might be an issue if another package manager is also installed (e.g. for containers)
|
||||
set -l listall "(yay -Pc)"
|
||||
set -l listrepos "(__fish_print_pacman_repos)"
|
||||
set -l listgroups "(pacman -Sg)\t'Package Group'"
|
||||
|
||||
set -l noopt 'not __fish_contains_opt -s S -s D -s Q -s R -s U -s T -s F -s Y -s W -s P -s G database query sync remove upgrade deptest files show getpkgbuild web yay'
|
||||
set -l listpacman "(__fish_print_packages)"
|
||||
set -l noopt 'not __fish_contains_opt -s Y -s G -s V -s P -s S -s D -s Q -s R -s U -s T -s F database query sync remove upgrade deptest files'
|
||||
set -l database '__fish_contains_opt -s D database'
|
||||
set -l getpkgbuild '__fish_contains_opt -s G getpkgbuild'
|
||||
set -l show '__fish_contains_opt -s P show'
|
||||
set -l query '__fish_contains_opt -s Q query'
|
||||
set -l remove '__fish_contains_opt -s R remove'
|
||||
set -l sync '__fish_contains_opt -s S sync'
|
||||
set -l upgrade '__fish_contains_opt -s U upgrade'
|
||||
set -l files '__fish_contains_opt -s F files'
|
||||
set -l yayspecific '__fish_contains_opt -s Y yay'
|
||||
|
||||
|
||||
|
||||
complete -c $progname -e
|
||||
complete -c $progname -f
|
||||
# HACK: We only need these two to coerce fish to stop file completion and complete options
|
||||
complete -c $progname -n "$noopt" -a "-D" -d "Modify the package database"
|
||||
complete -c $progname -n "$noopt" -a "-Q" -d "Query the package database"
|
||||
# complete -c $progname -n $noopt -a "-D" -d "Modify the package database"
|
||||
# complete -c $progname -n $noopt -a "-Q" -d "Query the package database"
|
||||
|
||||
# Primary operations
|
||||
complete -c $progname -s D -f -l database -n "$noopt" -d 'Modify the package database'
|
||||
complete -c $progname -s Q -f -l query -n "$noopt" -d 'Query the package database'
|
||||
complete -c $progname -s R -f -l remove -n "$noopt" -d 'Remove packages from the system'
|
||||
complete -c $progname -s S -f -l sync -n "$noopt" -d 'Synchronize packages'
|
||||
complete -c $progname -s T -f -l deptest -n "$noopt" -d 'Check dependencies'
|
||||
complete -c $progname -s U -l upgrade -n "$noopt" -d 'Upgrade or add a local package'
|
||||
complete -c $progname -s F -f -l files -n "$noopt" -d 'Query the files database'
|
||||
complete -c $progname -s V -f -l version -d 'Display version and exit'
|
||||
complete -c $progname -s h -f -l help -d 'Display help'
|
||||
complete -c $progname -s D -f -l database -n $noopt -d 'Modify the package database'
|
||||
complete -c $progname -s F -f -l files -n $noopt -d 'Query the files database'
|
||||
complete -c $progname -s G -f -l getpkgbuild -n $noopt -d 'Get PKGBUILD from ABS or AUR'
|
||||
complete -c $progname -s P -f -l show -n $noopt -d 'Print information'
|
||||
complete -c $progname -s Q -f -l query -n $noopt -d 'Query the package database'
|
||||
complete -c $progname -s R -f -l remove -n $noopt -d 'Remove packages from the system'
|
||||
complete -c $progname -s S -f -l sync -n $noopt -d 'Synchronize packages'
|
||||
complete -c $progname -s T -f -l deptest -n $noopt -d 'Check if dependencies are installed'
|
||||
complete -c $progname -s U -f -l upgrade -n $noopt -d 'Upgrade or add a local package'
|
||||
complete -c $progname -s Y -f -l yay -n $noopt -d 'Yay specific operations'
|
||||
complete -c $progname -s V -f -l version -n $noopt -d 'Display version and exit'
|
||||
complete -c $progname -s h -f -l help -n $noopt -d 'Display help'
|
||||
|
||||
# General options
|
||||
# Only offer these once a command has been given so they get prominent display
|
||||
complete -c $progname -n "not $noopt" -s b -l dbpath -d 'Alternate database location' -xa "(__fish_complete_directories)"
|
||||
complete -c $progname -n "not $noopt" -s r -l root -d 'Alternate installation root' -xa "(__fish_complete_directories)"
|
||||
complete -c $progname -n "not $noopt" -s v -l verbose -d 'Output more status messages' -f
|
||||
complete -c $progname -n "not $noopt" -s a -l aur -d 'Assume targets are from the repositories'
|
||||
complete -c $progname -n "not $noopt" -l repo -d 'Assume targets are from the AUR'
|
||||
|
||||
complete -c $progname -n "not $noopt" -s b -l aururl -d 'Set an alternative AUR URL' -f
|
||||
complete -c $progname -n "not $noopt" -s b -l dbpath -d 'Alternative database location' -xa '(__fish_complete_directories)'
|
||||
complete -c $progname -n "not $noopt" -s r -l root -d 'Alternative installation root'
|
||||
complete -c $progname -n "not $noopt" -s v -l verbose -d 'Output more status messages'
|
||||
complete -c $progname -n "not $noopt" -s h -l help -d 'Display syntax for the given operation'
|
||||
complete -c $progname -n "not $noopt" -l arch -d 'Alternate architecture' -f
|
||||
complete -c $progname -n "not $noopt" -l cachedir -d 'Alternate package cache location' -xa "(__fish_complete_directories)"
|
||||
complete -c $progname -n "not $noopt" -l color -d 'Colorize the output' -fa '{auto,always,never}'
|
||||
complete -c $progname -n "not $noopt" -l config -d 'Alternate config file' -rF
|
||||
complete -c $progname -n "not $noopt" -l confirm -d 'Always ask for confirmation' -f
|
||||
complete -c $progname -n "not $noopt" -l cachedir -d 'Alternative package cache location'
|
||||
complete -c $progname -n "not $noopt" -l color -d 'Colorize the output'
|
||||
complete -c $progname -n "not $noopt" -l config -d 'Alternate config file'
|
||||
complete -c $progname -n "not $noopt" -l debug -d 'Display debug messages' -f
|
||||
complete -c $progname -n "not $noopt" -l disable-download-timeout -d 'Use relaxed timeouts for download' -f
|
||||
complete -c $progname -n "not $noopt" -l gpgdir -d 'Alternate home directory for GnuPG' -xa "(__fish_complete_directories)"
|
||||
complete -c $progname -n "not $noopt" -l hookdir -d 'Alternate hook location' -xa "(__fish_complete_directories)"
|
||||
complete -c $progname -n "not $noopt" -l logfile -d 'Alternate log file'
|
||||
complete -c $progname -n "not $noopt" -l noconfirm -d 'Bypass any confirmation' -f
|
||||
complete -c $progname -n "not $noopt" -l sysroot -d 'Operate on a mounted guest system (root-only)' -xa "(__fish_complete_directories)"
|
||||
complete -c $progname -n "not $noopt" -l gpgdir -d 'GPG directory to verify signatures'
|
||||
complete -c $progname -n "not $noopt" -l hookdir -d 'Hook file directory'
|
||||
complete -c $progname -n "not $noopt" -l logfile -d 'Specify alternative log file'
|
||||
|
||||
# File, query, sync options (files, query, sync)
|
||||
for condition in files query sync
|
||||
complete -c $progname -n "$$condition" -s q -l quiet -d 'Show less information' -f
|
||||
end
|
||||
complete -c $progname -n "not $noopt" -l noconfirm -d 'Bypass any question' -f
|
||||
complete -c $progname -n "not $noopt" -l topdown -d 'Shows repository packages first and then aur' -f
|
||||
complete -c $progname -n "not $noopt" -l bottomup -d 'Shows aur packages first and then repository' -f
|
||||
complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg development version' -f
|
||||
complete -c $progname -n "not $noopt" -l nodevel -d 'Disable development version checking' -f
|
||||
complete -c $progname -n "not $noopt" -l afterclean -d 'Clean package sources after successful build' -f
|
||||
complete -c $progname -n "not $noopt" -l noafterclean -d 'Disable package sources cleaning' -f
|
||||
complete -c $progname -n "not $noopt" -l timeupdate -d 'Check package modification date and version' -f
|
||||
complete -c $progname -n "not $noopt" -l notimeupdate -d 'Check only package version change' -f
|
||||
|
||||
# Transaction options (sync, remove, upgrade)
|
||||
for condition in sync remove upgrade
|
||||
complete -c $progname -n "$$condition" -s d -l nodeps -d 'Skip [all] dependency checks' -f
|
||||
complete -c $progname -n "$$condition" -s p -l print -d 'Dry run, only print targets' -f
|
||||
complete -c $progname -n "$$condition" -l assume-installed -d 'Add a virtual package to satisfy dependencies' -f
|
||||
complete -c $progname -n "$$condition" -l dbonly -d 'Modify database entry only' -f
|
||||
complete -c $progname -n "$$condition" -l noprogressbar -d 'Do not display progress bar' -f
|
||||
complete -c $progname -n "$$condition" -l noscriptlet -d 'Do not execute install script' -f
|
||||
complete -c $progname -n "$$condition" -l print-format -d 'Specify printf-like format' -x
|
||||
end
|
||||
|
||||
# File and query options (files, query)
|
||||
for condition in files query
|
||||
complete -c $progname -n "$$condition" -s l -l list -d 'List the files owned by PACKAGE' -f
|
||||
end
|
||||
|
||||
# File and sync options (files, sync)
|
||||
for condition in files sync
|
||||
complete -c $progname -n "$$condition" -s y -l refresh -d 'Download fresh package databases [force]' -f
|
||||
end
|
||||
|
||||
# Query and sync options (query, sync)
|
||||
for condition in query sync
|
||||
complete -c $progname -n "$$condition" -s g -l groups -d 'Display members of [all] package GROUP' -xa "$listgroups"
|
||||
end
|
||||
|
||||
# Sync and upgrade options (sync, upgrade)
|
||||
for condition in sync upgrade
|
||||
complete -c $progname -n "$$condition" -l asdeps -d 'Install packages as non-explicitly installed' -f
|
||||
complete -c $progname -n "$$condition" -l asexplicit -d 'Install packages as explicitly installed' -f
|
||||
complete -c $progname -n "$$condition" -l ignore -d 'Ignore a package upgrade (can be used more than once)' -xa "$listall"
|
||||
complete -c $progname -n "$$condition" -l ignoregroup -d 'Ignore a group upgrade (can be used more than once)' -xa "$listgroups"
|
||||
complete -c $progname -n "$$condition" -l needed -d 'Do not reinstall up to date packages' -f
|
||||
complete -c $progname -n "$$condition" -l overwrite -d 'Overwrite conflicting files (can be used more than once)' -rF
|
||||
end
|
||||
|
||||
# Database options
|
||||
set -l has_db_opt '__fish_contains_opt asdeps asexplicit check -s k'
|
||||
complete -c $progname -n "$database; and not $has_db_opt" -s k -l check -d 'Check database validity'
|
||||
complete -c $progname -n "$database" -s q -l quite -d 'Suppress output of success messages' -f
|
||||
complete -c $progname -n "$database; and not $has_db_opt" -l asdeps -d 'Mark PACKAGE as dependency' -x
|
||||
complete -c $progname -n "$database; and not $has_db_opt" -l asexplicit -d 'Mark PACKAGE as explicitly installed' -x
|
||||
complete -c $progname -n "$has_db_opt; and $database" -xa "$listinstalled"
|
||||
|
||||
# File options - since pacman 5
|
||||
complete -c $progname -n "$files" -s x -l regex -d 'Interpret each query as a regular expression' -f
|
||||
complete -c $progname -n "$files" -l machinereadable -d 'Print each match in a machine readable output format' -f
|
||||
complete -c $progname -n "$files" -d Package -xa "$listpacman"
|
||||
|
||||
# Query options
|
||||
complete -c $progname -n "$query" -s c -l changelog -d 'View the change log of PACKAGE' -f
|
||||
complete -c $progname -n "$query" -s d -l deps -d 'List only non-explicit packages (dependencies)' -f
|
||||
complete -c $progname -n "$query" -s e -l explicit -d 'List only explicitly installed packages' -f
|
||||
complete -c $progname -n "$query" -s i -l info -d 'View PACKAGE [backup files] information' -f
|
||||
complete -c $progname -n "$query" -s k -l check -d 'Check that PACKAGE files exist' -f
|
||||
complete -c $progname -n "$query" -s m -l foreign -d 'List installed packages not found in sync database' -f
|
||||
complete -c $progname -n "$query" -s n -l native -d 'list installed packages only found in sync database' -f
|
||||
complete -c $progname -n "$query" -s o -l owns -d 'Query the package that owns FILE' -rF
|
||||
complete -c $progname -n "$query" -s p -l file -d 'Query a package file instead of the database' -rF
|
||||
complete -c $progname -n "$query" -s s -l search -d 'Search locally-installed packages for regexp' -f
|
||||
complete -c $progname -n "$query" -s t -l unrequired -d 'List only unrequired packages [and optdepends]' -f
|
||||
complete -c $progname -n "$query" -s u -l upgrades -d 'List only out-of-date packages' -f
|
||||
complete -c $progname -n "$query" -d 'Installed package' -xa "$listinstalled"
|
||||
|
||||
# Remove options
|
||||
complete -c $progname -n "$remove" -s c -l cascade -d 'Also remove packages depending on PACKAGE' -f
|
||||
complete -c $progname -n "$remove" -s n -l nosave -d 'Ignore file backup designations' -f
|
||||
complete -c $progname -n "$remove" -s s -l recursive -d 'Also remove dependencies of PACKAGE' -f
|
||||
complete -c $progname -n "$remove" -s u -l unneeded -d 'Only remove targets not required by PACKAGE' -f
|
||||
complete -c $progname -n "$remove" -d 'Installed package' -xa "$listinstalled"
|
||||
|
||||
# Sync options
|
||||
complete -c $progname -n "$sync" -s c -l clean -d 'Remove [all] packages from cache' -f
|
||||
complete -c $progname -n "$sync" -s i -l info -d 'View PACKAGE [extended] information' -f
|
||||
complete -c $progname -n "$sync" -s l -l list -d 'List all packages in REPOSITORY' -xa "$listrepos"
|
||||
complete -c $progname -n "$sync" -s s -l search -d 'Search remote repositories for regexp' -f
|
||||
complete -c $progname -n "$sync" -s u -l sysupgrade -d 'Upgrade all packages that are out of date'
|
||||
complete -c $progname -n "$sync" -s w -l downloadonly -d 'Only download the target packages'
|
||||
complete -c $progname -n "$sync" -xa "$listall $listgroups"
|
||||
|
||||
# Upgrade options
|
||||
# Theoretically, pacman reads packages in all formats that libarchive supports
|
||||
# In practice, it's going to be tar.xz, tar.gz, tar.zst, or just pkg.tar (uncompressed pkg)
|
||||
complete -c $progname -n "$upgrade" -xa '(__fish_complete_suffix pkg.tar.zst; __fish_complete_suffix pkg.tar.xz; __fish_complete_suffix pkg.tar.gz; __fish_complete_suffix pkg.tar;)' -d 'Package file'
|
||||
|
||||
|
||||
# Yay operations
|
||||
complete -c $progname -s Y -f -l yay -n "$noopt" -d 'Yay specific operations'
|
||||
complete -c $progname -s P -f -l show -n "$noopt" -d 'Print information'
|
||||
complete -c $progname -s G -f -l getpkgbuild -n "$noopt" -d 'Get PKGBUILD from ABS or AUR'
|
||||
complete -c $progname -s W -f -l web -n "$noopt" -d 'Web operations'
|
||||
|
||||
# Web options
|
||||
complete -c $progname -n "$webspecific" -s v -l vote -d 'Vote for AUR packages' -f
|
||||
complete -c $progname -n "$webspecific" -s u -l unvote -d 'Unvote for AUR packages' -f
|
||||
complete -c $progname -n "$webspecific" -xa "$listall"
|
||||
|
||||
# New options
|
||||
complete -c $progname -n "not $noopt" -s a -l aur -d 'Assume targets are from the AUR' -f
|
||||
complete -c $progname -n "not $noopt" -s N -l repo -d 'Assume targets are from the repositories' -f
|
||||
|
||||
# Yay options
|
||||
complete -c $progname -n "$yayspecific" -s c -l clean -d 'Remove unneeded dependencies' -f
|
||||
complete -c $progname -n "$yayspecific" -l gendb -d 'Generate development package DB' -f
|
||||
|
||||
# Show options
|
||||
complete -c $progname -n "$show" -s c -l complete -d 'Print a list of all AUR and repo packages' -f
|
||||
#complete -c $progname -n "$show" -s f -l fish -d 'During complete adjust the output for the fish shell' -f
|
||||
complete -c $progname -n "$show" -s d -l defaultconfig -d 'Print default yay configuration' -f
|
||||
complete -c $progname -n "$show" -s g -l currentconfig -d 'Print current yay configuration' -f
|
||||
complete -c $progname -n "$show" -s s -l stats -d 'Display system package statistics' -f
|
||||
complete -c $progname -n "$show" -s w -l news -d 'Print arch news' -f
|
||||
complete -c $progname -n "$show" -s q -l quiet -d 'Do not print news description' -f
|
||||
|
||||
# Getpkgbuild options
|
||||
complete -c $progname -n "$getpkgbuild" -s f -l force -d 'Force download for existing ABS packages' -f
|
||||
complete -c $progname -n "$getpkgbuild" -xa "$listall"
|
||||
complete -c $progname -n "$getpkgbuild" -s p -l print -d 'Print pkgbuild of packages' -f
|
||||
|
||||
# Permanent configuration settings
|
||||
complete -c $progname -n "not $noopt" -l save -d 'Save current arguments to yay permanent configuration' -f
|
||||
complete -c $progname -n "not $noopt" -l aururl -d 'Set an alternative AUR URL' -f
|
||||
complete -c $progname -n "not $noopt" -l aurrpcurl -d 'Set an alternative URL for the AUR /rpc endpoint' -f
|
||||
complete -c $progname -n "not $noopt" -l builddir -d 'Directory to use for Building AUR Packages' -r
|
||||
complete -c $progname -n "not $noopt" -l mflags -d 'Pass the following options to makepkg' -f
|
||||
complete -c $progname -n "not $noopt" -l gpgflags -d 'Pass the following options to gpg' -f
|
||||
complete -c $progname -n "not $noopt" -l buildir -d 'Specify the build directory' -f
|
||||
complete -c $progname -n "not $noopt" -l editor -d 'Editor to use' -f
|
||||
complete -c $progname -n "not $noopt" -l editorflags -d 'Editor flags to use' -f
|
||||
complete -c $progname -n "not $noopt" -l makepkg -d 'Makepkg command to use' -f
|
||||
@ -198,48 +81,156 @@ complete -c $progname -n "not $noopt" -l pacman -d 'Pacman command to use' -f
|
||||
complete -c $progname -n "not $noopt" -l tar -d 'Tar command to use' -f
|
||||
complete -c $progname -n "not $noopt" -l git -d 'Git command to use' -f
|
||||
complete -c $progname -n "not $noopt" -l gpg -d 'Gpg command to use' -f
|
||||
complete -c $progname -n "not $noopt" -l config -d 'The pacman config file to use' -r
|
||||
complete -c $progname -n "not $noopt" -l makepkgconf -d 'Use custom makepkg.conf location' -r
|
||||
complete -c $progname -n "not $noopt" -l nomakepkgconf -d 'Use default makepkg.conf' -f
|
||||
complete -c $progname -n "not $noopt" -l requestsplitn -d 'Max amount of packages to query per AUR request' -f
|
||||
complete -c $progname -n "not $noopt" -l completioninterval -d 'Refresh interval for completion cache' -f
|
||||
complete -c $progname -n "not $noopt" -l sortby -d 'Sort AUR results by a specific field during search' -xa "{votes,popularity,id,baseid,name,base,submitted,modified}"
|
||||
complete -c $progname -n "not $noopt" -l searchby -d 'Search for AUR packages by querying the specified field' -xa "{name,name-desc,maintainer,depends,checkdepends,makedepends,optdepends}"
|
||||
complete -c $progname -n "not $noopt" -l answerclean -d 'Set a predetermined answer for the clean build menu' -xa "{All,None,Installed,NotInstalled}"
|
||||
complete -c $progname -n "not $noopt" -l answerdiff -d 'Set a predetermined answer for the edit diff menu' -xa "{All,None,Installed,NotInstalled}"
|
||||
complete -c $progname -n "not $noopt" -l answeredit -d 'Set a predetermined answer for the edit pkgbuild menu' -xa "{All,None,Installed,NotInstalled}"
|
||||
complete -c $progname -n "not $noopt" -l answerupgrade -d 'Set a predetermined answer for the upgrade menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noanswerclean -d 'Unset the answer for the clean build menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noanswerdiff -d 'Unset the answer for the diff menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noansweredit -d 'Unset the answer for the edit pkgbuild menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noanswerupgrade -d 'Unset the answer for the upgrade menu' -f
|
||||
complete -c $progname -n "not $noopt" -l cleanmenu -d 'Give the option to clean build PKGBUILDS' -f
|
||||
complete -c $progname -n "not $noopt" -l diffmenu -d 'Give the option to show diffs for build files' -f
|
||||
complete -c $progname -n "not $noopt" -l editmenu -d 'Give the option to edit/view PKGBUILDS' -f
|
||||
complete -c $progname -n "not $noopt" -l askremovemake -d 'Ask to remove make deps after install' -f
|
||||
complete -c $progname -n "not $noopt" -l askyesremovemake -d 'Ask to remove make deps after install(with "Y" as default)' -f
|
||||
complete -c $progname -n "not $noopt" -l removemake -d 'Remove make deps after install' -f
|
||||
complete -c $progname -n "not $noopt" -l noremovemake -d 'Do not remove make deps after install' -f
|
||||
complete -c $progname -n "not $noopt" -l topdown -d 'Shows repository packages first and then aur' -f
|
||||
complete -c $progname -n "not $noopt" -l bottomup -d 'Shows aur packages first and then repository' -f
|
||||
complete -c $progname -n "not $noopt" -l singlelineresults -d 'List each search result on its own line' -f
|
||||
complete -c $progname -n "not $noopt" -l doublelineresults -d 'List each search result on two lines, like pacman' -f
|
||||
complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg development version' -f
|
||||
complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f
|
||||
complete -c $progname -n "not $noopt" -l keepsrc -d 'Keep pkg/ and src/ after building packages' -f
|
||||
complete -c $progname -n "not $noopt" -l timeupdate -d 'Check package modification date and version' -f
|
||||
complete -c $progname -n "not $noopt" -l sudoloop -d 'Loop sudo calls in the background to avoid timeout' -f
|
||||
complete -c $progname -n "not $noopt" -l nosudoloop -d 'Do not loop sudo calls in the background' -f
|
||||
complete -c $progname -n "not $noopt" -l redownload -d 'Redownload PKGBUILD of package even if up-to-date' -f
|
||||
complete -c $progname -n "not $noopt" -l redownloadall -d 'Redownload PKGBUILD of package and deps even if up-to-date' -f
|
||||
complete -c $progname -n "not $noopt" -l noredownload -d 'Do not redownload up-to-date PKGBUILDs' -f
|
||||
complete -c $progname -n "not $noopt" -l provides -d 'Look for matching providers when searching for packages' -f
|
||||
complete -c $progname -n "not $noopt" -l pgpfetch -d 'Prompt to import PGP keys from PKGBUILDs' -f
|
||||
complete -c $progname -n "not $noopt" -l useask -d 'Automatically resolve conflicts using pacmans ask flag' -f
|
||||
complete -c $progname -n "not $noopt" -l combinedupgrade -d 'Refresh then perform the repo and AUR upgrade together' -f
|
||||
complete -c $progname -n "not $noopt" -l batchinstall -d 'Build multiple AUR packages then install them together' -f
|
||||
complete -c $progname -n "not $noopt" -l redownloadall -d 'Redownload PKGBUILD of package and deps even if up-to-date' -f
|
||||
complete -c $progname -n "not $noopt" -l rebuild -d 'Always build target packages' -f
|
||||
complete -c $progname -n "not $noopt" -l rebuildall -d 'Always build all AUR packages' -f
|
||||
complete -c $progname -n "not $noopt" -l rebuildtree -d 'Always build all AUR packages even if installed' -f
|
||||
complete -c $progname -n "not $noopt" -l norebuild -d 'Skip package build if in cache and up to date' -f
|
||||
complete -c $progname -n "not $noopt" -l mflags -d 'Pass the following options to makepkg' -f
|
||||
complete -c $progname -n "not $noopt" -l gpgflags -d 'Pass the following options to gpg' -f
|
||||
complete -c $progname -n "not $noopt" -l sudoloop -d 'Loop sudo calls in the background to avoid timeout' -f
|
||||
|
||||
complete -c $progname -n "not $noopt" -l sortby -d 'Sort AUR results by a specific field during search' -f
|
||||
|
||||
complete -c $progname -n "not $noopt" -l answerclean -d 'Set a predetermined answer for the clean build menu' -f
|
||||
complete -c $progname -n "not $noopt" -l answeredit -d 'Set a predetermined answer for the edit pkgbuild menu' -f
|
||||
complete -c $progname -n "not $noopt" -l answerupgrade -d 'Set a predetermined answer for the upgrade menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noanswerclean -d 'Unset the answer for the clean build menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noansweredit -d 'Unset the answer for the edit pkgbuild menu' -f
|
||||
complete -c $progname -n "not $noopt" -l noanswerupgrade -d 'Unset the answer for the upgrade menu' -f
|
||||
|
||||
complete -c $progname -n "not $noopt" -l cleanmenu -d 'Give the option to clean build PKGBUILDS' -f
|
||||
complete -c $progname -n "not $noopt" -l diffmenu -d 'Give the option to show diffs for build files' -f
|
||||
complete -c $progname -n "not $noopt" -l editmenu -d 'Give the option to edit/view PKGBUILDS' -f
|
||||
complete -c $progname -n "not $noopt" -l upgrademenu -d 'Show a detailed list of updates with the option to skip any' -f
|
||||
complete -c $progname -n "not $noopt" -l nocleanmenu -d 'Do not clean build PKGBUILDS' -f
|
||||
complete -c $progname -n "not $noopt" -l nodiffmenu -d 'Do not show diffs for build files' -f
|
||||
complete -c $progname -n "not $noopt" -l noeditmenu -d 'Do not edit/view PKGBUILDS' -f
|
||||
complete -c $progname -n "not $noopt" -l noupgrademenu -d 'Do not show the upgrade menu' -f
|
||||
|
||||
|
||||
complete -c $progname -n "not $noopt" -l provides -d 'Look for matching providers when searching for packages'
|
||||
complete -c $progname -n "not $noopt" -l noprovides -d 'Just look for packages by pkgname'
|
||||
complete -c $progname -n "not $noopt" -l pgpfetch -d 'Prompt to import PGP keys from PKGBUILDs'
|
||||
complete -c $progname -n "not $noopt" -l nopgpfetch -d 'Do not prompt to import PGP keys'
|
||||
|
||||
# Post V7.887
|
||||
complete -c $progname -n "not $noopt" -l useask -d 'Automatically resolve conflicts using pacmans ask flag'
|
||||
complete -c $progname -n "not $noopt" -l nouseask -d 'Confirm conflicts manually during the install'
|
||||
complete -c $progname -n "not $noopt" -l combinedupgrade -d 'Refresh then perform the repo and AUR upgrade together'
|
||||
complete -c $progname -n "not $noopt" -l nocombinedupgrade -d 'Perform the repo upgrade and AUR upgrade separately'
|
||||
|
||||
#Post V8.976
|
||||
complete -c $progname -n "not $noopt" -l nomakepkgconf -d 'Use default makepkg.conf'
|
||||
complete -c $progname -n "not $noopt" -l makepkgconf -d 'Use custom makepkg.conf location'
|
||||
complete -c $progname -n "not $noopt" -l removemake -d 'Remove make deps after install'
|
||||
complete -c $progname -n "not $noopt" -l askremovemake -d 'Ask to remove make deps after install'
|
||||
complete -c $progname -n "not $noopt" -l noremovemake -d 'Do not remove make deps after install'
|
||||
complete -c $progname -n "not $noopt" -l completioninterval -d 'Refresh interval for completion cache'
|
||||
|
||||
# Yay options
|
||||
complete -c $progname -n $yayspecific -s c -l clean -d 'Remove unneeded dependencies' -f
|
||||
complete -c $progname -n $yayspecific -l gendb -d 'Generate development package DB' -f
|
||||
|
||||
# Show options
|
||||
complete -c $progname -n $show -s d -l defaultconfig -d 'Print default yay configuration' -f
|
||||
complete -c $progname -n $show -s g -l currentconfig -d 'Print current yay configuration' -f
|
||||
complete -c $progname -n $show -s s -l stats -d 'Display system package statistics' -f
|
||||
complete -c $progname -n $show -s w -l news -d 'Print arch news'
|
||||
complete -c $progname -n $show -s q -l quiet -d 'Do not print news description'
|
||||
|
||||
# Getpkgbuild options
|
||||
complete -c $progname -n $getpkgbuild -s f -l force -d 'Force download for existing tar packages' -f
|
||||
|
||||
# Transaction options (sync, remove, upgrade)
|
||||
for condition in sync remove upgrade
|
||||
complete -c $progname -n $$condition -s d -l nodeps -d 'Skip [all] dependency checks' -f
|
||||
complete -c $progname -n $$condition -l dbonly -d 'Modify database entry only' -f
|
||||
complete -c $progname -n $$condition -l noprogressbar -d 'Do not display progress bar' -f
|
||||
complete -c $progname -n $$condition -l noscriptlet -d 'Do not execute install script' -f
|
||||
complete -c $progname -n $$condition -s p -l print -d 'Dry run, only print targets' -f
|
||||
complete -c $progname -n $$condition -l print-format -x -d 'Specify printf-like format' -f
|
||||
end
|
||||
|
||||
# Database and upgrade options (database, sync, upgrade)
|
||||
for condition in database sync upgrade
|
||||
complete -c $progname -n $$condition -l asdeps -d 'Mark PACKAGE as dependency' -f
|
||||
complete -c $progname -n $$condition -l asexplicit -d 'Mark PACKAGE as explicitly installed' -f
|
||||
end
|
||||
|
||||
# Upgrade options (sync, upgrade)
|
||||
for condition in sync upgrade
|
||||
complete -c $progname -n $$condition -l force -d 'Bypass file conflict checks' -f
|
||||
complete -c $progname -n $$condition -l ignore -d 'Ignore upgrade of PACKAGE' -xa "$listinstalled" -f
|
||||
complete -c $progname -n $$condition -l ignoregroup -d 'Ignore upgrade of GROUP' -xa "$listgroups" -f
|
||||
complete -c $progname -n $$condition -l needed -d 'Do not reinstall up-to-date targets' -f
|
||||
complete -c $progname -n $$condition -l recursive -d 'Recursively reinstall all dependencies' -f
|
||||
end
|
||||
|
||||
# Query and sync options
|
||||
for condition in query sync
|
||||
complete -c $progname -n $$condition -s g -l groups -d 'Display all packages in GROUP' -xa "$listgroups" -f
|
||||
complete -c $progname -n $$condition -s i -l info -d 'Display information on PACKAGE' -f
|
||||
complete -c $progname -n $$condition -s q -l quiet -d 'Show less information' -f
|
||||
complete -c $progname -n $$condition -s s -l search -r -d 'Search packages for regexp' -f
|
||||
end
|
||||
|
||||
# Get PKGBUILD options
|
||||
complete -c $progname -n "$getpkgbuild" -xa "$listall"
|
||||
|
||||
# Query options
|
||||
complete -c $progname -n $query -s c -l changelog -d 'View the change log of PACKAGE' -f
|
||||
complete -c $progname -n $query -s d -l deps -d 'List only non-explicit packages (dependencies)' -f
|
||||
complete -c $progname -n $query -s e -l explicit -d 'List only explicitly installed packages' -f
|
||||
complete -c $progname -n $query -s k -l check -d 'Check if all files owned by PACKAGE are present' -f
|
||||
complete -c $progname -n $query -s l -l list -d 'List all files owned by PACKAGE' -f
|
||||
complete -c $progname -n $query -s m -l foreign -d 'List all packages not in the database' -f
|
||||
complete -c $progname -n $query -s o -l owns -r -d 'Search for the package that owns FILE' -xa '' -f
|
||||
complete -c $progname -n $query -s p -l file -d 'Apply the query to a package file, not package' -xa '' -f
|
||||
complete -c $progname -n $query -s t -l unrequired -d 'List only unrequired packages' -f
|
||||
complete -c $progname -n $query -s u -l upgrades -d 'List only out-of-date packages' -f
|
||||
complete -c $progname -n "$query" -d 'Installed package' -xa $listinstalled -f
|
||||
|
||||
# Remove options
|
||||
complete -c $progname -n $remove -s c -l cascade -d 'Also remove packages depending on PACKAGE' -f
|
||||
complete -c $progname -n $remove -s n -l nosave -d 'Ignore file backup designations' -f
|
||||
complete -c $progname -n $remove -s s -l recursive -d 'Also remove dependencies of PACKAGE' -f
|
||||
complete -c $progname -n $remove -s u -l unneeded -d 'Only remove targets not required by PACKAGE' -f
|
||||
complete -c $progname -n "$remove" -d 'Installed package' -xa $listinstalled -f
|
||||
|
||||
# Sync options
|
||||
complete -c $progname -n $sync -s c -l clean -d 'Remove [all] packages from cache'
|
||||
complete -c $progname -n $sync -s l -l list -xa "$listrepos" -d 'List all packages in REPOSITORY'
|
||||
complete -c $progname -n "$sync; and not __fish_contains_opt -s u sysupgrade" -s u -l sysupgrade -d 'Upgrade all packages that are out of date'
|
||||
complete -c $progname -n "$sync; and __fish_contains_opt -s u sysupgrade" -s u -l sysupgrade -d 'Also downgrade packages'
|
||||
complete -c $progname -n $sync -s w -l downloadonly -d 'Only download the target packages'
|
||||
complete -c $progname -n $sync -s y -l refresh -d 'Download fresh copy of the package list'
|
||||
complete -c $progname -n "$sync" -xa "$listall $listgroups"
|
||||
|
||||
# Database options
|
||||
set -l has_db_opt '__fish_contains_opt asdeps asexplicit'
|
||||
complete -c $progname -n "$database; and not $has_db_opt" -xa --asdeps -d 'Mark PACKAGE as dependency'
|
||||
complete -c $progname -n "$database; and not $has_db_opt" -xa --asexplicit -d 'Mark PACKAGE as explicitly installed'
|
||||
complete -c $progname -n "$database; and not $has_db_opt" -s k -l check -d 'Check database validity'
|
||||
complete -c $progname -n "$has_db_opt; and $database" -xa "$listinstalled"
|
||||
|
||||
# File options - since pacman 5
|
||||
set -l has_file_opt '__fish_contains_opt list search -s l -s s'
|
||||
complete -c $progname -n "$files; and not $has_file_opt" -xa --list -d 'List files owned by given packages'
|
||||
complete -c $progname -n "$files; and not $has_file_opt" -xa -l -d 'List files owned by given packages'
|
||||
complete -c $progname -n "$files; and not $has_file_opt" -xa --search -d 'Search packages for matching files'
|
||||
complete -c $progname -n "$files; and not $has_file_opt" -xa -s -d 'Search packages for matching files'
|
||||
complete -c $progname -n "$files" -s y -l refresh -d 'Refresh the files database' -f
|
||||
complete -c $progname -n "$files" -s l -l list -d 'List files owned by given packages' -xa $listpacman
|
||||
complete -c $progname -n "$files" -s s -l search -d 'Search packages for matching files'
|
||||
complete -c $progname -n "$files" -s o -l owns -d 'Search for packages that include the given files'
|
||||
complete -c $progname -n "$files" -s q -l quiet -d 'Show less information' -f
|
||||
complete -c $progname -n "$files" -l machinereadable -d 'Show in machine readable format: repo\0pkgname\0pkgver\0path\n' -f
|
||||
|
||||
# Upgrade options
|
||||
complete -c $progname -n "$upgrade" -xa '(__fish_complete_suffix pkg.tar.xz)' -d 'Package file'
|
||||
complete -c $progname -n "$upgrade" -xa '(__fish_complete_suffix pkg.tar.gz)' -d 'Package file'
|
||||
complete -c $progname -n "$upgrade" -xa '(__fish_complete_suffix pkg.tar.lzo)' -d 'Package file'
|
||||
complete -c $progname -n "$upgrade" -xa '(__fish_complete_suffix pkg.tar)' -d 'Package file'
|
||||
|
@ -1,5 +1,5 @@
|
||||
#compdef yay
|
||||
# vim:tabstop=2 shiftwidth=2 filetype=zsh
|
||||
# vim:fdm=marker foldlevel=0 tabstop=2 shiftwidth=2 filetype=zsh
|
||||
|
||||
typeset -A opt_args
|
||||
setopt extendedglob
|
||||
@ -16,17 +16,15 @@ _pacman_opts_commands=(
|
||||
{-T,--deptest}'[Check if dependencies are installed]'
|
||||
{-U,--upgrade}'[Upgrade a package]'
|
||||
{-Y,--yay}'[Yay specific options]'
|
||||
{-W,--web}'[web options]'
|
||||
{-V,--version}'[Display version and exit]'
|
||||
'(-h --help)'{-h,--help}'[Display usage]'
|
||||
)
|
||||
|
||||
# options for passing to _arguments: options common to all commands
|
||||
_pacman_opts_common=(
|
||||
{-N,--repo}'[Assume targets are from the repositories]'
|
||||
'--repo[Assume targets are from the repositories]'
|
||||
{-a,--aur}'[Assume targets are from the AUR]'
|
||||
'--aururl[Set an alternative AUR URL]:url'
|
||||
'--aurrpcurl[Set an alternative URL for the AUR /rpc endpoint]:url'
|
||||
'--arch[Set an alternate architecture]'
|
||||
{-b,--dbpath}'[Alternate database location]:database_location:_files -/'
|
||||
'--color[colorize the output]:color options:(always never auto)'
|
||||
@ -38,7 +36,7 @@ _pacman_opts_common=(
|
||||
'--makepkgconf[makepkg.conf file to use]:config file:_files'
|
||||
'--nomakepkgconf[Use the default makepkg.conf]'
|
||||
'--requestsplitn[Max amount of packages to query per AUR request]:number'
|
||||
'--completioninterval[Time in days to refresh completion cache]:number'
|
||||
'--completioninterval[Time in days to to refresh completion cache]:number'
|
||||
'--confirm[Always ask for confirmation]'
|
||||
'--debug[Display debug messages]'
|
||||
'--gpgdir[Set an alternate directory for GnuPG (instead of /etc/pacman.d/gnupg)]: :_files -/'
|
||||
@ -55,51 +53,56 @@ _pacman_opts_common=(
|
||||
'--editorflags[Flags to pass to editor]'
|
||||
'--makepkg[makepkg command to use]:makepkg:_files'
|
||||
'--pacman[pacman command to use]:pacman:_files'
|
||||
'--tar[bsdtar command to use]:tar:_files'
|
||||
'--git[git command to use]:git:_files'
|
||||
'--gpg[gpg command to use]:gpg:_files'
|
||||
|
||||
'--sortby[Sort AUR results by a specific field during search]:sortby options:(votes popularity id baseid name base submitted modified)'
|
||||
'--answerclean[Set a predetermined answer for the clean build menu]:answer'
|
||||
'--answerdiff[Set a predetermined answer for the diff menu]:answer'
|
||||
'--answeredit[Set a predetermined answer for the edit pkgbuild menu]:answer'
|
||||
'--answerupgrade[Set a predetermined answer for the upgrade menu]:answer'
|
||||
'--noanswerclean[Unset the answer for the clean build menu]'
|
||||
'--noanswerdiff[Unset the answer for the diff menu]'
|
||||
'--noansweredit[Unset the answer for the edit pkgbuild menu]'
|
||||
'--noanswerupgrade[Unset the answer for the upgrade menu]'
|
||||
'--cleanmenu[Give the option to clean build PKGBUILDS]'
|
||||
'--diffmenu[Give the option to show diffs for build files]'
|
||||
'--editmenu[Give the option to edit/view PKGBUILDS]'
|
||||
'--upgrademenu[Show a detailed list of updates with the option to skip any]'
|
||||
"--nocleanmenu[Don't clean build PKGBUILDS]"
|
||||
"--nodiffmenu[Don't show diffs for build files]"
|
||||
"--noeditmenu[Don't edit/view PKGBUILDS]"
|
||||
"--noupgrademenu[Don't show the upgrade menu]"
|
||||
"--askremovemake[Ask to remove makedepends after install]"
|
||||
"--askyesremovemake[Ask to remove makedepends after install(with "Y" as default)]"
|
||||
"--removemake[Remove makedepends after install]"
|
||||
"--noremovemake[Don't remove makedepends after install]"
|
||||
|
||||
'--bottomup[Show AUR packages first]'
|
||||
'--topdown[Show repository packages first]'
|
||||
'--singlelineresults[List each search result on its own line]'
|
||||
'--doublelineresults[List each search result on two lines, like pacman]'
|
||||
'--devel[Check -git/-svn/-hg development version]'
|
||||
'--cleanafter[Clean package sources after successful build]'
|
||||
'--keepsrc[Keep pkg/ and src/ after building packages]'
|
||||
'--nodevel[Disable development version checking]'
|
||||
'--afterclean[Clean package sources after successful build]'
|
||||
'--noafterclean[Disable package sources cleaning after successful build]'
|
||||
'--timeupdate[Check packages modification date and version]'
|
||||
'--notimeupdate[Check only package version change]'
|
||||
'--redownload[Always download pkgbuilds of targets]'
|
||||
'--redownloadall[Always download pkgbuilds of all AUR packages]'
|
||||
'--noredownload[Skip pkgbuild download if in cache and up to date]'
|
||||
'--rebuild[Always build target packages]'
|
||||
'--rebuildall[Always build all AUR packages]'
|
||||
'--provides[Look for matching providers when searching for packages]'
|
||||
'--provides[Look for matching provders when searching for packages]'
|
||||
'--noprovides[Just look for packages by pkgname]'
|
||||
'--pgpfetch[Prompt to import PGP keys from PKGBUILDs]'
|
||||
"--nopgpfetch[Don't prompt to import PGP keys]"
|
||||
"--useask[Automatically resolve conflicts using pacman's ask flag]"
|
||||
'--nouseask[Confirm conflicts manually during the install]'
|
||||
'--combinedupgrade[Refresh then perform the repo and AUR upgrade together]'
|
||||
'--nocombinedupgrade[Perform the repo upgrade and AUR upgrade separately]'
|
||||
'--rebuildtree[Always build all AUR packages even if installed]'
|
||||
'--norebuild[Skip package build if in cache and up to date]'
|
||||
'--mflags[Pass arguments to makepkg]:mflags'
|
||||
'--gpgflags[Pass arguments to gpg]:gpgflags'
|
||||
'--sudoloop[Loop sudo calls in the background to avoid timeout]'
|
||||
'--searchby[Search for packages using a specified field]'
|
||||
'--sortby[Sort AUR results by a specific field during search]'
|
||||
'--batchinstall[Build multiple AUR packages then install them together]'
|
||||
'--nosudoloop[Do not loop sudo calls in the backgrount]'
|
||||
)
|
||||
|
||||
# options for passing to _arguments: options for --upgrade commands
|
||||
@ -108,7 +111,7 @@ _pacman_opts_pkgfile=(
|
||||
'*--nodeps[Skip dependency checks]'
|
||||
'*--assume-installed[Add virtual package to satisfy dependencies]'
|
||||
'--dbonly[Only remove database entry, do not remove files]'
|
||||
'--overwrite[Overwrite conflicting files]:file:_files -g "*"'
|
||||
'--force[Overwrite conflicting files]'
|
||||
'--needed[Do not reinstall up to date packages]'
|
||||
'--asdeps[mark packages as non-explicitly installed]'
|
||||
'--asexplicit[mark packages as explicitly installed]'
|
||||
@ -151,14 +154,7 @@ _pacman_opts_yay_modifiers=(
|
||||
|
||||
# -G
|
||||
_pacman_opts_getpkgbuild_modifiers=(
|
||||
{-f,--force}'[Force download for existing ABS packages]'
|
||||
{-p,--print}'[Print PKGBUILDs]:package:_pacman_completions_all_packages'
|
||||
)
|
||||
|
||||
# -W
|
||||
_pacman_opts_web_modifiers=(
|
||||
{-u,--unvote}'[Unvote AUR package]:package:_pacman_completions_all_packages'
|
||||
{-v,--vote}'[Vote AUR package]:package:_pacman_completions_all_packages'
|
||||
{-f,--force}'[Force download for existing tar packages]'
|
||||
)
|
||||
|
||||
# -P
|
||||
@ -193,6 +189,8 @@ _pacman_opts_database=(
|
||||
|
||||
_pacman_opts_files=(
|
||||
{-l,--list}'[List the files owned by the queried package]:package:_pacman_completions_all_packages'
|
||||
{-o,--owns}'[Query the package that owns]:files:_files'
|
||||
{-s,--search}'[Search package file names for matching strings]:files:_files'
|
||||
{-x,--regex}'[Enable searching using regular expressions]:regex:'
|
||||
{-y,--refresh}'[Download fresh files databases from the server]'
|
||||
'--machinereadable[Produce machine-readable output]'
|
||||
@ -225,7 +223,7 @@ _pacman_opts_sync_modifiers=(
|
||||
'*--ignoregroup[Ignore a group upgrade]:package group:_pacman_completions_all_groups'
|
||||
'--asdeps[Install packages as non-explicitly installed]'
|
||||
'--asexplicit[Install packages as explicitly installed]'
|
||||
'--overwrite[Overwrite conflicting files]:files:_files'
|
||||
'--force[Overwrite conflicting files]'
|
||||
'--print-format[Specify how the targets should be printed]'
|
||||
)
|
||||
|
||||
@ -500,19 +498,16 @@ _pacman_zsh_comp() {
|
||||
"$_pacman_opts_query_modifiers[@]" \
|
||||
'*:package file:_files -g "*.pkg.tar*~*.sig(.,@)"'
|
||||
;;
|
||||
T*)
|
||||
_pacman_action_deptest
|
||||
;;
|
||||
Q*)
|
||||
_pacman_action_query
|
||||
;;
|
||||
P*)
|
||||
_arguments -s : \
|
||||
'-P' \
|
||||
"$_pacman_opts_print_modifiers[@]"
|
||||
;;
|
||||
W*)
|
||||
_arguments -s : \
|
||||
'-W' \
|
||||
"$_pacman_opts_web_modifiers[@]"
|
||||
;;
|
||||
R*)
|
||||
_pacman_action_remove
|
||||
;;
|
||||
@ -543,7 +538,10 @@ _pacman_zsh_comp() {
|
||||
_pacman_action_sync
|
||||
;;
|
||||
T*)
|
||||
_pacman_action_deptest
|
||||
_arguments -s : \
|
||||
'-T' \
|
||||
"$_pacman_opts_common[@]" \
|
||||
":packages:_pacman_all_packages"
|
||||
;;
|
||||
U*)
|
||||
_pacman_action_upgrade
|
||||
@ -553,12 +551,10 @@ _pacman_zsh_comp() {
|
||||
;;
|
||||
Y*)
|
||||
_arguments -s : \
|
||||
'-Y' \
|
||||
"$_pacman_opts_yay_modifiers[@]"
|
||||
;;
|
||||
G*)
|
||||
_arguments -s : \
|
||||
'-G' \
|
||||
"$_pacman_opts_getpkgbuild_modifiers[@]"
|
||||
;;
|
||||
|
||||
|
433
config.go
Normal file
433
config.go
Normal file
@ -0,0 +1,433 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
pacmanconf "github.com/Morganamilo/go-pacmanconf"
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
// Verbosity settings for search
|
||||
const (
|
||||
NumberMenu = iota
|
||||
Detailed
|
||||
Minimal
|
||||
)
|
||||
|
||||
// Describes Sorting method for numberdisplay
|
||||
const (
|
||||
BottomUp = iota
|
||||
TopDown
|
||||
)
|
||||
|
||||
type targetMode int
|
||||
|
||||
const (
|
||||
ModeAUR targetMode = iota
|
||||
ModeRepo
|
||||
ModeAny
|
||||
)
|
||||
|
||||
// Configuration stores yay's config.
|
||||
type Configuration struct {
|
||||
AURURL string `json:"aururl"`
|
||||
BuildDir string `json:"buildDir"`
|
||||
Editor string `json:"editor"`
|
||||
EditorFlags string `json:"editorflags"`
|
||||
MakepkgBin string `json:"makepkgbin"`
|
||||
MakepkgConf string `json:"makepkgconf"`
|
||||
PacmanBin string `json:"pacmanbin"`
|
||||
PacmanConf string `json:"pacmanconf"`
|
||||
TarBin string `json:"tarbin"`
|
||||
ReDownload string `json:"redownload"`
|
||||
ReBuild string `json:"rebuild"`
|
||||
AnswerClean string `json:"answerclean"`
|
||||
AnswerDiff string `json:"answerdiff"`
|
||||
AnswerEdit string `json:"answeredit"`
|
||||
AnswerUpgrade string `json:"answerupgrade"`
|
||||
GitBin string `json:"gitbin"`
|
||||
GpgBin string `json:"gpgbin"`
|
||||
GpgFlags string `json:"gpgflags"`
|
||||
MFlags string `json:"mflags"`
|
||||
SortBy string `json:"sortby"`
|
||||
GitFlags string `json:"gitflags"`
|
||||
RemoveMake string `json:"removemake"`
|
||||
RequestSplitN int `json:"requestsplitn"`
|
||||
SearchMode int `json:"-"`
|
||||
SortMode int `json:"sortmode"`
|
||||
CompletionInterval int `json:"completionrefreshtime"`
|
||||
SudoLoop bool `json:"sudoloop"`
|
||||
TimeUpdate bool `json:"timeupdate"`
|
||||
NoConfirm bool `json:"-"`
|
||||
Devel bool `json:"devel"`
|
||||
CleanAfter bool `json:"cleanAfter"`
|
||||
GitClone bool `json:"gitclone"`
|
||||
Provides bool `json:"provides"`
|
||||
PGPFetch bool `json:"pgpfetch"`
|
||||
UpgradeMenu bool `json:"upgrademenu"`
|
||||
CleanMenu bool `json:"cleanmenu"`
|
||||
DiffMenu bool `json:"diffmenu"`
|
||||
EditMenu bool `json:"editmenu"`
|
||||
CombinedUpgrade bool `json:"combinedupgrade"`
|
||||
UseAsk bool `json:"useask"`
|
||||
}
|
||||
|
||||
var version = "8.1139"
|
||||
|
||||
// configFileName holds the name of the config file.
|
||||
const configFileName string = "config.json"
|
||||
|
||||
// vcsFileName holds the name of the vcs file.
|
||||
const vcsFileName string = "vcs.json"
|
||||
|
||||
// useColor enables/disables colored printing
|
||||
var useColor bool
|
||||
|
||||
// configHome handles config directory home
|
||||
var configHome string
|
||||
|
||||
// cacheHome handles cache home
|
||||
var cacheHome string
|
||||
|
||||
// savedInfo holds the current vcs info
|
||||
var savedInfo vcsInfo
|
||||
|
||||
// configfile holds yay config file path.
|
||||
var configFile string
|
||||
|
||||
// vcsfile holds yay vcs info file path.
|
||||
var vcsFile string
|
||||
|
||||
// shouldSaveConfig holds whether or not the config should be saved
|
||||
var shouldSaveConfig bool
|
||||
|
||||
// YayConf holds the current config values for yay.
|
||||
var config Configuration
|
||||
|
||||
// AlpmConf holds the current config values for pacman.
|
||||
var pacmanConf *pacmanconf.Config
|
||||
|
||||
// AlpmHandle is the alpm handle used by yay.
|
||||
var alpmHandle *alpm.Handle
|
||||
|
||||
// Mode is used to restrict yay to AUR or repo only modes
|
||||
var mode = ModeAny
|
||||
|
||||
// SaveConfig writes yay config to file.
|
||||
func (config *Configuration) saveConfig() error {
|
||||
marshalledinfo, _ := json.MarshalIndent(config, "", "\t")
|
||||
in, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
_, err = in.Write(marshalledinfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = in.Sync()
|
||||
return err
|
||||
}
|
||||
|
||||
func (config *Configuration) defaultSettings() {
|
||||
buildDir := "$HOME/.cache/yay"
|
||||
if os.Getenv("XDG_CACHE_HOME") != "" {
|
||||
buildDir = "$XDG_CACHE_HOME/yay"
|
||||
}
|
||||
|
||||
config.AURURL = "https://aur.archlinux.org"
|
||||
config.BuildDir = buildDir
|
||||
config.CleanAfter = false
|
||||
config.Editor = ""
|
||||
config.EditorFlags = ""
|
||||
config.Devel = false
|
||||
config.MakepkgBin = "makepkg"
|
||||
config.MakepkgConf = ""
|
||||
config.NoConfirm = false
|
||||
config.PacmanBin = "pacman"
|
||||
config.PGPFetch = true
|
||||
config.PacmanConf = "/etc/pacman.conf"
|
||||
config.GpgFlags = ""
|
||||
config.MFlags = ""
|
||||
config.GitFlags = ""
|
||||
config.SortMode = BottomUp
|
||||
config.CompletionInterval = 7
|
||||
config.SortBy = "votes"
|
||||
config.SudoLoop = false
|
||||
config.TarBin = "bsdtar"
|
||||
config.GitBin = "git"
|
||||
config.GpgBin = "gpg"
|
||||
config.TimeUpdate = false
|
||||
config.RequestSplitN = 150
|
||||
config.ReDownload = "no"
|
||||
config.ReBuild = "no"
|
||||
config.AnswerClean = ""
|
||||
config.AnswerDiff = ""
|
||||
config.AnswerEdit = ""
|
||||
config.AnswerUpgrade = ""
|
||||
config.RemoveMake = "ask"
|
||||
config.GitClone = true
|
||||
config.Provides = true
|
||||
config.UpgradeMenu = true
|
||||
config.CleanMenu = true
|
||||
config.DiffMenu = true
|
||||
config.EditMenu = false
|
||||
config.UseAsk = false
|
||||
config.CombinedUpgrade = false
|
||||
}
|
||||
|
||||
func (config *Configuration) expandEnv() {
|
||||
config.AURURL = os.ExpandEnv(config.AURURL)
|
||||
config.BuildDir = os.ExpandEnv(config.BuildDir)
|
||||
config.Editor = os.ExpandEnv(config.Editor)
|
||||
config.EditorFlags = os.ExpandEnv(config.EditorFlags)
|
||||
config.MakepkgBin = os.ExpandEnv(config.MakepkgBin)
|
||||
config.MakepkgConf = os.ExpandEnv(config.MakepkgConf)
|
||||
config.PacmanBin = os.ExpandEnv(config.PacmanBin)
|
||||
config.PacmanConf = os.ExpandEnv(config.PacmanConf)
|
||||
config.GpgFlags = os.ExpandEnv(config.GpgFlags)
|
||||
config.MFlags = os.ExpandEnv(config.MFlags)
|
||||
config.GitFlags = os.ExpandEnv(config.GitFlags)
|
||||
config.SortBy = os.ExpandEnv(config.SortBy)
|
||||
config.TarBin = os.ExpandEnv(config.TarBin)
|
||||
config.GitBin = os.ExpandEnv(config.GitBin)
|
||||
config.GpgBin = os.ExpandEnv(config.GpgBin)
|
||||
config.ReDownload = os.ExpandEnv(config.ReDownload)
|
||||
config.ReBuild = os.ExpandEnv(config.ReBuild)
|
||||
config.AnswerClean = os.ExpandEnv(config.AnswerClean)
|
||||
config.AnswerDiff = os.ExpandEnv(config.AnswerDiff)
|
||||
config.AnswerEdit = os.ExpandEnv(config.AnswerEdit)
|
||||
config.AnswerUpgrade = os.ExpandEnv(config.AnswerUpgrade)
|
||||
config.RemoveMake = os.ExpandEnv(config.RemoveMake)
|
||||
}
|
||||
|
||||
// Editor returns the preferred system editor.
|
||||
func editor() (string, []string) {
|
||||
switch {
|
||||
case config.Editor != "":
|
||||
editor, err := exec.LookPath(config.Editor)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
return editor, strings.Fields(config.EditorFlags)
|
||||
}
|
||||
fallthrough
|
||||
case os.Getenv("EDITOR") != "":
|
||||
editorArgs := strings.Fields(os.Getenv("EDITOR"))
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
fallthrough
|
||||
case os.Getenv("VISUAL") != "":
|
||||
editorArgs := strings.Fields(os.Getenv("VISUAL"))
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
fmt.Println()
|
||||
fmt.Println(bold(red(arrow)), bold(cyan("$EDITOR")), bold("is not set"))
|
||||
fmt.Println(bold(red(arrow)) + bold(" Please add ") + bold(cyan("$EDITOR")) + bold(" or ") + bold(cyan("$VISUAL")) + bold(" to your environment variables."))
|
||||
|
||||
for {
|
||||
fmt.Print(green(bold(arrow + " Edit PKGBUILD with: ")))
|
||||
editorInput, err := getInput("")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
editorArgs := strings.Fields(editorInput)
|
||||
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ContinueTask prompts if user wants to continue task.
|
||||
//If NoConfirm is set the action will continue without user input.
|
||||
func continueTask(s string, cont bool) bool {
|
||||
if config.NoConfirm {
|
||||
return cont
|
||||
}
|
||||
|
||||
var response string
|
||||
var postFix string
|
||||
yes := "yes"
|
||||
no := "no"
|
||||
y := string([]rune(yes)[0])
|
||||
n := string([]rune(no)[0])
|
||||
|
||||
if cont {
|
||||
postFix = fmt.Sprintf(" [%s/%s] ", strings.ToUpper(y), n)
|
||||
} else {
|
||||
postFix = fmt.Sprintf(" [%s/%s] ", y, strings.ToUpper(n))
|
||||
}
|
||||
|
||||
fmt.Print(bold(green(arrow)+" "+s), bold(postFix))
|
||||
|
||||
len, err := fmt.Scanln(&response)
|
||||
if err != nil || len == 0 {
|
||||
return cont
|
||||
}
|
||||
|
||||
response = strings.ToLower(response)
|
||||
return response == yes || response == y
|
||||
}
|
||||
|
||||
func getInput(defaultValue string) (string, error) {
|
||||
if defaultValue != "" || config.NoConfirm {
|
||||
fmt.Println(defaultValue)
|
||||
return defaultValue, nil
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
buf, overflow, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if overflow {
|
||||
return "", fmt.Errorf("Input too long")
|
||||
}
|
||||
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
func (config Configuration) String() string {
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
enc.SetIndent("", "\t")
|
||||
if err := enc.Encode(config); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func toUsage(usages []string) alpm.Usage {
|
||||
if len(usages) == 0 {
|
||||
return alpm.UsageAll
|
||||
}
|
||||
|
||||
var ret alpm.Usage = 0
|
||||
for _, usage := range usages {
|
||||
switch usage {
|
||||
case "Sync":
|
||||
ret |= alpm.UsageSync
|
||||
case "Search":
|
||||
ret |= alpm.UsageSearch
|
||||
case "Install":
|
||||
ret |= alpm.UsageInstall
|
||||
case "Upgrade":
|
||||
ret |= alpm.UsageUpgrade
|
||||
case "All":
|
||||
ret |= alpm.UsageAll
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func configureAlpm(conf *pacmanconf.Config) error {
|
||||
var err error
|
||||
|
||||
// TODO: set SigLevel
|
||||
//sigLevel := alpm.SigPackage | alpm.SigPackageOptional | alpm.SigDatabase | alpm.SigDatabaseOptional
|
||||
//localFileSigLevel := alpm.SigUseDefault
|
||||
//remoteFileSigLevel := alpm.SigUseDefault
|
||||
|
||||
for _, repo := range pacmanConf.Repos {
|
||||
// TODO: set SigLevel
|
||||
db, err := alpmHandle.RegisterSyncDb(repo.Name, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db.SetServers(repo.Servers)
|
||||
db.SetUsage(toUsage(repo.Usage))
|
||||
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetCacheDirs(pacmanConf.CacheDir...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add hook directories 1-by-1 to avoid overwriting the system directory
|
||||
for _, dir := range pacmanConf.HookDir {
|
||||
if err = alpmHandle.AddHookDir(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetGPGDir(pacmanConf.GPGDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetLogFile(pacmanConf.LogFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetIgnorePkgs(pacmanConf.IgnorePkg...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetIgnoreGroups(pacmanConf.IgnoreGroup...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetArch(pacmanConf.Architecture); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetNoUpgrades(pacmanConf.NoUpgrade...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if alpmHandle.SetNoExtracts(pacmanConf.NoExtract...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
/*if err = alpmHandle.SetDefaultSigLevel(sigLevel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetLocalFileSigLevel(localFileSigLevel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetRemoteFileSigLevel(remoteFileSigLevel); err != nil {
|
||||
return err
|
||||
}*/
|
||||
|
||||
if err = alpmHandle.SetDeltaRatio(pacmanConf.UseDelta); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetUseSyslog(pacmanConf.UseSyslog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = alpmHandle.SetCheckSpace(pacmanConf.CheckSpace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
61
config_test.go
Normal file
61
config_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func expect(t *testing.T, field string, a interface{}, b interface{}, err error) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(a, b) {
|
||||
t.Errorf("%s expected: %s got %s", field, a, b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
config.PacmanConf = "testdata/pacman.conf"
|
||||
|
||||
err := initAlpm()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
h := alpmHandle
|
||||
|
||||
root, err := h.Root()
|
||||
expect(t, "RootDir", "/", root, err)
|
||||
|
||||
cache, err := h.CacheDirs()
|
||||
expect(t, "CacheDir", []string{"/cachedir/", "/another/"}, cache.Slice(), err)
|
||||
|
||||
log, err := h.LogFile()
|
||||
expect(t, "LogFile", "/logfile", log, err)
|
||||
|
||||
gpg, err := h.GPGDir()
|
||||
expect(t, "GPGDir", "/gpgdir/", gpg, err)
|
||||
|
||||
hook, err := h.HookDirs()
|
||||
expect(t, "HookDir", []string{"/usr/share/libalpm/hooks/", "/hookdir/"}, hook.Slice(), err)
|
||||
|
||||
delta, err := h.DeltaRatio()
|
||||
expect(t, "UseDelta", 0.5, delta, err)
|
||||
|
||||
arch, err := h.Arch()
|
||||
expect(t, "Architecture", "8086", arch, err)
|
||||
|
||||
ignorePkg, err := h.IgnorePkgs()
|
||||
expect(t, "IgnorePkg", []string{"ignore", "this", "package"}, ignorePkg.Slice(), err)
|
||||
|
||||
ignoreGroup, err := h.IgnoreGroups()
|
||||
expect(t, "IgnoreGroup", []string{"ignore", "this", "group"}, ignoreGroup.Slice(), err)
|
||||
|
||||
noUp, err := h.NoUpgrades()
|
||||
expect(t, "NoUpgrade", []string{"noupgrade"}, noUp.Slice(), err)
|
||||
|
||||
noEx, err := h.NoExtracts()
|
||||
expect(t, "NoExtract", []string{"noextract"}, noEx.Slice(), err)
|
||||
|
||||
check, err := h.CheckSpace()
|
||||
expect(t, "CheckSpace", true, check, err)
|
||||
}
|
174
dep.go
Normal file
174
dep.go
Normal file
@ -0,0 +1,174 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
)
|
||||
|
||||
type providers struct {
|
||||
lookfor string
|
||||
Pkgs []*rpc.Pkg
|
||||
}
|
||||
|
||||
func makeProviders(name string) providers {
|
||||
return providers{
|
||||
name,
|
||||
make([]*rpc.Pkg, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (q providers) Len() int {
|
||||
return len(q.Pkgs)
|
||||
}
|
||||
|
||||
func (q providers) Less(i, j int) bool {
|
||||
if q.lookfor == q.Pkgs[i].Name {
|
||||
return true
|
||||
}
|
||||
|
||||
if q.lookfor == q.Pkgs[j].Name {
|
||||
return false
|
||||
}
|
||||
|
||||
return lessRunes([]rune(q.Pkgs[i].Name), []rune(q.Pkgs[j].Name))
|
||||
}
|
||||
|
||||
func (q providers) Swap(i, j int) {
|
||||
q.Pkgs[i], q.Pkgs[j] = q.Pkgs[j], q.Pkgs[i]
|
||||
}
|
||||
|
||||
func splitDep(dep string) (string, string, string) {
|
||||
mod := ""
|
||||
|
||||
split := strings.FieldsFunc(dep, func(c rune) bool {
|
||||
match := c == '>' || c == '<' || c == '='
|
||||
|
||||
if match {
|
||||
mod += string(c)
|
||||
}
|
||||
|
||||
return match
|
||||
})
|
||||
|
||||
if len(split) == 0 {
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
if len(split) == 1 {
|
||||
return split[0], "", ""
|
||||
}
|
||||
|
||||
return split[0], mod, split[1]
|
||||
}
|
||||
|
||||
func pkgSatisfies(name, version, dep string) bool {
|
||||
depName, depMod, depVersion := splitDep(dep)
|
||||
|
||||
if depName != name {
|
||||
return false
|
||||
}
|
||||
|
||||
return verSatisfies(version, depMod, depVersion)
|
||||
}
|
||||
|
||||
func provideSatisfies(provide, dep string) bool {
|
||||
depName, depMod, depVersion := splitDep(dep)
|
||||
provideName, provideMod, provideVersion := splitDep(provide)
|
||||
|
||||
if provideName != depName {
|
||||
return false
|
||||
}
|
||||
|
||||
// Unversioned provieds can not satisfy a versioned dep
|
||||
if provideMod == "" && depMod != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return verSatisfies(provideVersion, depMod, depVersion)
|
||||
}
|
||||
|
||||
func verSatisfies(ver1, mod, ver2 string) bool {
|
||||
switch mod {
|
||||
case "=":
|
||||
return alpm.VerCmp(ver1, ver2) == 0
|
||||
case "<":
|
||||
return alpm.VerCmp(ver1, ver2) < 0
|
||||
case "<=":
|
||||
return alpm.VerCmp(ver1, ver2) <= 0
|
||||
case ">":
|
||||
return alpm.VerCmp(ver1, ver2) > 0
|
||||
case ">=":
|
||||
return alpm.VerCmp(ver1, ver2) >= 0
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
|
||||
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, provide := range pkg.Provides {
|
||||
if provideSatisfies(provide, dep) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func satisfiesRepo(dep string, pkg *alpm.Package) bool {
|
||||
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
|
||||
return true
|
||||
}
|
||||
|
||||
if pkg.Provides().ForEach(func(provide alpm.Depend) error {
|
||||
if provideSatisfies(provide.String(), dep) {
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
return nil
|
||||
}) != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
//split apart db/package to db and package
|
||||
func splitDbFromName(pkg string) (string, string) {
|
||||
split := strings.SplitN(pkg, "/", 2)
|
||||
|
||||
if len(split) == 2 {
|
||||
return split[0], split[1]
|
||||
}
|
||||
return "", split[0]
|
||||
}
|
||||
|
||||
func getBases(pkgs []*rpc.Pkg) []Base {
|
||||
basesMap := make(map[string]Base)
|
||||
for _, pkg := range pkgs {
|
||||
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
|
||||
}
|
||||
|
||||
bases := make([]Base, 0, len(basesMap))
|
||||
for _, base := range basesMap {
|
||||
bases = append(bases, base)
|
||||
}
|
||||
|
||||
return bases
|
||||
}
|
||||
|
||||
func isDevelName(name string) bool {
|
||||
for _, suffix := range []string{"git", "svn", "hg", "bzr", "nightly"} {
|
||||
if strings.HasSuffix(name, "-"+suffix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Contains(name, "-always-")
|
||||
}
|
283
depCheck.go
Normal file
283
depCheck.go
Normal file
@ -0,0 +1,283 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts mapStringSet) {
|
||||
for _, pkg := range dp.Aur {
|
||||
if pkg.Name == name {
|
||||
continue
|
||||
}
|
||||
|
||||
if satisfiesAur(conflict, pkg) {
|
||||
conflicts.Add(name, pkg.Name)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Repo {
|
||||
if pkg.Name() == name {
|
||||
continue
|
||||
}
|
||||
|
||||
if satisfiesRepo(conflict, pkg) {
|
||||
conflicts.Add(name, pkg.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts mapStringSet) {
|
||||
dp.LocalDb.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if satisfiesRepo(conflict, &pkg) {
|
||||
n := pkg.Name()
|
||||
if n != conflict {
|
||||
n += " (" + conflict + ")"
|
||||
}
|
||||
conflicts.Add(name, n)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts mapStringSet) {
|
||||
for _, pkg := range dp.Aur {
|
||||
if pkg.Name == name {
|
||||
continue
|
||||
}
|
||||
|
||||
if satisfiesAur(conflict, pkg) {
|
||||
if name != conflict {
|
||||
name += " (" + conflict + ")"
|
||||
}
|
||||
|
||||
conflicts.Add(pkg.Name, name)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Repo {
|
||||
if pkg.Name() == name {
|
||||
continue
|
||||
}
|
||||
|
||||
if satisfiesRepo(conflict, pkg) {
|
||||
if name != conflict {
|
||||
name += " (" + conflict + ")"
|
||||
}
|
||||
|
||||
conflicts.Add(pkg.Name(), name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *depPool) checkInnerConflicts(conflicts mapStringSet) {
|
||||
for _, pkg := range dp.Aur {
|
||||
for _, conflict := range pkg.Conflicts {
|
||||
dp.checkInnerConflict(pkg.Name, conflict, conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Repo {
|
||||
pkg.Conflicts().ForEach(func(conflict alpm.Depend) error {
|
||||
dp.checkInnerConflict(pkg.Name(), conflict.String(), conflicts)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *depPool) checkForwardConflicts(conflicts mapStringSet) {
|
||||
for _, pkg := range dp.Aur {
|
||||
for _, conflict := range pkg.Conflicts {
|
||||
dp.checkForwardConflict(pkg.Name, conflict, conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Repo {
|
||||
pkg.Conflicts().ForEach(func(conflict alpm.Depend) error {
|
||||
dp.checkForwardConflict(pkg.Name(), conflict.String(), conflicts)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *depPool) checkReverseConflicts(conflicts mapStringSet) {
|
||||
dp.LocalDb.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||
if dp.hasPackage(pkg.Name()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
pkg.Conflicts().ForEach(func(conflict alpm.Depend) error {
|
||||
dp.checkReverseConflict(pkg.Name(), conflict.String(), conflicts)
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (dp *depPool) CheckConflicts() (mapStringSet, error) {
|
||||
var wg sync.WaitGroup
|
||||
innerConflicts := make(mapStringSet)
|
||||
conflicts := make(mapStringSet)
|
||||
wg.Add(2)
|
||||
|
||||
fmt.Println(bold(cyan("::") + bold(" Checking for conflicts...")))
|
||||
go func() {
|
||||
dp.checkForwardConflicts(conflicts)
|
||||
dp.checkReverseConflicts(conflicts)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
fmt.Println(bold(cyan("::") + bold(" Checking for inner conflicts...")))
|
||||
go func() {
|
||||
dp.checkInnerConflicts(innerConflicts)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if len(innerConflicts) != 0 {
|
||||
fmt.Println()
|
||||
fmt.Println(bold(red(arrow)), bold("Inner conflicts found:"))
|
||||
|
||||
for name, pkgs := range innerConflicts {
|
||||
str := red(bold(smallArrow)) + " " + name + ":"
|
||||
for pkg := range pkgs {
|
||||
str += " " + cyan(pkg) + ","
|
||||
}
|
||||
str = strings.TrimSuffix(str, ",")
|
||||
|
||||
fmt.Println(str)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Unresolvable package conflicts, aborting")
|
||||
}
|
||||
|
||||
if len(conflicts) != 0 {
|
||||
fmt.Println()
|
||||
fmt.Println(bold(red(arrow)), bold("Package conflicts found:"))
|
||||
|
||||
if !config.UseAsk {
|
||||
fmt.Println(bold(red(arrow)), bold("You will have to confirm these when installing"))
|
||||
}
|
||||
|
||||
for name, pkgs := range conflicts {
|
||||
str := red(bold(smallArrow)) + " Installing " + cyan(name) + " will remove:"
|
||||
for pkg := range pkgs {
|
||||
str += " " + cyan(pkg) + ","
|
||||
}
|
||||
str = strings.TrimSuffix(str, ",")
|
||||
|
||||
fmt.Println(str)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
|
||||
if config.NoConfirm && !config.UseAsk {
|
||||
return nil, fmt.Errorf("Package conflicts can not be resolved with noconfirm, aborting")
|
||||
}
|
||||
}
|
||||
|
||||
return conflicts, nil
|
||||
}
|
||||
|
||||
type missing struct {
|
||||
Good stringSet
|
||||
Missing map[string][][]string
|
||||
}
|
||||
|
||||
func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
|
||||
if missing.Good.get(dep) {
|
||||
return
|
||||
}
|
||||
|
||||
if trees, ok := missing.Missing[dep]; ok {
|
||||
for _, tree := range trees {
|
||||
if stringSliceEqual(tree, stack) {
|
||||
return
|
||||
}
|
||||
}
|
||||
missing.Missing[dep] = append(missing.Missing[dep], stack)
|
||||
return
|
||||
}
|
||||
|
||||
aurPkg := dp.findSatisfierAur(dep)
|
||||
if aurPkg != nil {
|
||||
missing.Good.set(dep)
|
||||
for _, deps := range [3][]string{aurPkg.Depends, aurPkg.MakeDepends, aurPkg.CheckDepends} {
|
||||
for _, aurDep := range deps {
|
||||
if _, err := dp.LocalDb.PkgCache().FindSatisfier(aurDep); err == nil {
|
||||
missing.Good.set(aurDep)
|
||||
continue
|
||||
}
|
||||
|
||||
dp._checkMissing(aurDep, append(stack, aurPkg.Name), missing)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
repoPkg := dp.findSatisfierRepo(dep)
|
||||
if repoPkg != nil {
|
||||
missing.Good.set(dep)
|
||||
repoPkg.Depends().ForEach(func(repoDep alpm.Depend) error {
|
||||
if _, err := dp.LocalDb.PkgCache().FindSatisfier(repoDep.String()); err == nil {
|
||||
missing.Good.set(repoDep.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
dp._checkMissing(repoDep.String(), append(stack, repoPkg.Name()), missing)
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
missing.Missing[dep] = [][]string{stack}
|
||||
}
|
||||
|
||||
func (dp *depPool) CheckMissing() error {
|
||||
missing := &missing{
|
||||
make(stringSet),
|
||||
make(map[string][][]string),
|
||||
}
|
||||
|
||||
for _, target := range dp.Targets {
|
||||
dp._checkMissing(target.DepString(), make([]string, 0), missing)
|
||||
}
|
||||
|
||||
if len(missing.Missing) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Println(bold(red(arrow+" Error: ")) + "Could not find all required packages:")
|
||||
for dep, trees := range missing.Missing {
|
||||
for _, tree := range trees {
|
||||
|
||||
fmt.Print(" ", cyan(dep))
|
||||
|
||||
if len(tree) == 0 {
|
||||
fmt.Print(" (Target")
|
||||
} else {
|
||||
fmt.Print(" (Wanted by: ")
|
||||
for n := 0; n < len(tree)-1; n++ {
|
||||
fmt.Print(cyan(tree[n]), " -> ")
|
||||
}
|
||||
fmt.Print(cyan(tree[len(tree)-1]))
|
||||
}
|
||||
|
||||
fmt.Println(")")
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("")
|
||||
}
|
135
depOrder.go
Normal file
135
depOrder.go
Normal file
@ -0,0 +1,135 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
)
|
||||
|
||||
type Base []*rpc.Pkg
|
||||
|
||||
func (b Base) Pkgbase() string {
|
||||
return b[0].PackageBase
|
||||
}
|
||||
|
||||
func (b Base) Version() string {
|
||||
return b[0].Version
|
||||
}
|
||||
|
||||
func (b Base) URLPath() string {
|
||||
return b[0].URLPath
|
||||
}
|
||||
|
||||
type depOrder struct {
|
||||
Aur []Base
|
||||
Repo []*alpm.Package
|
||||
Runtime stringSet
|
||||
}
|
||||
|
||||
func makeDepOrder() *depOrder {
|
||||
return &depOrder{
|
||||
make([]Base, 0),
|
||||
make([]*alpm.Package, 0),
|
||||
make(stringSet),
|
||||
}
|
||||
}
|
||||
|
||||
func getDepOrder(dp *depPool) *depOrder {
|
||||
do := makeDepOrder()
|
||||
|
||||
for _, target := range dp.Targets {
|
||||
dep := target.DepString()
|
||||
aurPkg := dp.Aur[dep]
|
||||
if aurPkg != nil && pkgSatisfies(aurPkg.Name, aurPkg.Version, dep) {
|
||||
do.orderPkgAur(aurPkg, dp, true)
|
||||
}
|
||||
|
||||
aurPkg = dp.findSatisfierAur(dep)
|
||||
if aurPkg != nil {
|
||||
do.orderPkgAur(aurPkg, dp, true)
|
||||
}
|
||||
|
||||
repoPkg := dp.findSatisfierRepo(dep)
|
||||
if repoPkg != nil {
|
||||
do.orderPkgRepo(repoPkg, dp, true)
|
||||
}
|
||||
}
|
||||
|
||||
return do
|
||||
}
|
||||
|
||||
func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
|
||||
if runtime {
|
||||
do.Runtime.set(pkg.Name)
|
||||
}
|
||||
delete(dp.Aur, pkg.Name)
|
||||
|
||||
for i, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
||||
for _, dep := range deps {
|
||||
aurPkg := dp.findSatisfierAur(dep)
|
||||
if aurPkg != nil {
|
||||
do.orderPkgAur(aurPkg, dp, runtime && i == 0)
|
||||
}
|
||||
|
||||
repoPkg := dp.findSatisfierRepo(dep)
|
||||
if repoPkg != nil {
|
||||
do.orderPkgRepo(repoPkg, dp, runtime && i == 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, base := range do.Aur {
|
||||
if base.Pkgbase() == pkg.PackageBase {
|
||||
do.Aur[i] = append(base, pkg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
do.Aur = append(do.Aur, Base{pkg})
|
||||
}
|
||||
|
||||
func (do *depOrder) orderPkgRepo(pkg *alpm.Package, dp *depPool, runtime bool) {
|
||||
if runtime {
|
||||
do.Runtime.set(pkg.Name())
|
||||
}
|
||||
delete(dp.Repo, pkg.Name())
|
||||
|
||||
pkg.Depends().ForEach(func(dep alpm.Depend) (err error) {
|
||||
repoPkg := dp.findSatisfierRepo(dep.String())
|
||||
if repoPkg != nil {
|
||||
do.orderPkgRepo(repoPkg, dp, runtime)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
do.Repo = append(do.Repo, pkg)
|
||||
}
|
||||
|
||||
func (do *depOrder) HasMake() bool {
|
||||
lenAur := 0
|
||||
for _, base := range do.Aur {
|
||||
lenAur += len(base)
|
||||
}
|
||||
|
||||
return len(do.Runtime) != lenAur+len(do.Repo)
|
||||
}
|
||||
|
||||
func (do *depOrder) getMake() []string {
|
||||
makeOnly := make([]string, 0, len(do.Aur)+len(do.Repo)-len(do.Runtime))
|
||||
|
||||
for _, base := range do.Aur {
|
||||
for _, pkg := range base {
|
||||
if !do.Runtime.get(pkg.Name) {
|
||||
makeOnly = append(makeOnly, pkg.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range do.Repo {
|
||||
if !do.Runtime.get(pkg.Name()) {
|
||||
makeOnly = append(makeOnly, pkg.Name())
|
||||
}
|
||||
}
|
||||
|
||||
return makeOnly
|
||||
}
|
474
depPool.go
Normal file
474
depPool.go
Normal file
@ -0,0 +1,474 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
)
|
||||
|
||||
type target struct {
|
||||
Db string
|
||||
Name string
|
||||
Mod string
|
||||
Version string
|
||||
}
|
||||
|
||||
func toTarget(pkg string) target {
|
||||
db, dep := splitDbFromName(pkg)
|
||||
name, mod, version := splitDep(dep)
|
||||
|
||||
return target{
|
||||
db,
|
||||
name,
|
||||
mod,
|
||||
version,
|
||||
}
|
||||
}
|
||||
|
||||
func (t target) DepString() string {
|
||||
return t.Name + t.Mod + t.Version
|
||||
}
|
||||
|
||||
func (t target) String() string {
|
||||
if t.Db != "" {
|
||||
return t.Db + "/" + t.DepString()
|
||||
}
|
||||
|
||||
return t.DepString()
|
||||
}
|
||||
|
||||
type depPool struct {
|
||||
Targets []target
|
||||
Explicit stringSet
|
||||
Repo map[string]*alpm.Package
|
||||
Aur map[string]*rpc.Pkg
|
||||
AurCache map[string]*rpc.Pkg
|
||||
Groups []string
|
||||
LocalDb *alpm.Db
|
||||
SyncDb alpm.DbList
|
||||
Warnings *aurWarnings
|
||||
}
|
||||
|
||||
func makeDepPool() (*depPool, error) {
|
||||
localDb, err := alpmHandle.LocalDb()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
syncDb, err := alpmHandle.SyncDbs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dp := &depPool{
|
||||
make([]target, 0),
|
||||
make(stringSet),
|
||||
make(map[string]*alpm.Package),
|
||||
make(map[string]*rpc.Pkg),
|
||||
make(map[string]*rpc.Pkg),
|
||||
make([]string, 0),
|
||||
localDb,
|
||||
syncDb,
|
||||
nil,
|
||||
}
|
||||
|
||||
return dp, nil
|
||||
}
|
||||
|
||||
// Includes db/ prefixes and group installs
|
||||
func (dp *depPool) ResolveTargets(pkgs []string) error {
|
||||
// RPC requests are slow
|
||||
// Combine as many AUR package requests as possible into a single RPC
|
||||
// call
|
||||
aurTargets := make(stringSet)
|
||||
|
||||
pkgs = removeInvalidTargets(pkgs)
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
var err error
|
||||
target := toTarget(pkg)
|
||||
|
||||
// skip targets already satisfied
|
||||
// even if the user enters db/pkg and aur/pkg the latter will
|
||||
// still get skipped even if it's from a different database to
|
||||
// the one specified
|
||||
// this is how pacman behaves
|
||||
if dp.hasPackage(target.DepString()) {
|
||||
continue
|
||||
}
|
||||
|
||||
var foundPkg *alpm.Package
|
||||
var singleDb *alpm.Db
|
||||
|
||||
// aur/ prefix means we only check the aur
|
||||
if target.Db == "aur" || mode == ModeAUR {
|
||||
dp.Targets = append(dp.Targets, target)
|
||||
aurTargets.set(target.DepString())
|
||||
continue
|
||||
}
|
||||
|
||||
// If there'ss a different priefix only look in that repo
|
||||
if target.Db != "" {
|
||||
singleDb, err = alpmHandle.SyncDbByName(target.Db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
foundPkg, err = singleDb.PkgCache().FindSatisfier(target.DepString())
|
||||
//otherwise find it in any repo
|
||||
} else {
|
||||
foundPkg, err = dp.SyncDb.FindSatisfier(target.DepString())
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
dp.Targets = append(dp.Targets, target)
|
||||
dp.Explicit.set(foundPkg.Name())
|
||||
dp.ResolveRepoDependency(foundPkg)
|
||||
continue
|
||||
} else {
|
||||
//check for groups
|
||||
//currently we don't resolve the packages in a group
|
||||
//only check if the group exists
|
||||
//would be better to check the groups from singleDb if
|
||||
//the user specified a db but there's no easy way to do
|
||||
//it without making alpm_lists so don't bother for now
|
||||
//db/group is probably a rare use case
|
||||
group, err := dp.SyncDb.PkgCachebyGroup(target.Name)
|
||||
if err == nil {
|
||||
dp.Groups = append(dp.Groups, target.String())
|
||||
group.ForEach(func(pkg alpm.Package) error {
|
||||
dp.Explicit.set(pkg.Name())
|
||||
return nil
|
||||
})
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
//if there was no db prefix check the aur
|
||||
if target.Db == "" {
|
||||
aurTargets.set(target.DepString())
|
||||
}
|
||||
|
||||
dp.Targets = append(dp.Targets, target)
|
||||
}
|
||||
|
||||
if len(aurTargets) > 0 && (mode == ModeAny || mode == ModeAUR) {
|
||||
return dp.resolveAURPackages(aurTargets, true)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Pseudo provides finder.
|
||||
// Try to find provides by performing a search of the package name
|
||||
// This effectively performs -Ss on each package
|
||||
// then runs -Si on each result to cache the information.
|
||||
//
|
||||
// For example if you were to -S yay then yay -Ss would give:
|
||||
// yay-git yay-bin yay realyog pacui pacui-git ruby-yard
|
||||
// These packages will all be added to the cache in case they are needed later
|
||||
// Ofcouse only the first three packages provide yay, the rest are just false
|
||||
// positives.
|
||||
//
|
||||
// This method increases dependency resolve time
|
||||
func (dp *depPool) findProvides(pkgs stringSet) error {
|
||||
var mux sync.Mutex
|
||||
var wg sync.WaitGroup
|
||||
|
||||
doSearch := func(pkg string) {
|
||||
defer wg.Done()
|
||||
var err error
|
||||
var results []rpc.Pkg
|
||||
|
||||
// Hack for a bigger search result, if the user wants
|
||||
// java-envronment we can search for just java instead and get
|
||||
// more hits.
|
||||
words := strings.Split(pkg, "-")
|
||||
|
||||
for i := range words {
|
||||
results, err = rpc.SearchByNameDesc(strings.Join(words[:i+1], "-"))
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
mux.Lock()
|
||||
if _, ok := dp.AurCache[result.Name]; !ok {
|
||||
pkgs.set(result.Name)
|
||||
}
|
||||
mux.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
for pkg := range pkgs {
|
||||
if _, err := dp.LocalDb.PkgByName(pkg); err == nil {
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go doSearch(pkg)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *depPool) cacheAURPackages(_pkgs stringSet) error {
|
||||
pkgs := _pkgs.copy()
|
||||
query := make([]string, 0)
|
||||
|
||||
for pkg := range pkgs {
|
||||
if _, ok := dp.AurCache[pkg]; ok {
|
||||
pkgs.remove(pkg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if config.Provides {
|
||||
err := dp.findProvides(pkgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for pkg := range pkgs {
|
||||
if _, ok := dp.AurCache[pkg]; !ok {
|
||||
name, _, _ := splitDep(pkg)
|
||||
query = append(query, name)
|
||||
}
|
||||
}
|
||||
|
||||
info, err := aurInfo(query, dp.Warnings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pkg := range info {
|
||||
// Dump everything in cache just in case we need it later
|
||||
dp.AurCache[pkg.Name] = pkg
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *depPool) resolveAURPackages(pkgs stringSet, explicit bool) error {
|
||||
newPackages := make(stringSet)
|
||||
newAURPackages := make(stringSet)
|
||||
|
||||
err := dp.cacheAURPackages(pkgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for name := range pkgs {
|
||||
_, ok := dp.Aur[name]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
|
||||
pkg := dp.findSatisfierAurCache(name)
|
||||
if pkg == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if explicit {
|
||||
dp.Explicit.set(pkg.Name)
|
||||
}
|
||||
dp.Aur[pkg.Name] = pkg
|
||||
|
||||
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
||||
for _, dep := range deps {
|
||||
newPackages.set(dep)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for dep := range newPackages {
|
||||
if dp.hasSatisfier(dep) {
|
||||
continue
|
||||
}
|
||||
|
||||
_, isInstalled := dp.LocalDb.PkgCache().FindSatisfier(dep) //has satisfier installed: skip
|
||||
repoPkg, inRepos := dp.SyncDb.FindSatisfier(dep) //has satisfier in repo: fetch it
|
||||
if isInstalled == nil && (config.ReBuild != "tree" || inRepos == nil) {
|
||||
continue
|
||||
}
|
||||
|
||||
if inRepos == nil {
|
||||
dp.ResolveRepoDependency(repoPkg)
|
||||
continue
|
||||
}
|
||||
|
||||
//assume it's in the aur
|
||||
//ditch the versioning because the RPC can't handle it
|
||||
newAURPackages.set(dep)
|
||||
|
||||
}
|
||||
|
||||
err = dp.resolveAURPackages(newAURPackages, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func (dp *depPool) ResolveRepoDependency(pkg *alpm.Package) {
|
||||
dp.Repo[pkg.Name()] = pkg
|
||||
|
||||
pkg.Depends().ForEach(func(dep alpm.Depend) (err error) {
|
||||
//have satisfier in dep tree: skip
|
||||
if dp.hasSatisfier(dep.String()) {
|
||||
return
|
||||
}
|
||||
|
||||
//has satisfier installed: skip
|
||||
_, isInstalled := dp.LocalDb.PkgCache().FindSatisfier(dep.String())
|
||||
if isInstalled == nil {
|
||||
return
|
||||
}
|
||||
|
||||
//has satisfier in repo: fetch it
|
||||
repoPkg, inRepos := dp.SyncDb.FindSatisfier(dep.String())
|
||||
if inRepos != nil {
|
||||
return
|
||||
}
|
||||
|
||||
dp.ResolveRepoDependency(repoPkg)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func getDepPool(pkgs []string, warnings *aurWarnings) (*depPool, error) {
|
||||
dp, err := makeDepPool()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dp.Warnings = warnings
|
||||
err = dp.ResolveTargets(pkgs)
|
||||
|
||||
return dp, err
|
||||
}
|
||||
|
||||
func (dp *depPool) findSatisfierAur(dep string) *rpc.Pkg {
|
||||
for _, pkg := range dp.Aur {
|
||||
if satisfiesAur(dep, pkg) {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// This is mostly used to promote packages from the cache
|
||||
// to the Install list
|
||||
// Provide a pacman style provider menu if there's more than one candidate
|
||||
// This acts slightly differently from Pacman, It will give
|
||||
// a menu even if a package with a matching name exists. I believe this
|
||||
// method is better because most of the time you are choosing between
|
||||
// foo and foo-git.
|
||||
// Using Pacman's ways trying to install foo would never give you
|
||||
// a menu.
|
||||
// TODO: maybe intermix repo providers in the menu
|
||||
func (dp *depPool) findSatisfierAurCache(dep string) *rpc.Pkg {
|
||||
depName, _, _ := splitDep(dep)
|
||||
seen := make(stringSet)
|
||||
providers := makeProviders(depName)
|
||||
|
||||
if _, err := dp.LocalDb.PkgByName(depName); err == nil {
|
||||
if pkg, ok := dp.AurCache[dep]; ok && pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
return pkg
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if cmdArgs.op == "Y" || cmdArgs.op == "yay" {
|
||||
for _, pkg := range dp.AurCache {
|
||||
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
for _, target := range dp.Targets {
|
||||
if target.Name == pkg.Name {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.AurCache {
|
||||
if seen.get(pkg.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
providers.Pkgs = append(providers.Pkgs, pkg)
|
||||
seen.set(pkg.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, provide := range pkg.Provides {
|
||||
if provideSatisfies(provide, dep) {
|
||||
providers.Pkgs = append(providers.Pkgs, pkg)
|
||||
seen.set(pkg.Name)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if providers.Len() == 1 {
|
||||
return providers.Pkgs[0]
|
||||
}
|
||||
|
||||
if providers.Len() > 1 {
|
||||
sort.Sort(providers)
|
||||
return providerMenu(dep, providers)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *depPool) findSatisfierRepo(dep string) *alpm.Package {
|
||||
for _, pkg := range dp.Repo {
|
||||
if satisfiesRepo(dep, pkg) {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *depPool) hasSatisfier(dep string) bool {
|
||||
return dp.findSatisfierRepo(dep) != nil || dp.findSatisfierAur(dep) != nil
|
||||
}
|
||||
|
||||
func (dp *depPool) hasPackage(name string) bool {
|
||||
for _, pkg := range dp.Repo {
|
||||
if pkg.Name() == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Aur {
|
||||
if pkg.Name == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Groups {
|
||||
if pkg == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
262
doc/yay.8
262
doc/yay.8
@ -1,4 +1,5 @@
|
||||
.TH "YAY" "8" "2019\-10\-21" "Yay v12.0+" "Yay Manual"
|
||||
'\ t
|
||||
.TH "YAY" "8" "2018\-07\-01" "Yay v8.972+" "Yay Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH NAME
|
||||
@ -19,15 +20,10 @@ This manpage only covers options unique to Yay. For other options see
|
||||
\fBpacman(8)\fR.
|
||||
|
||||
.SH YAY OPERATIONS
|
||||
|
||||
.TP
|
||||
.B \-Y, \-\-yay
|
||||
Perform yay specific operations. This is the default if no other operation is
|
||||
selected and targets are defined.
|
||||
|
||||
.TP
|
||||
.B \-B, \-\-build
|
||||
Build a PKGBUILD in a given directory.
|
||||
selected.
|
||||
|
||||
.TP
|
||||
.B \-P, \-\-show
|
||||
@ -35,27 +31,25 @@ Perform yay specific print operations.
|
||||
|
||||
.TP
|
||||
.B \-G, \-\-getpkgbuild
|
||||
Downloads PKGBUILD from ABS or AUR. The ABS can only be used for Arch Linux repositories.
|
||||
|
||||
.TP
|
||||
.B \-W, \-\-web
|
||||
Web related operations such as voting for AUR packages.
|
||||
Downloads PKGBUILD from ABS or AUR. ABS pkgbuilds are always downloaded using
|
||||
tarballs and taken from trunk. The ABS can only be used for Arch Linux repositories
|
||||
|
||||
.RE
|
||||
If no operation is specified 'yay \-Syu' will be performed
|
||||
If no arguments are provided 'yay \-Syu' will be performed.
|
||||
|
||||
If no operation is specified and targets are provided \-Y will be assumed
|
||||
If no operation is selected \-Y will be assumed.
|
||||
|
||||
.SH EXTENDED PACMAN OPERATIONS
|
||||
.TP
|
||||
.B \-S, \-Si, \-Sl, \-Ss, \-Su, \-Sc, \-Qu
|
||||
.B \-S, \-Si, \-Ss, \-Su, \-Sc, \-Qu
|
||||
These operations are extended to support both AUR and repo packages.
|
||||
|
||||
.TP
|
||||
.B \-Sc
|
||||
Yay will also clean cached AUR package and any untracked Files in the
|
||||
cache. Cleaning untracked files will wipe any downloaded sources or
|
||||
built packages but will keep already downloaded vcs sources.
|
||||
cache. Untracked files cleaning only works for packages downloaded
|
||||
using gitclone. Cleaning untracked files will wipe any downloaded
|
||||
sources or built packages but will keep already downloaded vcs sources.
|
||||
|
||||
.TP
|
||||
.B \-R
|
||||
@ -63,7 +57,7 @@ Yay will also remove cached data about devel packages.
|
||||
|
||||
.SH NEW OPTIONS
|
||||
.TP
|
||||
.B \-N, \-\-repo
|
||||
.B \-\-repo
|
||||
Assume all targets are from the repositories. Additionally Actions such as
|
||||
sysupgrade will only act on repository packages.
|
||||
|
||||
@ -72,7 +66,7 @@ sysupgrade will only act on repository packages.
|
||||
Assume all targets are from the AUR. Additionally Actions such as
|
||||
sysupgrade will only act on AUR packages.
|
||||
|
||||
Note that dependency resolving will still act normally and include repository
|
||||
Note that dependency resolving will still act as normal and include repository
|
||||
packages.
|
||||
|
||||
.SH YAY OPTIONS (APPLY TO \-Y AND \-\-YAY)
|
||||
@ -82,10 +76,6 @@ packages.
|
||||
Displays a list of packages matching the search terms and prompts the user on
|
||||
which packages to install (yogurt mode).
|
||||
|
||||
The first search term is used to query the different sources and
|
||||
the following search terms are used to narrow the search results
|
||||
through exact matching.
|
||||
|
||||
.TP
|
||||
.B \-\-gendb
|
||||
Generate development package database. Tracks the latest commit for each
|
||||
@ -97,16 +87,16 @@ used when migrating to Yay from another AUR helper.
|
||||
.B \-c, \-\-clean
|
||||
Remove unneeded dependencies.
|
||||
|
||||
.TP
|
||||
.B \-cc
|
||||
Remove unneeded dependencies, including packages optionally required by any other package.
|
||||
|
||||
.SH SHOW OPTIONS (APPLY TO \-P AND \-\-show)
|
||||
.SH SHOW OPTIONS (APPLY TO \-P AND \-\-SHOW)
|
||||
.TP
|
||||
.B \-c, \-\-complete
|
||||
Print a list of all AUR and repo packages. This allows shell completion
|
||||
Print a list of all AUR and repo packages. This is to allow shell completion
|
||||
and is not intended to be used directly by the user.
|
||||
|
||||
.TP
|
||||
.B \-f, \-\-fish
|
||||
During complete adjust the output for the fish shell.
|
||||
|
||||
.TP
|
||||
.B \-d, \-\-defaultconfig
|
||||
Print default yay configuration.
|
||||
@ -115,11 +105,19 @@ Print default yay configuration.
|
||||
.B \-g, \-\-currentconfig
|
||||
Print current yay configuration.
|
||||
|
||||
.TP
|
||||
.B \-n, \-\-numberupgrades
|
||||
Deprecated, use \fByay -Qu\fR and \fBwc -l\fR instead\%.
|
||||
|
||||
.TP
|
||||
.B \-s, \-\-stats
|
||||
Displays information about installed packages and system health. If there are
|
||||
orphaned, or out\-of\-date packages, or packages that no longer exist on the
|
||||
AUR; warnings will be displayed.
|
||||
orphaned, out\-of\-date or packages that no longer exist on the AUR warnings will
|
||||
be displayed.
|
||||
|
||||
.TP
|
||||
.B \-u, \-\-upgrades
|
||||
Deprecated, use \fByay -Qu\fR instead\%.
|
||||
|
||||
.TP
|
||||
.B \-w, \-\-news
|
||||
@ -131,34 +129,12 @@ available news.
|
||||
.B \-q, \-\-quiet
|
||||
Only show titles when printing news.
|
||||
|
||||
.SH BUILD OPTIONS (APPLY TO \-B AND \-\-build)
|
||||
.TP
|
||||
.B \-i, \-\-install
|
||||
Build and install a PKGBUILD in a given directory
|
||||
|
||||
.SH GETPKGBUILD OPTIONS (APPLY TO \-G AND \-\-getpkgbuild)
|
||||
.SH GETPKGBUILD OPTIONS (APPLY TO \-G AND \-\-GETPKGBUILD)
|
||||
.TP
|
||||
.B \-f, \-\-force
|
||||
Force download for ABS packages that already exist in the current directory. This
|
||||
ensures directories are not accidentally overwritten.
|
||||
|
||||
.TP
|
||||
.B \-p, \-\-print
|
||||
Prints the PKGBUILD of the given packages to stdout.
|
||||
|
||||
.SH WEB OPTIONS (APPLY TO \-W AND \-\-web)
|
||||
|
||||
.TP
|
||||
Web related operations such as voting for AUR packages.
|
||||
Requires setting AUR_USERNAME and AUR_PASSWORD environment variables.
|
||||
|
||||
.TP
|
||||
.B \-u, \-\-unvote
|
||||
Remove vote from AUR package(s)
|
||||
|
||||
.TP
|
||||
.B \-v, \-\-vote
|
||||
Vote for AUR package(s)
|
||||
Force download for packages that already exist in the current directory. This
|
||||
is to ensure directories are not accidentally overwritten. This option is not
|
||||
needed for git based downloads as \fBgit pull\fR already has saftey mechanisms.
|
||||
|
||||
.SH PERMANENT CONFIGURATION SETTINGS
|
||||
.TP
|
||||
@ -169,28 +145,25 @@ file.
|
||||
|
||||
.TP
|
||||
.B \-\-aururl
|
||||
Set an alternative AUR URL.
|
||||
|
||||
.TP
|
||||
.B \-\-aurrpcurl
|
||||
Set an alternative URL for the AUR /rpc endpoint.
|
||||
Set an alternative AUR URL. This is mostly useful for users in china who wish
|
||||
to use https://aur.tuna.tsinghua.edu.cn/.
|
||||
|
||||
.TP
|
||||
.B \-\-builddir <dir>
|
||||
Directory to use for Building AUR Packages. This directory is also used as
|
||||
the AUR cache when deciding if Yay should skip builds.
|
||||
the AUR cache when deciding if Yay should should skip builds.
|
||||
|
||||
.TP
|
||||
.B \-\-editor <command>
|
||||
Editor to use when editing PKGBUILDs. If this is not set the \fBVISUAL\fR
|
||||
environment variable will be checked, followed by \fBEDITOR\fR. If none of
|
||||
Editor to use when editing PKGBUILDs. If this is not set the \fBEDITOR\fR
|
||||
environment variable will be checked, followed by \fBVISUAL\fR. If none of
|
||||
these are set Yay will prompt the user for an editor.
|
||||
|
||||
.TP
|
||||
.B \-\-editorflags <flags>
|
||||
Passes arguments to the editor. These flags get passed to every instance where
|
||||
the editor is called by Yay. Arguments are split on whitespace before being
|
||||
passed to the editor. Multiple arguments may be passed by supplying a space
|
||||
passed to gpg. Multiple arguments may be passed by supplying a space
|
||||
separated list that is quoted by the shell.
|
||||
|
||||
.TP
|
||||
@ -248,27 +221,23 @@ cache to never be refreshed.
|
||||
.B \-\-sortby <votes|popularity|id|baseid|name|base|submitted|modified>
|
||||
Sort AUR results by a specific field during search.
|
||||
|
||||
.TP
|
||||
.B \-\-searchby <name|name-desc|maintainer|depends|checkdepends|makedepends|optdepends|provides|conflicts|replaces|groups|keywords|comaintainers>
|
||||
Search for AUR packages by querying the specified field.
|
||||
|
||||
.TP
|
||||
.B \-\-answerclean <All|None|Installed|NotInstalled|...>
|
||||
Set a predetermined answer for the clean build menu question. This answer
|
||||
will be used instead of reading from standard input but will be parsed exactly
|
||||
the same.
|
||||
will be used instead of reading from standard input but will be treated exactly
|
||||
the same when parsed.
|
||||
|
||||
.TP
|
||||
.B \-\-answerdiff <All|None|Installed|NotInstalled|...>
|
||||
Set a predetermined answer for the edit diff menu question. This answer
|
||||
will be used instead of reading from standard input but will be parsed exactly
|
||||
the same.
|
||||
Set a predetermined answer for the edit diff menu question. This answer
|
||||
will be used instead of reading from standard input but will be treated exactly
|
||||
the same when parsed.
|
||||
|
||||
.TP
|
||||
.B \-\-answeredit <All|None|Installed|NotInstalled|...>
|
||||
Set a predetermined answer for the edit pkgbuild menu question. This answer
|
||||
will be used instead of reading from standard input but will be parsed exactly
|
||||
the same.
|
||||
will be used instead of reading from standard input but will be treated exactly
|
||||
the same when parsed.
|
||||
|
||||
.TP
|
||||
.B \-\-answerupgrade <Repo|^Repo|None|...>
|
||||
@ -297,9 +266,6 @@ Unset the answer for the upgrade menu.
|
||||
Show the clean menu. This menu gives you the chance to fully delete the
|
||||
downloaded build files from Yay's cache before redownloading a fresh copy.
|
||||
|
||||
If 'cleanmenu' is enabled in the configuration file, you can temporarily disable it by
|
||||
using '--cleanmenu=false' on the command line
|
||||
|
||||
.TP
|
||||
.B \-\-diffmenu
|
||||
Show the diff menu. This menu gives you the option to view diffs from
|
||||
@ -318,12 +284,35 @@ before building.
|
||||
recommended to edit pkgbuild variables unless you know what you are doing.
|
||||
|
||||
.TP
|
||||
.B \-\-askremovemake
|
||||
Ask to remove makedepends after installing packages.
|
||||
.B \-\-upgrademenu
|
||||
Show a detailed list of updates in a similar format to VerbosePkgLists.
|
||||
Upgrades can also be skipped using numbers, number ranges or repo names.
|
||||
Additionally ^ can be used to invert the selection.
|
||||
|
||||
\fBWarning\fR: It is not recommended to skip updates from the repositories as
|
||||
this can lead to partial upgrades. This feature is intended to easily skip AUR
|
||||
updates on the fly that may be broken or have a long compile time. Ultimately
|
||||
it is up to the user what upgrades they skip.
|
||||
|
||||
.TP
|
||||
.B \-\-askyesremovemake
|
||||
Ask to remove makedepends after installing packages(with "Y" as default).
|
||||
.B \-\-nocleanmenu
|
||||
Do not show the clean menu.
|
||||
|
||||
.TP
|
||||
.B \-\-nodiffmenu
|
||||
Do not show the diff menu.
|
||||
|
||||
.TP
|
||||
.B \-\-noeditmenu
|
||||
Do not show the edit menu.
|
||||
|
||||
.TP
|
||||
.B \-\-noupgrademenu
|
||||
Do not show the upgrade menu.
|
||||
|
||||
.TP
|
||||
.B \-\-askremovemake
|
||||
Ask to remove makedepends after installing packages.
|
||||
|
||||
.TP
|
||||
.B \-\-removemake
|
||||
@ -341,16 +330,6 @@ Display repository packages first and then AUR packages.
|
||||
.B \-\-bottomup
|
||||
Show AUR packages first and then repository packages.
|
||||
|
||||
.TP
|
||||
.B \-\-singlelineresults
|
||||
Override pacman's usual double-line search result format and list each result
|
||||
on its own line.
|
||||
|
||||
.TP
|
||||
.B \-\-doublelineresults
|
||||
Follow pacman's double-line search result format and list each result using
|
||||
two lines.
|
||||
|
||||
.TP
|
||||
.B \-\-devel
|
||||
During sysupgrade also check AUR development packages for updates. Currently
|
||||
@ -363,20 +342,29 @@ checked almost instantly and not require the original pkgbuild to be downloaded.
|
||||
The slower pacaur-like devel checks can be implemented manually by piping
|
||||
a list of packages into yay (see \fBexamples\fR).
|
||||
|
||||
If 'devel' is enabled in the configuration file, you can temporarily disable it by
|
||||
using '--devel=false' on the command line
|
||||
.TP
|
||||
.B \-\-nodevel
|
||||
Do not check for development packages updates during sysupgrade.
|
||||
|
||||
.TP
|
||||
.B \-\-cleanafter
|
||||
Remove untracked files after installation.
|
||||
|
||||
Untracked files are removed with the exception of directories.
|
||||
This allows VCS packages to easily pull an update
|
||||
instead of having to reclone the entire repo.
|
||||
.B \-\-gitclone
|
||||
Use git to download and update PKGBUILDs. PKGBUILDs previously downloaded
|
||||
using tarball will continue to use tarballs until the package is clean
|
||||
built. Similarly, PKGBUILDs managed with git will continue to use git until
|
||||
the package is clean built..
|
||||
|
||||
.TP
|
||||
.B \-\-keepsrc
|
||||
Keep pkg/ and src/ after building packages
|
||||
.B \-\-nogitclone
|
||||
Download and update PKGBUILDs using tarballs. The above conditions about
|
||||
previously installed packages still apply.
|
||||
|
||||
.TP
|
||||
.B \-\-afterclean
|
||||
Remove package sources after successful Install.
|
||||
|
||||
.TP
|
||||
.B \-\-noafterclean
|
||||
Do not remove package sources after successful Install.
|
||||
|
||||
.TP
|
||||
.B \-\-timeupdate
|
||||
@ -384,8 +372,8 @@ During sysupgrade also compare the build time of installed packages against
|
||||
the last modification time of each package's AUR page.
|
||||
|
||||
.TP
|
||||
.B \-\-separatesources
|
||||
Separate query results by source, AUR and sync
|
||||
.B \-\-notimeupdate
|
||||
Do not consider build times during sysupgrade.
|
||||
|
||||
.TP
|
||||
.B \-\-redownload
|
||||
@ -407,11 +395,22 @@ Look for matching providers when searching for AUR packages. When multiple
|
||||
providers are found a menu will appear prompting you to pick one. This
|
||||
increases dependency resolve time although this should not be noticeable.
|
||||
|
||||
.TP
|
||||
.B \-\-noprovides
|
||||
Do not look for matching providers when searching for AUR packages. If
|
||||
multiple providers happen to be found the menu will still appear.
|
||||
|
||||
.TP
|
||||
.B \-\-pgpfetch
|
||||
Prompt to import unknown PGP keys from the \fBvalidpgpkeys\fR field of each
|
||||
PKGBUILD.
|
||||
|
||||
.TP
|
||||
.B \-\-nopgpfetch
|
||||
Do not prompt to import unknown PGP keys. This is likely to cause a build
|
||||
failure unless using options such as \fB\-\-skippgpcheck\fR or a customized
|
||||
gpg config\%.
|
||||
|
||||
.TP
|
||||
.B \-\-useask
|
||||
Use pacman's --ask flag to automatically confirm package conflicts. Yay lists
|
||||
@ -419,6 +418,11 @@ conflicts ahead of time. It is possible that Yay does not detect
|
||||
a conflict, causing a package to be removed without the user's confirmation.
|
||||
However, this is very unlikely.
|
||||
|
||||
.TP
|
||||
.B \-\-nouseask
|
||||
Manually resolve package conflicts during the install. Packages which do not
|
||||
conflict will not need to be confined manually.
|
||||
|
||||
.TP
|
||||
.B \-\-combinedupgrade
|
||||
During sysupgrade, Yay will first perform a refresh, then show
|
||||
@ -431,11 +435,10 @@ the user's responsibility to either resolve the reason Yay exited or run
|
||||
a sysupgrade through pacman directly.
|
||||
|
||||
.TP
|
||||
.B \-\-batchinstall
|
||||
When building and installing AUR packages instead of installing each package
|
||||
after building, queue each package for install. Then once either all packages
|
||||
are built or a package in the build queue is needed as a dependency to build
|
||||
another package, install all the packages in the install queue.
|
||||
.B \-\-nocombinedupgrade
|
||||
During sysupgrade, Pacman \-Syu will be called, then the AUR upgrade will
|
||||
start. This means the upgrade menu and pkgbuild review will be performed
|
||||
after the sysupgrade has finished.
|
||||
|
||||
.TP
|
||||
.B \-\-rebuild
|
||||
@ -472,24 +475,15 @@ gpg is called by Yay. Arguments are split on whitespace before being
|
||||
passed to gpg. Multiple arguments may be passed by supplying a space
|
||||
separated list that is quoted by the shell.
|
||||
|
||||
.TP
|
||||
.B \-\-sudo <command>
|
||||
The command to use for \fBsudo\fR calls. This can be a command in
|
||||
\fBPATH\fR or an absolute path to the file.
|
||||
The sudoloop is not guaranteed to work with a custom \fBsudo\fR command.
|
||||
|
||||
.TP
|
||||
.B \-\-sudoflags <flags>
|
||||
Passes arguments to sudo. These flags get passed to every instance where
|
||||
sudo is called by Yay. Arguments are split on whitespace before being
|
||||
passed to sudo. Multiple arguments may be passed by supplying a space
|
||||
separated list that is quoted by the shell.
|
||||
|
||||
.TP
|
||||
.B \-\-sudoloop
|
||||
Loop sudo calls in the background to prevent sudo from timing out during long
|
||||
builds.
|
||||
|
||||
.TP
|
||||
.B \-\-nosudoloop
|
||||
Do not loop sudo calls in the background.
|
||||
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
yay \fIfoo\fR
|
||||
@ -531,22 +525,10 @@ Shows statistics for installed packages and system health.
|
||||
pacman -Qmq | grep -Ee '-(cvs|svn|git|hg|bzr|darcs)$' | yay -S --needed -
|
||||
pacaur-like devel check.
|
||||
|
||||
.SH ENVIRONMENT VARIABLES
|
||||
.TP
|
||||
.B AURDEST
|
||||
Can be set to configure the build directory.
|
||||
|
||||
Overridden by \-\-builddir.
|
||||
|
||||
.TP
|
||||
.B VISUAL, EDITOR
|
||||
When editor is not configured, use these variables to pick what editor
|
||||
to use when editing PKGBUILDS.
|
||||
|
||||
.SH FILES
|
||||
.TP
|
||||
.B CONFIG DIRECTORY
|
||||
The config directory is \fI$XDG_CONFIG_HOME/yay/\fR. If
|
||||
The config directory is \fI$XDG_CONFIG_HOME/yay/\fR. if
|
||||
\fB$XDG_CONFIG_HOME\fR is unset, the config directory will fall back to
|
||||
\fI$HOME/.config/yay\fR.
|
||||
|
||||
@ -556,7 +538,7 @@ mentioned in \fBPERMANENT CONFIGURATION SETTINGS\fR.
|
||||
|
||||
.TP
|
||||
.B CACHE DIRECTORY
|
||||
The cache directory is \fI$XDG_CACHE_HOME/yay/\fR. If
|
||||
The cache directory is \fI$XDG_CACHE_HOME/yay/\fR. if
|
||||
\fB$XDG_CACHE_HOME\fR is unset, the cache directory will fall back to
|
||||
\fI$HOME/.cache/yay\fR.
|
||||
|
||||
@ -594,6 +576,6 @@ See the arch wiki at https://wiki.archlinux.org/index.php/Arch_User_Repository f
|
||||
Please report bugs to our GitHub page https://github.com/Jguer/yay
|
||||
|
||||
.SH AUTHORS
|
||||
Jguer <joguer@proton.me>
|
||||
Jguer <joaogg3@gmail.com>
|
||||
.br
|
||||
Morgan <morganamilo@archlinux.org>
|
||||
Anna <morganamilo@gmail.com>
|
||||
|
302
download.go
Normal file
302
download.go
Normal file
@ -0,0 +1,302 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
// Decide what download method to use:
|
||||
// Use the config option when the destination does not already exits
|
||||
// If .git exists in the destination uer git
|
||||
// Otherwise use a tarrball
|
||||
func shouldUseGit(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return config.GitClone
|
||||
}
|
||||
|
||||
_, err = os.Stat(filepath.Join(path, ".git"))
|
||||
return err == nil || os.IsExist(err)
|
||||
}
|
||||
|
||||
func downloadFile(path string, url string) (err error) {
|
||||
// Create the file
|
||||
out, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// Get the data
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Writer the body to file
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
return err
|
||||
}
|
||||
|
||||
func gitHasDiff(path string, name string) (bool, error) {
|
||||
stdout, stderr, err := capture(passToGit(filepath.Join(path, name), "rev-parse", "HEAD", "HEAD@{upstream}"))
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%s%s", stderr, err)
|
||||
}
|
||||
|
||||
lines := strings.Split(stdout, "\n")
|
||||
head := lines[0]
|
||||
upstream := lines[1]
|
||||
|
||||
return head != upstream, nil
|
||||
}
|
||||
|
||||
func gitDownload(url string, path string, name string) (bool, error) {
|
||||
_, err := os.Stat(filepath.Join(path, name, ".git"))
|
||||
if os.IsNotExist(err) {
|
||||
cmd := passToGit(path, "clone", "--no-progress", url, name)
|
||||
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
|
||||
_, stderr, err := capture(cmd)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error cloning %s: %s", name, stderr)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("error reading %s", filepath.Join(path, name, ".git"))
|
||||
}
|
||||
|
||||
cmd := passToGit(filepath.Join(path, name), "fetch")
|
||||
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
|
||||
_, stderr, err := capture(cmd)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error fetching %s: %s", name, stderr)
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func gitMerge(path string, name string) error {
|
||||
_, stderr, err := capture(passToGit(filepath.Join(path, name), "reset", "--hard", "HEAD"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error resetting %s: %s", name, stderr)
|
||||
}
|
||||
|
||||
_, stderr, err = capture(passToGit(filepath.Join(path, name), "merge", "--no-edit", "--ff"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error merging %s: %s", name, stderr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gitDiff(path string, name string) error {
|
||||
err := show(passToGit(filepath.Join(path, name), "diff", "HEAD..HEAD@{upstream}"))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DownloadAndUnpack downloads url tgz and extracts to path.
|
||||
func downloadAndUnpack(url string, path string) error {
|
||||
err := os.MkdirAll(path, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileName := filepath.Base(url)
|
||||
|
||||
tarLocation := filepath.Join(path, fileName)
|
||||
defer os.Remove(tarLocation)
|
||||
|
||||
err = downloadFile(tarLocation, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, stderr, err := capture(exec.Command(config.TarBin, "-xf", tarLocation, "-C", path))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", stderr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPkgbuilds(pkgs []string) error {
|
||||
missing := false
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkgs = removeInvalidTargets(pkgs)
|
||||
aur, repo, err := packageSlices(pkgs)
|
||||
|
||||
for n := range aur {
|
||||
_, pkg := splitDbFromName(aur[n])
|
||||
aur[n] = pkg
|
||||
}
|
||||
|
||||
info, err := aurInfoPrint(aur)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(repo) > 0 {
|
||||
missing, err = getPkgbuildsfromABS(repo, wd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(aur) > 0 {
|
||||
allBases := getBases(info)
|
||||
bases := make([]Base, 0)
|
||||
|
||||
for _, base := range allBases {
|
||||
name := base.Pkgbase()
|
||||
_, err = os.Stat(filepath.Join(wd, name))
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
fmt.Println(bold(red(smallArrow)), err)
|
||||
continue
|
||||
} else if os.IsNotExist(err) || cmdArgs.existsArg("f", "force") || shouldUseGit(filepath.Join(wd, name)) {
|
||||
if err = os.RemoveAll(filepath.Join(wd, name)); err != nil {
|
||||
fmt.Println(bold(red(smallArrow)), err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s %s %s\n", yellow(smallArrow), cyan(name), "already downloaded -- use -f to overwrite")
|
||||
continue
|
||||
}
|
||||
|
||||
bases = append(bases, base)
|
||||
}
|
||||
|
||||
if _, err = downloadPkgbuilds(bases, nil, wd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
missing = missing || len(aur) != len(info)
|
||||
}
|
||||
|
||||
if missing {
|
||||
err = fmt.Errorf("")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// GetPkgbuild downloads pkgbuild from the ABS.
|
||||
func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
|
||||
var wg sync.WaitGroup
|
||||
var mux sync.Mutex
|
||||
var errs MultiError
|
||||
names := make(map[string]string)
|
||||
missing := make([]string, 0)
|
||||
downloaded := 0
|
||||
|
||||
dbList, err := alpmHandle.SyncDbs()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, pkgN := range pkgs {
|
||||
var pkg *alpm.Package
|
||||
var err error
|
||||
var url string
|
||||
pkgDb, name := splitDbFromName(pkgN)
|
||||
|
||||
if pkgDb != "" {
|
||||
if db, err := alpmHandle.SyncDbByName(pkgDb); err == nil {
|
||||
pkg, err = db.PkgByName(name)
|
||||
}
|
||||
} else {
|
||||
dbList.ForEach(func(db alpm.Db) error {
|
||||
if pkg, err = db.PkgByName(name); err == nil {
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if pkg == nil {
|
||||
missing = append(missing, name)
|
||||
continue
|
||||
}
|
||||
|
||||
name = pkg.Base()
|
||||
if name == "" {
|
||||
name = pkg.Name()
|
||||
}
|
||||
|
||||
switch pkg.DB().Name() {
|
||||
case "core", "extra", "testing":
|
||||
url = "https://git.archlinux.org/svntogit/packages.git/snapshot/packages/" + name + ".tar.gz"
|
||||
case "community", "multilib", "community-testing", "multilib-testing":
|
||||
url = "https://git.archlinux.org/svntogit/community.git/snapshot/packages/" + name + ".tar.gz"
|
||||
default:
|
||||
missing = append(missing, name)
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = os.Stat(filepath.Join(path, name))
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
fmt.Println(bold(red(smallArrow)), err)
|
||||
continue
|
||||
} else if os.IsNotExist(err) || cmdArgs.existsArg("f", "force") {
|
||||
if err = os.RemoveAll(filepath.Join(path, name)); err != nil {
|
||||
fmt.Println(bold(red(smallArrow)), err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s %s %s\n", yellow(smallArrow), cyan(name), "already downloaded -- use -f to overwrite")
|
||||
continue
|
||||
}
|
||||
|
||||
names[name] = url
|
||||
}
|
||||
|
||||
if len(missing) != 0 {
|
||||
fmt.Println(yellow(bold(smallArrow)), "Missing ABS packages: ", cyan(strings.Join(missing, " ")))
|
||||
}
|
||||
|
||||
download := func(pkg string, url string) {
|
||||
defer wg.Done()
|
||||
if err := downloadAndUnpack(url, cacheHome); err != nil {
|
||||
errs.Add(fmt.Errorf("%s Failed to get pkgbuild: %s: %s", bold(red(arrow)), bold(cyan(pkg)), bold(red(err.Error()))))
|
||||
return
|
||||
}
|
||||
|
||||
_, stderr, err := capture(exec.Command("mv", filepath.Join(cacheHome, "packages", pkg, "trunk"), filepath.Join(path, pkg)))
|
||||
mux.Lock()
|
||||
downloaded++
|
||||
if err != nil {
|
||||
errs.Add(fmt.Errorf("%s Failed to move %s: %s", bold(red(arrow)), bold(cyan(pkg)), bold(red(string(stderr)))))
|
||||
} else {
|
||||
fmt.Printf(bold(cyan("::"))+" Downloaded PKGBUILD from ABS (%d/%d): %s\n", downloaded, len(names), cyan(pkg))
|
||||
}
|
||||
mux.Unlock()
|
||||
}
|
||||
|
||||
count := 0
|
||||
for name, url := range names {
|
||||
wg.Add(1)
|
||||
go download(name, url)
|
||||
count++
|
||||
if count%25 == 0 {
|
||||
wg.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
errs.Add(os.RemoveAll(filepath.Join(cacheHome, "packages")))
|
||||
return len(missing) != 0, errs.Return()
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
)
|
||||
|
||||
var ErrPackagesNotFound = errors.New(gotext.Get("could not find all required packages"))
|
123
exec.go
Normal file
123
exec.go
Normal file
@ -0,0 +1,123 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func show(cmd *exec.Cmd) error {
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func capture(cmd *exec.Cmd) (string, string, error) {
|
||||
var outbuf, errbuf bytes.Buffer
|
||||
|
||||
cmd.Stdout = &outbuf
|
||||
cmd.Stderr = &errbuf
|
||||
err := cmd.Run()
|
||||
stdout := strings.TrimSpace(outbuf.String())
|
||||
stderr := strings.TrimSpace(errbuf.String())
|
||||
|
||||
return stdout, stderr, err
|
||||
}
|
||||
|
||||
func sudoLoopBackground() {
|
||||
updateSudo()
|
||||
go sudoLoop()
|
||||
}
|
||||
|
||||
func sudoLoop() {
|
||||
for {
|
||||
updateSudo()
|
||||
time.Sleep(298 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func updateSudo() {
|
||||
for {
|
||||
err := show(exec.Command("sudo", "-v"))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// waitLock will lock yay checking the status of db.lck until it does not exist
|
||||
func waitLock() {
|
||||
if _, err := os.Stat(filepath.Join(pacmanConf.DBPath, "db.lck")); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Print(bold(yellow(smallArrow)), " db.lck is present. Waiting...")
|
||||
|
||||
for {
|
||||
time.Sleep(3 * time.Second)
|
||||
if _, err := os.Stat(filepath.Join(pacmanConf.DBPath, "db.lck")); err != nil {
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func passToPacman(args *arguments) *exec.Cmd {
|
||||
argArr := make([]string, 0)
|
||||
|
||||
if args.needRoot() {
|
||||
argArr = append(argArr, "sudo")
|
||||
}
|
||||
|
||||
argArr = append(argArr, config.PacmanBin)
|
||||
argArr = append(argArr, cmdArgs.formatGlobals()...)
|
||||
argArr = append(argArr, args.formatArgs()...)
|
||||
if config.NoConfirm {
|
||||
argArr = append(argArr, "--noconfirm")
|
||||
}
|
||||
|
||||
argArr = append(argArr, "--config", config.PacmanConf)
|
||||
argArr = append(argArr, "--")
|
||||
argArr = append(argArr, args.targets...)
|
||||
|
||||
if args.needRoot() {
|
||||
waitLock()
|
||||
}
|
||||
return exec.Command(argArr[0], argArr[1:]...)
|
||||
}
|
||||
|
||||
func passToMakepkg(dir string, args ...string) *exec.Cmd {
|
||||
if config.NoConfirm {
|
||||
args = append(args)
|
||||
}
|
||||
|
||||
mflags := strings.Fields(config.MFlags)
|
||||
args = append(args, mflags...)
|
||||
|
||||
if config.MakepkgConf != "" {
|
||||
args = append(args, "--config", config.MakepkgConf)
|
||||
}
|
||||
|
||||
cmd := exec.Command(config.MakepkgBin, args...)
|
||||
cmd.Dir = dir
|
||||
return cmd
|
||||
}
|
||||
|
||||
func passToGit(dir string, _args ...string) *exec.Cmd {
|
||||
gitflags := strings.Fields(config.GitFlags)
|
||||
args := []string{"-C", dir}
|
||||
args = append(args, gitflags...)
|
||||
args = append(args, _args...)
|
||||
|
||||
cmd := exec.Command(config.GitBin, args...)
|
||||
return cmd
|
||||
}
|
80
get.go
80
get.go
@ -1,80 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/download"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
// yay -Gp.
|
||||
func printPkgbuilds(dbExecutor download.DBSearcher, aurClient aur.QueryClient,
|
||||
httpClient *http.Client, logger *text.Logger, targets []string,
|
||||
mode parser.TargetMode, aurURL string,
|
||||
) error {
|
||||
pkgbuilds, err := download.PKGBUILDs(dbExecutor, aurClient, httpClient, logger, targets, aurURL, mode)
|
||||
if err != nil {
|
||||
logger.Errorln(err)
|
||||
}
|
||||
|
||||
for target, pkgbuild := range pkgbuilds {
|
||||
logger.Printf("\n\n# %s\n\n%s", target, string(pkgbuild))
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != len(targets) {
|
||||
missing := []string{}
|
||||
|
||||
for _, target := range targets {
|
||||
if _, ok := pkgbuilds[target]; !ok {
|
||||
missing = append(missing, target)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
|
||||
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// yay -G.
|
||||
func getPkgbuilds(ctx context.Context, dbExecutor download.DBSearcher, aurClient aur.QueryClient,
|
||||
run *runtime.Runtime, targets []string, force bool,
|
||||
) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cloned, errD := download.PKGBUILDRepos(ctx, dbExecutor, aurClient,
|
||||
run.CmdBuilder, run.Logger, targets, run.Cfg.Mode, run.Cfg.AURURL, wd, force)
|
||||
if errD != nil {
|
||||
run.Logger.Errorln(errD)
|
||||
}
|
||||
|
||||
if len(targets) != len(cloned) {
|
||||
missing := []string{}
|
||||
|
||||
for _, target := range targets {
|
||||
if _, ok := cloned[target]; !ok {
|
||||
missing = append(missing, target)
|
||||
}
|
||||
}
|
||||
|
||||
run.Logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
|
||||
|
||||
err = fmt.Errorf("")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
35
go.mod
35
go.mod
@ -1,35 +0,0 @@
|
||||
module github.com/Jguer/yay/v12
|
||||
|
||||
require (
|
||||
github.com/Jguer/aur v1.2.3
|
||||
github.com/Jguer/go-alpm/v2 v2.2.2
|
||||
github.com/Jguer/votar v1.0.0
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
|
||||
github.com/Morganamilo/go-srcinfo v1.0.0
|
||||
github.com/adrg/strutil v0.3.1
|
||||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
|
||||
github.com/deckarep/golang-set/v2 v2.8.0
|
||||
github.com/hashicorp/go-multierror v1.1.1
|
||||
github.com/leonelquinteros/gotext v1.7.2
|
||||
github.com/stretchr/testify v1.10.0
|
||||
golang.org/x/net v0.41.0
|
||||
golang.org/x/sys v0.33.0
|
||||
golang.org/x/term v0.32.0
|
||||
gopkg.in/h2non/gock.v1 v1.1.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/itchyny/gojq v0.12.17 // indirect
|
||||
github.com/itchyny/timefmt-go v0.1.6 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/ohler55/ojg v1.26.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
go 1.23.5
|
||||
|
||||
toolchain go1.24.0
|
68
go.sum
68
go.sum
@ -1,68 +0,0 @@
|
||||
github.com/Jguer/aur v1.2.3 h1:D+OGgLxnAnZnw88DsRvnRQsn0Poxsy9ng7pBcsA0krM=
|
||||
github.com/Jguer/aur v1.2.3/go.mod h1:Dahvb6L1yr0rR7svyYSDwaRJoQMeyvJblwJ3QH/7CUs=
|
||||
github.com/Jguer/go-alpm/v2 v2.2.2 h1:sPwUoZp1X5Tw6K6Ba1lWvVJfcgVNEGVcxARLBttZnC0=
|
||||
github.com/Jguer/go-alpm/v2 v2.2.2/go.mod h1:lfe8gSe83F/KERaQvEfrSqQ4n+8bES+ZIyKWR/gm3MI=
|
||||
github.com/Jguer/votar v1.0.0 h1:drPYpV5Py5BeAQS8xezmT6uCEfLzotNjLf5yfmlHKTg=
|
||||
github.com/Jguer/votar v1.0.0/go.mod h1:rc6vgVlTqNjI4nAnPbDTbdxw/N7kXkbB8BcUDjeFbYQ=
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5 h1:TMscPjkb1ThXN32LuFY5bEYIcXZx3YlwzhS1GxNpn/c=
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5/go.mod h1:Hk55m330jNiwxRodIlMCvw5iEyoRUCIY64W1p9D+tHc=
|
||||
github.com/Morganamilo/go-srcinfo v1.0.0 h1:Wh4nEF+HJWo+29hnxM18Q2hi+DUf0GejS13+Wg+dzmI=
|
||||
github.com/Morganamilo/go-srcinfo v1.0.0/go.mod h1:MP6VGY1NNpVUmYIEgoM9acix95KQqIRyqQ0hCLsyYUY=
|
||||
github.com/adrg/strutil v0.3.1 h1:OLvSS7CSJO8lBii4YmBt8jiK9QOtB9CzCzwl4Ic/Fz4=
|
||||
github.com/adrg/strutil v0.3.1/go.mod h1:8h90y18QLrs11IBffcGX3NW/GFBXCMcNg4M7H6MspPA=
|
||||
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
|
||||
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
|
||||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y=
|
||||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/deckarep/golang-set/v2 v2.8.0 h1:swm0rlPCmdWn9mESxKOjWk8hXSqoxOp+ZlfuyaAdFlQ=
|
||||
github.com/deckarep/golang-set/v2 v2.8.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/itchyny/gojq v0.12.17 h1:8av8eGduDb5+rvEdaOO+zQUjA04MS0m3Ps8HiD+fceg=
|
||||
github.com/itchyny/gojq v0.12.17/go.mod h1:WBrEMkgAfAGO1LUcGOckBl5O726KPp+OlkKug0I/FEY=
|
||||
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
|
||||
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
|
||||
github.com/leonelquinteros/gotext v1.7.2 h1:bDPndU8nt+/kRo1m4l/1OXiiy2v7Z7dfPQ9+YP7G1Mc=
|
||||
github.com/leonelquinteros/gotext v1.7.2/go.mod h1:9/haCkm5P7Jay1sxKDGJ5WIg4zkz8oZKw4ekNpALob8=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/ohler55/ojg v1.26.1 h1:J5TaLmVEuvnpVH7JMdT1QdbpJU545Yp6cKiCO4aQILc=
|
||||
github.com/ohler55/ojg v1.26.1/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
1083
install.go
Normal file
1083
install.go
Normal file
File diff suppressed because it is too large
Load Diff
121
keys.go
Normal file
121
keys.go
Normal file
@ -0,0 +1,121 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
)
|
||||
|
||||
// pgpKeySet maps a PGP key with a list of PKGBUILDs that require it.
|
||||
// This is similar to stringSet, used throughout the code.
|
||||
type pgpKeySet map[string][]Base
|
||||
|
||||
func (set pgpKeySet) toSlice() []string {
|
||||
slice := make([]string, 0, len(set))
|
||||
for v := range set {
|
||||
slice = append(slice, v)
|
||||
}
|
||||
return slice
|
||||
}
|
||||
|
||||
func (set pgpKeySet) set(key string, p Base) {
|
||||
// Using ToUpper to make sure keys with a different case will be
|
||||
// considered the same.
|
||||
upperKey := strings.ToUpper(key)
|
||||
set[key] = append(set[upperKey], p)
|
||||
}
|
||||
|
||||
func (set pgpKeySet) get(key string) bool {
|
||||
upperKey := strings.ToUpper(key)
|
||||
_, exists := set[upperKey]
|
||||
return exists
|
||||
}
|
||||
|
||||
// checkPgpKeys iterates through the keys listed in the PKGBUILDs and if needed,
|
||||
// asks the user whether yay should try to import them.
|
||||
func checkPgpKeys(bases []Base, srcinfos map[string]*gosrc.Srcinfo) error {
|
||||
// Let's check the keys individually, and then we can offer to import
|
||||
// the problematic ones.
|
||||
problematic := make(pgpKeySet)
|
||||
args := append(strings.Fields(config.GpgFlags), "--list-keys")
|
||||
|
||||
// Mapping all the keys.
|
||||
for _, base := range bases {
|
||||
pkg := base.Pkgbase()
|
||||
srcinfo := srcinfos[pkg]
|
||||
|
||||
for _, key := range srcinfo.ValidPGPKeys {
|
||||
// If key already marked as problematic, indicate the current
|
||||
// PKGBUILD requires it.
|
||||
if problematic.get(key) {
|
||||
problematic.set(key, base)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd := exec.Command(config.GpgBin, append(args, key)...)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
problematic.set(key, base)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No key issues!
|
||||
if len(problematic) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
str, err := formatKeysToImport(problematic)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println(str)
|
||||
|
||||
if continueTask(bold(green("Import?")), true) {
|
||||
return importKeys(problematic.toSlice())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// importKeys tries to import the list of keys specified in its argument.
|
||||
func importKeys(keys []string) error {
|
||||
args := append(strings.Fields(config.GpgFlags), "--recv-keys")
|
||||
cmd := exec.Command(config.GpgBin, append(args, keys...)...)
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||
|
||||
fmt.Printf("%s %s...\n", bold(cyan("::")), bold("Importing keys with gpg..."))
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s Problem importing keys", bold(red(arrow+" Error:")))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// formatKeysToImport receives a set of keys and returns a string containing the
|
||||
// question asking the user wants to import the problematic keys.
|
||||
func formatKeysToImport(keys pgpKeySet) (string, error) {
|
||||
if len(keys) == 0 {
|
||||
return "", fmt.Errorf("%s No keys to import", bold(red(arrow+" Error:")))
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(bold(green(arrow)))
|
||||
buffer.WriteString(bold(green(" PGP keys need importing:")))
|
||||
for key, bases := range keys {
|
||||
pkglist := ""
|
||||
for _, base := range bases {
|
||||
pkglist += base.String() + " "
|
||||
}
|
||||
pkglist = strings.TrimRight(pkglist, " ")
|
||||
buffer.WriteString(fmt.Sprintf("\n%s %s, required by: %s", yellow(bold(smallArrow)), cyan(key), cyan(pkglist)))
|
||||
}
|
||||
return buffer.String(), nil
|
||||
}
|
218
keys_test.go
Normal file
218
keys_test.go
Normal file
@ -0,0 +1,218 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
)
|
||||
|
||||
const (
|
||||
// The default port used by the PGP key server.
|
||||
gpgServerPort = 11371
|
||||
)
|
||||
|
||||
func init() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
regex := regexp.MustCompile(`search=0[xX]([a-fA-F0-9]+)`)
|
||||
matches := regex.FindStringSubmatch(r.RequestURI)
|
||||
data := ""
|
||||
if matches != nil {
|
||||
data = getPgpKey(matches[1])
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/pgp-keys")
|
||||
w.Write([]byte(data))
|
||||
})
|
||||
}
|
||||
|
||||
func newPkg(basename string) *rpc.Pkg {
|
||||
return &rpc.Pkg{Name: basename, PackageBase: basename}
|
||||
}
|
||||
|
||||
func getPgpKey(key string) string {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if contents, err := ioutil.ReadFile(path.Join("testdata", "keys", key)); err == nil {
|
||||
buffer.WriteString("-----BEGIN PGP PUBLIC KEY BLOCK-----\n")
|
||||
buffer.WriteString("Version: SKS 1.1.6\n")
|
||||
buffer.WriteString("Comment: Hostname: yay\n\n")
|
||||
buffer.Write(contents)
|
||||
buffer.WriteString("\n-----END PGP PUBLIC KEY BLOCK-----\n")
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func startPgpKeyServer() *http.Server {
|
||||
srv := &http.Server{Addr: fmt.Sprintf("127.0.0.1:%d", gpgServerPort)}
|
||||
|
||||
go func() {
|
||||
srv.ListenAndServe()
|
||||
}()
|
||||
return srv
|
||||
}
|
||||
|
||||
func TestImportKeys(t *testing.T) {
|
||||
keyringDir, err := ioutil.TempDir("/tmp", "yay-test-keyring")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to init test keyring %q: %v\n", keyringDir, err)
|
||||
}
|
||||
defer os.RemoveAll(keyringDir)
|
||||
|
||||
config.GpgBin = "gpg"
|
||||
config.GpgFlags = fmt.Sprintf("--homedir %s --keyserver 127.0.0.1", keyringDir)
|
||||
|
||||
server := startPgpKeyServer()
|
||||
defer server.Shutdown(context.TODO())
|
||||
|
||||
casetests := []struct {
|
||||
keys []string
|
||||
wantError bool
|
||||
}{
|
||||
// Single key, should succeed.
|
||||
// C52048C0C0748FEE227D47A2702353E0F7E48EDB: Thomas Dickey.
|
||||
{
|
||||
keys: []string{"C52048C0C0748FEE227D47A2702353E0F7E48EDB"},
|
||||
wantError: false,
|
||||
},
|
||||
// Two keys, should succeed as well.
|
||||
// 11E521D646982372EB577A1F8F0871F202119294: Tom Stellard.
|
||||
// B6C8F98282B944E3B0D5C2530FC3042E345AD05D: Hans Wennborg.
|
||||
{
|
||||
keys: []string{"11E521D646982372EB577A1F8F0871F202119294",
|
||||
"B6C8F98282B944E3B0D5C2530FC3042E345AD05D"},
|
||||
wantError: false,
|
||||
},
|
||||
// Single invalid key, should fail.
|
||||
{
|
||||
keys: []string{"THIS-SHOULD-FAIL"},
|
||||
wantError: true,
|
||||
},
|
||||
// Two invalid keys, should fail.
|
||||
{
|
||||
keys: []string{"THIS-SHOULD-FAIL", "THIS-ONE-SHOULD-FAIL-TOO"},
|
||||
wantError: true,
|
||||
},
|
||||
// Invalid + valid key. Should fail as well.
|
||||
// 647F28654894E3BD457199BE38DBBDC86092693E: Greg Kroah-Hartman.
|
||||
{
|
||||
keys: []string{"THIS-SHOULD-FAIL",
|
||||
"647F28654894E3BD457199BE38DBBDC86092693E"},
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range casetests {
|
||||
err := importKeys(tt.keys)
|
||||
if !tt.wantError {
|
||||
if err != nil {
|
||||
t.Fatalf("Got error %q, want no error", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// Here, we want to see the error.
|
||||
if err == nil {
|
||||
t.Fatalf("Got no error; want error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeSrcinfo(pkgbase string, pgpkeys ...string) *gosrc.Srcinfo {
|
||||
srcinfo := gosrc.Srcinfo{}
|
||||
srcinfo.Pkgbase = pkgbase
|
||||
srcinfo.ValidPGPKeys = pgpkeys
|
||||
|
||||
return &srcinfo
|
||||
}
|
||||
|
||||
func TestCheckPgpKeys(t *testing.T) {
|
||||
keyringDir, err := ioutil.TempDir("/tmp", "yay-test-keyring")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to init test keyring: %v\n", err)
|
||||
}
|
||||
defer os.RemoveAll(keyringDir)
|
||||
|
||||
config.GpgBin = "gpg"
|
||||
config.GpgFlags = fmt.Sprintf("--homedir %s --keyserver 127.0.0.1", keyringDir)
|
||||
|
||||
server := startPgpKeyServer()
|
||||
defer server.Shutdown(context.TODO())
|
||||
|
||||
casetests := []struct {
|
||||
pkgs Base
|
||||
srcinfos map[string]*gosrc.Srcinfo
|
||||
wantError bool
|
||||
}{
|
||||
// cower: single package, one valid key not yet in the keyring.
|
||||
// 487EACC08557AD082088DABA1EB2638FF56C0C53: Dave Reisner.
|
||||
{
|
||||
pkgs: Base{newPkg("cower")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"cower": makeSrcinfo("cower", "487EACC08557AD082088DABA1EB2638FF56C0C53")},
|
||||
wantError: false,
|
||||
},
|
||||
// libc++: single package, two valid keys not yet in the keyring.
|
||||
// 11E521D646982372EB577A1F8F0871F202119294: Tom Stellard.
|
||||
// B6C8F98282B944E3B0D5C2530FC3042E345AD05D: Hans Wennborg.
|
||||
{
|
||||
pkgs: Base{newPkg("libc++")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"libc++": makeSrcinfo("libc++", "11E521D646982372EB577A1F8F0871F202119294", "B6C8F98282B944E3B0D5C2530FC3042E345AD05D")},
|
||||
wantError: false,
|
||||
},
|
||||
// Two dummy packages requiring the same key.
|
||||
// ABAF11C65A2970B130ABE3C479BE3E4300411886: Linus Torvalds.
|
||||
{
|
||||
pkgs: Base{newPkg("dummy-1"), newPkg("dummy-2")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"dummy-1": makeSrcinfo("dummy-1", "ABAF11C65A2970B130ABE3C479BE3E4300411886"), "dummy-2": makeSrcinfo("dummy-2", "ABAF11C65A2970B130ABE3C479BE3E4300411886")},
|
||||
wantError: false,
|
||||
},
|
||||
// dummy package: single package, two valid keys, one of them already
|
||||
// in the keyring.
|
||||
// 11E521D646982372EB577A1F8F0871F202119294: Tom Stellard.
|
||||
// C52048C0C0748FEE227D47A2702353E0F7E48EDB: Thomas Dickey.
|
||||
{
|
||||
pkgs: Base{newPkg("dummy-3")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"dummy-3": makeSrcinfo("dummy-3", "11E521D646982372EB577A1F8F0871F202119294", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")},
|
||||
wantError: false,
|
||||
},
|
||||
// Two dummy packages with existing keys.
|
||||
{
|
||||
pkgs: Base{newPkg("dummy-4"), newPkg("dummy-5")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"dummy-4": makeSrcinfo("dummy-4", "11E521D646982372EB577A1F8F0871F202119294"), "dummy-5": makeSrcinfo("dummy-5", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")},
|
||||
wantError: false,
|
||||
},
|
||||
// Dummy package with invalid key, should fail.
|
||||
{
|
||||
pkgs: Base{newPkg("dummy-7")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"dummy-7": makeSrcinfo("dummy-7", "THIS-SHOULD-FAIL")},
|
||||
wantError: true,
|
||||
},
|
||||
// Dummy package with both an invalid an another valid key, should fail.
|
||||
// A314827C4E4250A204CE6E13284FC34C8E4B1A25: Thomas Bächler.
|
||||
{
|
||||
pkgs: Base{newPkg("dummy-8")},
|
||||
srcinfos: map[string]*gosrc.Srcinfo{"dummy-8": makeSrcinfo("dummy-8", "A314827C4E4250A204CE6E13284FC34C8E4B1A25", "THIS-SHOULD-FAIL")},
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range casetests {
|
||||
err := checkPgpKeys([]Base{tt.pkgs}, tt.srcinfos)
|
||||
if !tt.wantError {
|
||||
if err != nil {
|
||||
t.Fatalf("Got error %q, want no error", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// Here, we want to see the error.
|
||||
if err == nil {
|
||||
t.Fatalf("Got no error; want error")
|
||||
}
|
||||
}
|
||||
}
|
108
local_install.go
108
local_install.go
@ -1,108 +0,0 @@
|
||||
// Experimental code for install local with dependency refactoring
|
||||
// Not at feature parity with install.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/dep"
|
||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/sync"
|
||||
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
)
|
||||
|
||||
var ErrNoBuildFiles = errors.New(gotext.Get("cannot find PKGBUILD and .SRCINFO in directory"))
|
||||
|
||||
func srcinfoExists(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder, targetDir string,
|
||||
) error {
|
||||
srcInfoDir := filepath.Join(targetDir, ".SRCINFO")
|
||||
pkgbuildDir := filepath.Join(targetDir, "PKGBUILD")
|
||||
if _, err := os.Stat(srcInfoDir); err == nil {
|
||||
if _, err := os.Stat(pkgbuildDir); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(pkgbuildDir); err == nil {
|
||||
// run makepkg to generate .SRCINFO
|
||||
srcinfo, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildMakepkgCmd(ctx, targetDir, "--printsrcinfo"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to generate .SRCINFO: %w - %s", err, stderr)
|
||||
}
|
||||
|
||||
if srcinfo == "" {
|
||||
return fmt.Errorf("generated .SRCINFO is empty, check your PKGBUILD for errors")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(srcInfoDir, []byte(srcinfo), 0o600); err != nil {
|
||||
return fmt.Errorf("unable to write .SRCINFO: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("%w: %s", ErrNoBuildFiles, targetDir)
|
||||
}
|
||||
|
||||
func installLocalPKGBUILD(
|
||||
ctx context.Context,
|
||||
run *runtime.Runtime,
|
||||
cmdArgs *parser.Arguments,
|
||||
dbExecutor db.Executor,
|
||||
) error {
|
||||
aurCache := run.AURClient
|
||||
noCheck := strings.Contains(run.Cfg.MFlags, "--nocheck")
|
||||
|
||||
if len(cmdArgs.Targets) < 1 {
|
||||
return errors.New(gotext.Get("no target directories specified"))
|
||||
}
|
||||
|
||||
srcInfos := map[string]*gosrc.Srcinfo{}
|
||||
for _, targetDir := range cmdArgs.Targets {
|
||||
if err := srcinfoExists(ctx, run.CmdBuilder, targetDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkgbuild, err := gosrc.ParseFile(filepath.Join(targetDir, ".SRCINFO"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", gotext.Get("failed to parse .SRCINFO"), err)
|
||||
}
|
||||
|
||||
srcInfos[targetDir] = pkgbuild
|
||||
}
|
||||
|
||||
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
|
||||
cmdArgs.ExistsDouble("d", "nodeps"), noCheck, cmdArgs.ExistsArg("needed"),
|
||||
run.Logger.Child("grapher"))
|
||||
graph, err := grapher.GraphFromSrcInfos(ctx, nil, srcInfos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opService := sync.NewOperationService(ctx, dbExecutor, run)
|
||||
multiErr := &multierror.MultiError{}
|
||||
targets := graph.TopoSortedLayerMap(func(name string, ii *dep.InstallInfo) error {
|
||||
if ii.Source == dep.Missing {
|
||||
multiErr.Add(fmt.Errorf("%w: %s %s", ErrPackagesNotFound, name, ii.Version))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err := multiErr.Return(); err != nil {
|
||||
return err
|
||||
}
|
||||
return opService.Run(ctx, run, cmdArgs, targets, []string{})
|
||||
}
|
File diff suppressed because it is too large
Load Diff
342
main.go
342
main.go
@ -1,154 +1,222 @@
|
||||
package main // import "github.com/Jguer/yay"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime/debug"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db/ialpm"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
pacmanconf "github.com/Morganamilo/go-pacmanconf"
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
var (
|
||||
yayVersion = "12.0.4" // To be set by compiler.
|
||||
localePath = "/usr/share/locale" // To be set by compiler.
|
||||
)
|
||||
|
||||
func initGotext() {
|
||||
if envLocalePath := os.Getenv("LOCALE_PATH"); envLocalePath != "" {
|
||||
localePath = envLocalePath
|
||||
}
|
||||
|
||||
if lc := os.Getenv("LANGUAGE"); lc != "" {
|
||||
// Split LANGUAGE by ':' and prioritize the first locale
|
||||
// Should fix in gotext to support this
|
||||
locales := strings.Split(lc, ":")
|
||||
if len(locales) > 0 && locales[0] != "" {
|
||||
gotext.Configure(localePath, locales[0], "yay")
|
||||
}
|
||||
} else if lc := os.Getenv("LC_ALL"); lc != "" {
|
||||
gotext.Configure(localePath, lc, "yay")
|
||||
} else if lc := os.Getenv("LC_MESSAGES"); lc != "" {
|
||||
gotext.Configure(localePath, lc, "yay")
|
||||
func setPaths() error {
|
||||
if configHome = os.Getenv("XDG_CONFIG_HOME"); configHome != "" {
|
||||
configHome = filepath.Join(configHome, "yay")
|
||||
} else if configHome = os.Getenv("HOME"); configHome != "" {
|
||||
configHome = filepath.Join(configHome, ".config/yay")
|
||||
} else {
|
||||
gotext.Configure(localePath, os.Getenv("LANG"), "yay")
|
||||
return fmt.Errorf("XDG_CONFIG_HOME and HOME unset")
|
||||
}
|
||||
|
||||
if cacheHome = os.Getenv("XDG_CACHE_HOME"); cacheHome != "" {
|
||||
cacheHome = filepath.Join(cacheHome, "yay")
|
||||
} else if cacheHome = os.Getenv("HOME"); cacheHome != "" {
|
||||
cacheHome = filepath.Join(cacheHome, ".cache/yay")
|
||||
} else {
|
||||
return fmt.Errorf("XDG_CACHE_HOME and HOME unset")
|
||||
}
|
||||
|
||||
configFile = filepath.Join(configHome, configFileName)
|
||||
vcsFile = filepath.Join(cacheHome, vcsFileName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initConfig() error {
|
||||
cfile, err := os.Open(configFile)
|
||||
if !os.IsNotExist(err) && err != nil {
|
||||
return fmt.Errorf("Failed to open config file '%s': %s", configFile, err)
|
||||
}
|
||||
|
||||
defer cfile.Close()
|
||||
if !os.IsNotExist(err) {
|
||||
decoder := json.NewDecoder(cfile)
|
||||
if err = decoder.Decode(&config); err != nil {
|
||||
return fmt.Errorf("Failed to read config '%s': %s", configFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initVCS() error {
|
||||
vfile, err := os.Open(vcsFile)
|
||||
if !os.IsNotExist(err) && err != nil {
|
||||
return fmt.Errorf("Failed to open vcs file '%s': %s", vcsFile, err)
|
||||
}
|
||||
|
||||
defer vfile.Close()
|
||||
if !os.IsNotExist(err) {
|
||||
decoder := json.NewDecoder(vfile)
|
||||
if err = decoder.Decode(&savedInfo); err != nil {
|
||||
return fmt.Errorf("Failed to read vcs '%s': %s", vcsFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initHomeDirs() error {
|
||||
if _, err := os.Stat(configHome); os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(configHome, 0755); err != nil {
|
||||
return fmt.Errorf("Failed to create config directory '%s': %s", configHome, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(cacheHome); os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(cacheHome, 0755); err != nil {
|
||||
return fmt.Errorf("Failed to create cache directory '%s': %s", cacheHome, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initBuildDir() error {
|
||||
if _, err := os.Stat(config.BuildDir); os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(config.BuildDir, 0755); err != nil {
|
||||
return fmt.Errorf("Failed to create BuildDir directory '%s': %s", config.BuildDir, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initAlpm() error {
|
||||
var err error
|
||||
var stderr string
|
||||
|
||||
root := "/"
|
||||
if value, _, exists := cmdArgs.getArg("root", "r"); exists {
|
||||
root = value
|
||||
}
|
||||
|
||||
pacmanConf, stderr, err = pacmanconf.PacmanConf("--config", config.PacmanConf, "--root", root)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", stderr)
|
||||
}
|
||||
|
||||
if value, _, exists := cmdArgs.getArg("dbpath", "b"); exists {
|
||||
pacmanConf.DBPath = value
|
||||
}
|
||||
|
||||
if value, _, exists := cmdArgs.getArg("arch"); exists {
|
||||
pacmanConf.Architecture = value
|
||||
}
|
||||
|
||||
if value, _, exists := cmdArgs.getArg("ignore"); exists {
|
||||
pacmanConf.IgnorePkg = append(pacmanConf.IgnorePkg, strings.Split(value, ",")...)
|
||||
}
|
||||
|
||||
if value, _, exists := cmdArgs.getArg("ignoregroup"); exists {
|
||||
pacmanConf.IgnoreGroup = append(pacmanConf.IgnoreGroup, strings.Split(value, ",")...)
|
||||
}
|
||||
|
||||
//TODO
|
||||
//current system does not allow duplicate arguments
|
||||
//but pacman allows multiple cachdirs to be passed
|
||||
//for now only handle one cache dir
|
||||
if value, _, exists := cmdArgs.getArg("cachdir"); exists {
|
||||
pacmanConf.CacheDir = []string{value}
|
||||
}
|
||||
|
||||
if value, _, exists := cmdArgs.getArg("gpgdir"); exists {
|
||||
pacmanConf.GPGDir = value
|
||||
}
|
||||
|
||||
if err = initAlpmHandle(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if value, _, _ := cmdArgs.getArg("color"); value == "always" || value == "auto" {
|
||||
useColor = true
|
||||
} else if value == "never" {
|
||||
useColor = false
|
||||
} else {
|
||||
useColor = pacmanConf.Color
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initAlpmHandle() error {
|
||||
var err error
|
||||
|
||||
if alpmHandle != nil {
|
||||
if err := alpmHandle.Release(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if alpmHandle, err = alpm.Init(pacmanConf.RootDir, pacmanConf.DBPath); err != nil {
|
||||
return fmt.Errorf("Unable to CreateHandle: %s", err)
|
||||
}
|
||||
|
||||
if err = configureAlpm(pacmanConf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
alpmHandle.SetQuestionCallback(questionCallback)
|
||||
alpmHandle.SetLogCallback(logCallback)
|
||||
return nil
|
||||
}
|
||||
|
||||
func exitOnError(err error) {
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fmt.Println(str)
|
||||
}
|
||||
cleanup()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func cleanup() int {
|
||||
if alpmHandle != nil {
|
||||
if err := alpmHandle.Release(); err != nil {
|
||||
fmt.Println(err)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func main() {
|
||||
fallbackLog := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, false, "fallback")
|
||||
var (
|
||||
err error
|
||||
ctx = context.Background()
|
||||
ret = 0
|
||||
)
|
||||
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
fallbackLog.Errorln("Panic occurred:", rec)
|
||||
fallbackLog.Errorln("Stack trace:", string(debug.Stack()))
|
||||
ret = 1
|
||||
}
|
||||
|
||||
os.Exit(ret)
|
||||
}()
|
||||
|
||||
initGotext()
|
||||
|
||||
if os.Geteuid() == 0 {
|
||||
fallbackLog.Warnln(gotext.Get("Avoid running yay as root/sudo."))
|
||||
if 0 == os.Geteuid() {
|
||||
fmt.Println("Please avoid running yay as root/sudo.")
|
||||
}
|
||||
|
||||
configPath := settings.GetConfigPath()
|
||||
// Parse config
|
||||
cfg, err := settings.NewConfig(fallbackLog, configPath, yayVersion)
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if errS := cfg.RunMigrations(fallbackLog,
|
||||
settings.DefaultMigrations(), configPath, yayVersion); errS != nil {
|
||||
fallbackLog.Errorln(errS)
|
||||
}
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
|
||||
// Parse command line
|
||||
if err = cfg.ParseCommandLine(cmdArgs); err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.SaveConfig {
|
||||
if errS := cfg.Save(configPath, yayVersion); errS != nil {
|
||||
fallbackLog.Errorln(errS)
|
||||
}
|
||||
}
|
||||
|
||||
// Build run
|
||||
run, err := runtime.NewRuntime(cfg, cmdArgs, yayVersion)
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
dbExecutor, err := ialpm.NewExecutor(run.PacmanConf, run.Logger.Child("db"))
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
fallbackLog.Errorln("Panic occurred in DB operation:", rec)
|
||||
fallbackLog.Errorln("Stack trace:", string(debug.Stack()))
|
||||
}
|
||||
|
||||
dbExecutor.Cleanup()
|
||||
}()
|
||||
|
||||
if err = handleCmd(ctx, run, cmdArgs, dbExecutor); err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
exitError := &exec.ExitError{}
|
||||
if errors.As(err, &exitError) {
|
||||
// mirror pacman exit code when applicable
|
||||
ret = exitError.ExitCode()
|
||||
return
|
||||
}
|
||||
|
||||
// fallback
|
||||
ret = 1
|
||||
exitOnError(setPaths())
|
||||
config.defaultSettings()
|
||||
exitOnError(initHomeDirs())
|
||||
exitOnError(initConfig())
|
||||
exitOnError(cmdArgs.parseCommandLine())
|
||||
if shouldSaveConfig {
|
||||
config.saveConfig()
|
||||
}
|
||||
config.expandEnv()
|
||||
exitOnError(initBuildDir())
|
||||
exitOnError(initVCS())
|
||||
exitOnError(initAlpm())
|
||||
exitOnError(handleCmd())
|
||||
os.Exit(cleanup())
|
||||
}
|
||||
|
101
parser_test.go
Normal file
101
parser_test.go
Normal file
@ -0,0 +1,101 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func intRangesEqual(a, b intRanges) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for n := range a {
|
||||
r1 := a[n]
|
||||
r2 := b[n]
|
||||
|
||||
if r1.min != r2.min || r1.max != r2.max {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func stringSetEqual(a, b stringSet) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for n := range a {
|
||||
if !b.get(n) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func TestParseNumberMenu(t *testing.T) {
|
||||
type result struct {
|
||||
Include intRanges
|
||||
Exclude intRanges
|
||||
OtherInclude stringSet
|
||||
OtherExclude stringSet
|
||||
}
|
||||
|
||||
inputs := []string{
|
||||
"1 2 3 4 5",
|
||||
"1-10 5-15",
|
||||
"10-5 90-85",
|
||||
"1 ^2 ^10-5 99 ^40-38 ^123 60-62",
|
||||
"abort all none",
|
||||
"a-b ^a-b ^abort",
|
||||
"1\t2 3 4\t\t \t 5",
|
||||
"1 2,3, 4, 5,6 ,7 ,8",
|
||||
"",
|
||||
" \t ",
|
||||
"A B C D E",
|
||||
}
|
||||
|
||||
expected := []result{
|
||||
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{makeIntRange(1, 10), makeIntRange(5, 15)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{makeIntRange(5, 10), makeIntRange(85, 90)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{makeIntRange(1, 1), makeIntRange(99, 99), makeIntRange(60, 62)}, intRanges{makeIntRange(2, 2), makeIntRange(5, 10), makeIntRange(38, 40), makeIntRange(123, 123)}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, makeStringSet("abort", "all", "none"), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, makeStringSet("a-b"), makeStringSet("abort", "a-b")},
|
||||
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), makeIntRange(8, 8)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, makeStringSet("a", "b", "c", "d", "e"), make(stringSet)},
|
||||
}
|
||||
|
||||
for n, in := range inputs {
|
||||
res := expected[n]
|
||||
include, exclude, otherInclude, otherExclude := parseNumberMenu(in)
|
||||
|
||||
if !intRangesEqual(include, res.Include) ||
|
||||
!intRangesEqual(exclude, res.Exclude) ||
|
||||
!stringSetEqual(otherInclude, res.OtherInclude) ||
|
||||
!stringSetEqual(otherExclude, res.OtherExclude) {
|
||||
|
||||
t.Fatalf("Test %d Failed: Expected: include=%+v exclude=%+v otherInclude=%+v otherExclude=%+v got include=%+v excluive=%+v otherInclude=%+v otherExclude=%+v",
|
||||
n+1, res.Include, res.Exclude, res.OtherInclude, res.OtherExclude, include, exclude, otherInclude, otherExclude)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db/ialpm"
|
||||
"github.com/Jguer/yay/v12/pkg/dep"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/Jguer/aur/metadata"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
)
|
||||
|
||||
func handleCmd(logger *text.Logger) error {
|
||||
cfg, err := settings.NewConfig(logger, settings.GetConfigPath(), "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
if errP := cfg.ParseCommandLine(cmdArgs); errP != nil {
|
||||
return errP
|
||||
}
|
||||
|
||||
run, err := runtime.NewRuntime(cfg, cmdArgs, "1.0.0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbExecutor, err := ialpm.NewExecutor(run.PacmanConf, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aurCache, err := metadata.New(
|
||||
metadata.WithCacheFilePath(
|
||||
filepath.Join(cfg.BuildDir, "aur.json")))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", gotext.Get("failed to retrieve aur Cache"), err)
|
||||
}
|
||||
|
||||
grapher := dep.NewGrapher(dbExecutor, aurCache, true, settings.NoConfirm,
|
||||
cmdArgs.ExistsDouble("d", "nodeps"), false, false,
|
||||
run.Logger.Child("grapher"))
|
||||
|
||||
return graphPackage(context.Background(), grapher, cmdArgs.Targets)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fallbackLog := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, false, "fallback")
|
||||
if err := handleCmd(fallbackLog); err != nil {
|
||||
fallbackLog.Errorln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func graphPackage(
|
||||
ctx context.Context,
|
||||
grapher *dep.Grapher,
|
||||
targets []string,
|
||||
) error {
|
||||
if len(targets) != 1 {
|
||||
return errors.New(gotext.Get("only one target is allowed"))
|
||||
}
|
||||
|
||||
graph, err := grapher.GraphFromAUR(ctx, nil, []string{targets[0]})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stdout, graph.String())
|
||||
fmt.Fprintln(os.Stdout, "\nlayers map\n", graph.TopoSortedLayerMap(nil))
|
||||
|
||||
return nil
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package completion
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
)
|
||||
|
||||
type PkgSynchronizer interface {
|
||||
SyncPackages(...string) []db.IPackage
|
||||
}
|
||||
|
||||
type httpRequestDoer interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
// Show provides completion info for shells.
|
||||
func Show(ctx context.Context, httpClient httpRequestDoer,
|
||||
dbExecutor PkgSynchronizer, aurURL, completionPath string, interval int, force bool,
|
||||
) error {
|
||||
err := Update(ctx, httpClient, dbExecutor, aurURL, completionPath, interval, force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
in, err := os.OpenFile(completionPath, os.O_RDWR|os.O_CREATE, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
_, err = io.Copy(os.Stdout, in)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Update updates completion cache to be used by Complete.
|
||||
func Update(ctx context.Context, httpClient httpRequestDoer,
|
||||
dbExecutor PkgSynchronizer, aurURL, completionPath string, interval int, force bool,
|
||||
) error {
|
||||
info, err := os.Stat(completionPath)
|
||||
|
||||
if os.IsNotExist(err) || (interval != -1 && time.Since(info.ModTime()).Hours() >= float64(interval*24)) || force {
|
||||
errd := os.MkdirAll(filepath.Dir(completionPath), 0o755)
|
||||
if errd != nil {
|
||||
return errd
|
||||
}
|
||||
|
||||
out, errf := os.Create(completionPath)
|
||||
if errf != nil {
|
||||
return errf
|
||||
}
|
||||
|
||||
if createAURList(ctx, httpClient, aurURL, out) != nil {
|
||||
defer os.Remove(completionPath)
|
||||
}
|
||||
|
||||
erra := createRepoList(dbExecutor, out)
|
||||
|
||||
out.Close()
|
||||
|
||||
return erra
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateAURList creates a new completion file.
|
||||
func createAURList(ctx context.Context, client httpRequestDoer, aurURL string, out io.Writer) error {
|
||||
u, err := url.Parse(aurURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.Path = path.Join(u.Path, "packages.gz")
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("invalid status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
|
||||
scanner.Scan()
|
||||
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
if strings.HasPrefix(text, "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := io.WriteString(out, text+"\tAUR\n"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// createRepoList appends Repo packages to completion cache.
|
||||
func createRepoList(dbExecutor PkgSynchronizer, out io.Writer) error {
|
||||
for _, pkg := range dbExecutor.SyncPackages() {
|
||||
_, err := io.WriteString(out, pkg.Name()+"\t"+pkg.DB().Name()+"\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package completion
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const samplePackageResp = `
|
||||
# AUR package list, generated on Fri, 24 Jul 2020 22:05:22 GMT
|
||||
cytadela
|
||||
bitefusion
|
||||
globs-svn
|
||||
ri-li
|
||||
globs-benchmarks-svn
|
||||
dunelegacy
|
||||
lumina
|
||||
eternallands-sound
|
||||
`
|
||||
|
||||
const expectPackageCompletion = `cytadela AUR
|
||||
bitefusion AUR
|
||||
globs-svn AUR
|
||||
ri-li AUR
|
||||
globs-benchmarks-svn AUR
|
||||
dunelegacy AUR
|
||||
lumina AUR
|
||||
eternallands-sound AUR
|
||||
`
|
||||
|
||||
type mockDoer struct {
|
||||
t *testing.T
|
||||
returnBody string
|
||||
returnStatusCode int
|
||||
returnErr error
|
||||
wantUrl string
|
||||
}
|
||||
|
||||
func (m *mockDoer) Do(req *http.Request) (*http.Response, error) {
|
||||
assert.Equal(m.t, m.wantUrl, req.URL.String())
|
||||
return &http.Response{
|
||||
StatusCode: m.returnStatusCode,
|
||||
Body: io.NopCloser(bytes.NewBufferString(m.returnBody)),
|
||||
}, m.returnErr
|
||||
}
|
||||
|
||||
func Test_createAURList(t *testing.T) {
|
||||
t.Parallel()
|
||||
doer := &mockDoer{
|
||||
t: t,
|
||||
wantUrl: "https://aur.archlinux.org/packages.gz",
|
||||
returnStatusCode: 200,
|
||||
returnBody: samplePackageResp,
|
||||
returnErr: nil,
|
||||
}
|
||||
out := &bytes.Buffer{}
|
||||
err := createAURList(context.Background(), doer, "https://aur.archlinux.org", out)
|
||||
assert.NoError(t, err)
|
||||
gotOut := out.String()
|
||||
assert.Equal(t, expectPackageCompletion, gotOut)
|
||||
}
|
||||
|
||||
func Test_createAURListHTTPError(t *testing.T) {
|
||||
t.Parallel()
|
||||
doer := &mockDoer{
|
||||
t: t,
|
||||
wantUrl: "https://aur.archlinux.org/packages.gz",
|
||||
returnStatusCode: 200,
|
||||
returnBody: samplePackageResp,
|
||||
returnErr: errors.New("Not available"),
|
||||
}
|
||||
|
||||
out := &bytes.Buffer{}
|
||||
err := createAURList(context.Background(), doer, "https://aur.archlinux.org", out)
|
||||
assert.EqualError(t, err, "Not available")
|
||||
}
|
||||
|
||||
func Test_createAURListStatusError(t *testing.T) {
|
||||
t.Parallel()
|
||||
doer := &mockDoer{
|
||||
t: t,
|
||||
wantUrl: "https://aur.archlinux.org/packages.gz",
|
||||
returnStatusCode: 503,
|
||||
returnBody: samplePackageResp,
|
||||
returnErr: nil,
|
||||
}
|
||||
|
||||
out := &bytes.Buffer{}
|
||||
err := createAURList(context.Background(), doer, "https://aur.archlinux.org", out)
|
||||
assert.EqualError(t, err, "invalid status code: 503")
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type (
|
||||
IPackage = alpm.IPackage
|
||||
Depend = alpm.Depend
|
||||
)
|
||||
|
||||
// VerCmp performs version comparison according to Pacman conventions. Return
|
||||
// value is <0 if and only if v1 is older than v2.
|
||||
func VerCmp(v1, v2 string) int {
|
||||
return alpm.VerCmp(v1, v2)
|
||||
}
|
||||
|
||||
type Upgrade struct {
|
||||
Name string
|
||||
Base string
|
||||
Repository string
|
||||
LocalVersion string
|
||||
RemoteVersion string
|
||||
Reason alpm.PkgReason
|
||||
Extra string // Extra information to be displayed
|
||||
}
|
||||
|
||||
type SyncUpgrade struct {
|
||||
Package alpm.IPackage
|
||||
LocalVersion string
|
||||
Reason alpm.PkgReason
|
||||
}
|
||||
|
||||
type Executor interface {
|
||||
AlpmArchitectures() ([]string, error)
|
||||
BiggestPackages() []IPackage
|
||||
Cleanup()
|
||||
InstalledRemotePackageNames() []string
|
||||
InstalledRemotePackages() map[string]IPackage
|
||||
InstalledSyncPackageNames() []string
|
||||
IsCorrectVersionInstalled(string, string) bool
|
||||
LastBuildTime() time.Time
|
||||
LocalPackage(string) IPackage
|
||||
LocalPackages() []IPackage
|
||||
LocalSatisfierExists(string) bool
|
||||
PackageDepends(IPackage) []Depend
|
||||
PackageGroups(IPackage) []string
|
||||
PackageOptionalDepends(IPackage) []Depend
|
||||
PackageProvides(IPackage) []Depend
|
||||
PackagesFromGroup(string) []IPackage
|
||||
PackagesFromGroupAndDB(string, string) ([]IPackage, error)
|
||||
RefreshHandle() error
|
||||
SyncUpgrades(enableDowngrade bool) (
|
||||
map[string]SyncUpgrade, error)
|
||||
Repos() []string
|
||||
SatisfierFromDB(string, string) (IPackage, error)
|
||||
SyncPackage(string) IPackage
|
||||
SyncPackageFromDB(string, string) IPackage
|
||||
SyncPackages(...string) []IPackage
|
||||
SyncSatisfier(string) IPackage
|
||||
SyncSatisfierExists(string) bool
|
||||
|
||||
SetLogger(logger *text.Logger)
|
||||
}
|
@ -1,543 +0,0 @@
|
||||
package ialpm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
pacmanconf "github.com/Morganamilo/go-pacmanconf"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type AlpmExecutor struct {
|
||||
handle *alpm.Handle
|
||||
localDB alpm.IDB
|
||||
syncDB alpm.IDBList
|
||||
syncDBsCache []alpm.IDB
|
||||
conf *pacmanconf.Config
|
||||
log *text.Logger
|
||||
|
||||
installedRemotePkgNames []string
|
||||
installedRemotePkgMap map[string]alpm.IPackage
|
||||
installedSyncPkgNames []string
|
||||
}
|
||||
|
||||
func NewExecutor(pacmanConf *pacmanconf.Config, logger *text.Logger) (*AlpmExecutor, error) {
|
||||
ae := &AlpmExecutor{
|
||||
handle: nil,
|
||||
localDB: nil,
|
||||
syncDB: nil,
|
||||
syncDBsCache: []alpm.IDB{},
|
||||
conf: pacmanConf,
|
||||
log: logger,
|
||||
installedRemotePkgNames: nil,
|
||||
installedRemotePkgMap: nil,
|
||||
installedSyncPkgNames: nil,
|
||||
}
|
||||
|
||||
if err := ae.RefreshHandle(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var err error
|
||||
ae.localDB, err = ae.handle.LocalDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ae.syncDB, err = ae.handle.SyncDBs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ae, nil
|
||||
}
|
||||
|
||||
func toUsage(usages []string) alpm.Usage {
|
||||
if len(usages) == 0 {
|
||||
return alpm.UsageAll
|
||||
}
|
||||
|
||||
var ret alpm.Usage
|
||||
|
||||
for _, usage := range usages {
|
||||
switch usage {
|
||||
case "Sync":
|
||||
ret |= alpm.UsageSync
|
||||
case "Search":
|
||||
ret |= alpm.UsageSearch
|
||||
case "Install":
|
||||
ret |= alpm.UsageInstall
|
||||
case "Upgrade":
|
||||
ret |= alpm.UsageUpgrade
|
||||
case "All":
|
||||
ret |= alpm.UsageAll
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func configureAlpm(pacmanConf *pacmanconf.Config, alpmHandle *alpm.Handle) error {
|
||||
for _, repo := range pacmanConf.Repos {
|
||||
// TODO: set SigLevel
|
||||
alpmDB, err := alpmHandle.RegisterSyncDB(repo.Name, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
alpmDB.SetServers(repo.Servers)
|
||||
alpmDB.SetUsage(toUsage(repo.Usage))
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetCacheDirs(pacmanConf.CacheDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add hook directories 1-by-1 to avoid overwriting the system directory
|
||||
for _, dir := range pacmanConf.HookDir {
|
||||
if err := alpmHandle.AddHookDir(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetGPGDir(pacmanConf.GPGDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetLogFile(pacmanConf.LogFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetIgnorePkgs(pacmanConf.IgnorePkg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetIgnoreGroups(pacmanConf.IgnoreGroup); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmSetArchitecture(alpmHandle, pacmanConf.Architecture); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetNoUpgrades(pacmanConf.NoUpgrade); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetNoExtracts(pacmanConf.NoExtract); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := alpmHandle.SetUseSyslog(pacmanConf.UseSyslog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return alpmHandle.SetCheckSpace(pacmanConf.CheckSpace)
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) logCallback() func(level alpm.LogLevel, str string) {
|
||||
return func(level alpm.LogLevel, str string) {
|
||||
switch level {
|
||||
case alpm.LogWarning:
|
||||
ae.log.Warn(str)
|
||||
case alpm.LogError:
|
||||
ae.log.Error(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) questionCallback() func(question alpm.QuestionAny) {
|
||||
return func(question alpm.QuestionAny) {
|
||||
if qi, err := question.QuestionInstallIgnorepkg(); err == nil {
|
||||
qi.SetInstall(true)
|
||||
}
|
||||
|
||||
qp, err := question.QuestionSelectProvider()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if settings.HideMenus {
|
||||
return
|
||||
}
|
||||
|
||||
size := 0
|
||||
|
||||
_ = qp.Providers(ae.handle).ForEach(func(pkg alpm.IPackage) error {
|
||||
size++
|
||||
return nil
|
||||
})
|
||||
|
||||
str := text.Bold(gotext.Get("There are %[1]d providers available for %[2]s:", size, qp.Dep()))
|
||||
|
||||
size = 1
|
||||
|
||||
var dbName string
|
||||
|
||||
_ = qp.Providers(ae.handle).ForEach(func(pkg alpm.IPackage) error {
|
||||
thisDB := pkg.DB().Name()
|
||||
|
||||
if dbName != thisDB {
|
||||
dbName = thisDB
|
||||
str += "\n"
|
||||
str += ae.log.SprintOperationInfo(gotext.Get("Repository"), " ", dbName, "\n ")
|
||||
}
|
||||
str += fmt.Sprintf("%d) %s ", size, pkg.Name())
|
||||
size++
|
||||
return nil
|
||||
})
|
||||
|
||||
ae.log.OperationInfoln(str)
|
||||
|
||||
for {
|
||||
ae.log.Println(gotext.Get("\nEnter a number (default=1): "))
|
||||
|
||||
// TODO: reenable noconfirm
|
||||
if settings.NoConfirm {
|
||||
ae.log.Println()
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
numberBuf, err := ae.log.GetInput("", false)
|
||||
if err != nil {
|
||||
ae.log.Errorln(err)
|
||||
break
|
||||
}
|
||||
|
||||
if numberBuf == "" {
|
||||
break
|
||||
}
|
||||
|
||||
num, err := strconv.Atoi(numberBuf)
|
||||
if err != nil {
|
||||
ae.log.Errorln(gotext.Get("invalid number: %s", numberBuf))
|
||||
continue
|
||||
}
|
||||
|
||||
if num < 1 || num > size {
|
||||
ae.log.Errorln(gotext.Get("invalid value: %d is not between %d and %d", num, 1, size))
|
||||
continue
|
||||
}
|
||||
|
||||
qp.SetUseIndex(num - 1)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) RefreshHandle() error {
|
||||
if ae.handle != nil {
|
||||
if errRelease := ae.handle.Release(); errRelease != nil {
|
||||
return errRelease
|
||||
}
|
||||
}
|
||||
|
||||
alpmHandle, err := alpm.Initialize(ae.conf.RootDir, ae.conf.DBPath)
|
||||
if err != nil {
|
||||
return errors.New(gotext.Get("unable to CreateHandle: %s", err))
|
||||
}
|
||||
|
||||
if errConf := configureAlpm(ae.conf, alpmHandle); errConf != nil {
|
||||
return errConf
|
||||
}
|
||||
|
||||
alpmSetQuestionCallback(alpmHandle, ae.questionCallback())
|
||||
alpmSetLogCallback(alpmHandle, ae.logCallback())
|
||||
ae.handle = alpmHandle
|
||||
ae.syncDBsCache = nil
|
||||
|
||||
ae.syncDB, err = alpmHandle.SyncDBs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ae.localDB, err = alpmHandle.LocalDB()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) LocalSatisfierExists(pkgName string) bool {
|
||||
if _, err := ae.localDB.PkgCache().FindSatisfier(pkgName); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SyncSatisfierExists(pkgName string) bool {
|
||||
if _, err := ae.syncDB.FindSatisfier(pkgName); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) IsCorrectVersionInstalled(pkgName, versionRequired string) bool {
|
||||
alpmPackage := ae.localDB.Pkg(pkgName)
|
||||
if alpmPackage == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return alpmPackage.Version() == versionRequired
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SyncSatisfier(pkgName string) alpm.IPackage {
|
||||
foundPkg, err := ae.syncDB.FindSatisfier(pkgName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return foundPkg
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackagesFromGroup(groupName string) []alpm.IPackage {
|
||||
groupPackages := []alpm.IPackage{}
|
||||
_ = ae.syncDB.FindGroupPkgs(groupName).ForEach(func(pkg alpm.IPackage) error {
|
||||
groupPackages = append(groupPackages, pkg)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return groupPackages
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackagesFromGroupAndDB(groupName, dbName string) ([]alpm.IPackage, error) {
|
||||
singleDBList, err := ae.handle.SyncDBListByDBName(dbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupPackages := []alpm.IPackage{}
|
||||
_ = singleDBList.FindGroupPkgs(groupName).ForEach(func(pkg alpm.IPackage) error {
|
||||
groupPackages = append(groupPackages, pkg)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return groupPackages, nil
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) LocalPackages() []alpm.IPackage {
|
||||
localPackages := []alpm.IPackage{}
|
||||
_ = ae.localDB.PkgCache().ForEach(func(pkg alpm.IPackage) error {
|
||||
localPackages = append(localPackages, pkg)
|
||||
return nil
|
||||
})
|
||||
|
||||
return localPackages
|
||||
}
|
||||
|
||||
// SyncPackages searches SyncDB for packages or returns all packages if no search param is given.
|
||||
func (ae *AlpmExecutor) SyncPackages(pkgNames ...string) []alpm.IPackage {
|
||||
repoPackages := []alpm.IPackage{}
|
||||
_ = ae.syncDB.ForEach(func(alpmDB alpm.IDB) error {
|
||||
if len(pkgNames) == 0 {
|
||||
_ = alpmDB.PkgCache().ForEach(func(pkg alpm.IPackage) error {
|
||||
repoPackages = append(repoPackages, pkg)
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
_ = alpmDB.Search(pkgNames).ForEach(func(pkg alpm.IPackage) error {
|
||||
repoPackages = append(repoPackages, pkg)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return repoPackages
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) LocalPackage(pkgName string) alpm.IPackage {
|
||||
pkg := ae.localDB.Pkg(pkgName)
|
||||
if pkg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) syncDBs() []alpm.IDB {
|
||||
if ae.syncDBsCache == nil {
|
||||
ae.syncDBsCache = ae.syncDB.Slice()
|
||||
}
|
||||
|
||||
return ae.syncDBsCache
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SyncPackage(pkgName string) alpm.IPackage {
|
||||
for _, db := range ae.syncDBs() {
|
||||
if dbPkg := db.Pkg(pkgName); dbPkg != nil {
|
||||
return dbPkg
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SyncPackageFromDB(pkgName, dbName string) alpm.IPackage {
|
||||
singleDB, err := ae.handle.SyncDBByName(dbName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return singleDB.Pkg(pkgName)
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SatisfierFromDB(pkgName, dbName string) (alpm.IPackage, error) {
|
||||
singleDBList, err := ae.handle.SyncDBListByDBName(dbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
foundPkg, err := singleDBList.FindSatisfier(pkgName)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return foundPkg, nil
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageDepends(pkg alpm.IPackage) []alpm.Depend {
|
||||
alpmPackage := pkg.(*alpm.Package)
|
||||
return alpmPackage.Depends().Slice()
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageOptionalDepends(pkg alpm.IPackage) []alpm.Depend {
|
||||
alpmPackage := pkg.(*alpm.Package)
|
||||
return alpmPackage.OptionalDepends().Slice()
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageProvides(pkg alpm.IPackage) []alpm.Depend {
|
||||
alpmPackage := pkg.(*alpm.Package)
|
||||
return alpmPackage.Provides().Slice()
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageGroups(pkg alpm.IPackage) []string {
|
||||
alpmPackage := pkg.(*alpm.Package)
|
||||
return alpmPackage.Groups().Slice()
|
||||
}
|
||||
|
||||
// upRepo gathers local packages and checks if they have new versions.
|
||||
// Output: Upgrade type package list.
|
||||
func (ae *AlpmExecutor) SyncUpgrades(enableDowngrade bool) (
|
||||
map[string]db.SyncUpgrade, error,
|
||||
) {
|
||||
ups := map[string]db.SyncUpgrade{}
|
||||
var errReturn error
|
||||
|
||||
localDB, errDB := ae.handle.LocalDB()
|
||||
if errDB != nil {
|
||||
return ups, errDB
|
||||
}
|
||||
|
||||
if err := ae.handle.TransInit(alpm.TransFlagNoLock); err != nil {
|
||||
return ups, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
errReturn = ae.handle.TransRelease()
|
||||
}()
|
||||
|
||||
if err := ae.handle.SyncSysupgrade(enableDowngrade); err != nil {
|
||||
return ups, err
|
||||
}
|
||||
|
||||
_ = ae.handle.TransGetAdd().ForEach(func(pkg alpm.IPackage) error {
|
||||
localVer := "-"
|
||||
reason := alpm.PkgReasonExplicit
|
||||
|
||||
if localPkg := localDB.Pkg(pkg.Name()); localPkg != nil {
|
||||
localVer = localPkg.Version()
|
||||
reason = localPkg.Reason()
|
||||
}
|
||||
|
||||
ups[pkg.Name()] = db.SyncUpgrade{
|
||||
Package: pkg,
|
||||
Reason: reason,
|
||||
LocalVersion: localVer,
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return ups, errReturn
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) BiggestPackages() []alpm.IPackage {
|
||||
localPackages := []alpm.IPackage{}
|
||||
_ = ae.localDB.PkgCache().SortBySize().ForEach(func(pkg alpm.IPackage) error {
|
||||
localPackages = append(localPackages, pkg)
|
||||
return nil
|
||||
})
|
||||
|
||||
return localPackages
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) LastBuildTime() time.Time {
|
||||
var lastTime time.Time
|
||||
|
||||
_ = ae.syncDB.ForEach(func(db alpm.IDB) error {
|
||||
_ = db.PkgCache().ForEach(func(pkg alpm.IPackage) error {
|
||||
thisTime := pkg.BuildDate()
|
||||
if thisTime.After(lastTime) {
|
||||
lastTime = thisTime
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
||||
return lastTime
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) Cleanup() {
|
||||
if ae.handle != nil {
|
||||
if err := ae.handle.Release(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) Repos() (repos []string) {
|
||||
_ = ae.syncDB.ForEach(func(db alpm.IDB) error {
|
||||
repos = append(repos, db.Name())
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func alpmSetArchitecture(alpmHandle *alpm.Handle, arch []string) error {
|
||||
return alpmHandle.SetArchitectures(arch)
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) AlpmArchitectures() ([]string, error) {
|
||||
architectures, err := ae.handle.GetArchitectures()
|
||||
|
||||
return architectures.Slice(), err
|
||||
}
|
||||
|
||||
func alpmSetLogCallback(alpmHandle *alpm.Handle, cb func(alpm.LogLevel, string)) {
|
||||
alpmHandle.SetLogCallback(func(ctx interface{}, lvl alpm.LogLevel, msg string) {
|
||||
cbo := ctx.(func(alpm.LogLevel, string))
|
||||
cbo(lvl, msg)
|
||||
}, cb)
|
||||
}
|
||||
|
||||
func alpmSetQuestionCallback(alpmHandle *alpm.Handle, cb func(alpm.QuestionAny)) {
|
||||
alpmHandle.SetQuestionCallback(func(ctx interface{}, q alpm.QuestionAny) {
|
||||
cbo := ctx.(func(alpm.QuestionAny))
|
||||
cbo(q)
|
||||
}, cb)
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package ialpm
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func TestAlpmExecutor(t *testing.T) {
|
||||
t.Parallel()
|
||||
pacmanConf := &pacmanconf.Config{
|
||||
RootDir: "/",
|
||||
DBPath: "/var/lib/pacman/",
|
||||
CacheDir: []string{"/cachedir/", "/another/"},
|
||||
HookDir: []string{"/hookdir/"},
|
||||
GPGDir: "/gpgdir/",
|
||||
LogFile: "/logfile",
|
||||
HoldPkg: []string(nil),
|
||||
IgnorePkg: []string{"ignore", "this", "package"},
|
||||
IgnoreGroup: []string{"ignore", "this", "group"},
|
||||
Architecture: []string{"8086"},
|
||||
XferCommand: "",
|
||||
NoUpgrade: []string{"noupgrade"},
|
||||
NoExtract: []string{"noextract"},
|
||||
CleanMethod: []string{"KeepInstalled"},
|
||||
SigLevel: []string{"PackageOptional", "PackageTrustedOnly", "DatabaseOptional", "DatabaseTrustedOnly"},
|
||||
LocalFileSigLevel: []string(nil),
|
||||
RemoteFileSigLevel: []string(nil),
|
||||
UseSyslog: false,
|
||||
Color: false,
|
||||
UseDelta: 0,
|
||||
TotalDownload: true,
|
||||
CheckSpace: true,
|
||||
VerbosePkgLists: true,
|
||||
DisableDownloadTimeout: false,
|
||||
Repos: []pacmanconf.Repository{
|
||||
{Name: "repo1", Servers: []string{"repo1"}, SigLevel: []string(nil), Usage: []string{"All"}},
|
||||
{Name: "repo2", Servers: []string{"repo2"}, SigLevel: []string(nil), Usage: []string{"All"}},
|
||||
},
|
||||
}
|
||||
|
||||
aExec, err := NewExecutor(pacmanConf, text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), false, "test"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, aExec.conf)
|
||||
assert.EqualValues(t, pacmanConf, aExec.conf)
|
||||
|
||||
assert.NotNil(t, aExec.localDB)
|
||||
assert.NotNil(t, aExec.syncDB)
|
||||
assert.NotNil(t, aExec.questionCallback)
|
||||
h := aExec.handle
|
||||
assert.NotNil(t, h)
|
||||
|
||||
root, err := h.Root()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "/", root)
|
||||
|
||||
dbPath, err := h.DBPath()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "/var/lib/pacman/", dbPath)
|
||||
|
||||
cache, err := h.CacheDirs()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"/cachedir/", "/another/"}, cache.Slice())
|
||||
|
||||
log, err := h.LogFile()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "/logfile", log)
|
||||
|
||||
gpg, err := h.GPGDir()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "/gpgdir/", gpg)
|
||||
|
||||
hook, err := h.HookDirs()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"/usr/share/libalpm/hooks/", "/hookdir/"}, hook.Slice())
|
||||
|
||||
arch, err := alpmTestGetArch(h)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"8086"}, arch)
|
||||
|
||||
ignorePkg, err := h.IgnorePkgs()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"ignore", "this", "package"}, ignorePkg.Slice())
|
||||
|
||||
ignoreGroup, err := h.IgnoreGroups()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"ignore", "this", "group"}, ignoreGroup.Slice())
|
||||
|
||||
noUp, err := h.NoUpgrades()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"noupgrade"}, noUp.Slice())
|
||||
|
||||
noEx, err := h.NoExtracts()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"noextract"}, noEx.Slice())
|
||||
|
||||
check, err := h.CheckSpace()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, true, check)
|
||||
}
|
||||
|
||||
func alpmTestGetArch(h *alpm.Handle) ([]string, error) {
|
||||
architectures, err := h.GetArchitectures()
|
||||
|
||||
return architectures.Slice(), err
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package ialpm
|
||||
|
||||
import (
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
// GetPackageNamesBySource returns package names with and without correspondence in SyncDBS respectively.
|
||||
func (ae *AlpmExecutor) getPackageNamesBySource() {
|
||||
if ae.installedRemotePkgMap == nil {
|
||||
ae.installedRemotePkgMap = map[string]alpm.IPackage{}
|
||||
}
|
||||
for _, localpkg := range ae.LocalPackages() {
|
||||
pkgName := localpkg.Name()
|
||||
if ae.SyncPackage(pkgName) != nil {
|
||||
ae.installedSyncPkgNames = append(ae.installedSyncPkgNames, pkgName)
|
||||
} else {
|
||||
ae.installedRemotePkgNames = append(ae.installedRemotePkgNames, pkgName)
|
||||
ae.installedRemotePkgMap[pkgName] = localpkg
|
||||
}
|
||||
}
|
||||
|
||||
ae.log.Debugln("populating db executor package caches.",
|
||||
"sync_len", len(ae.installedSyncPkgNames), "remote_len", len(ae.installedRemotePkgNames))
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) InstalledRemotePackages() map[string]alpm.IPackage {
|
||||
if ae.installedRemotePkgMap == nil {
|
||||
ae.getPackageNamesBySource()
|
||||
}
|
||||
|
||||
return ae.installedRemotePkgMap
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) InstalledRemotePackageNames() []string {
|
||||
if ae.installedRemotePkgNames == nil {
|
||||
ae.getPackageNamesBySource()
|
||||
}
|
||||
|
||||
return ae.installedRemotePkgNames
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) InstalledSyncPackageNames() []string {
|
||||
if ae.installedSyncPkgNames == nil {
|
||||
ae.getPackageNamesBySource()
|
||||
}
|
||||
|
||||
return ae.installedSyncPkgNames
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SetLogger(logger *text.Logger) {
|
||||
ae.log = logger
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
IPackage = alpm.IPackage
|
||||
Depend = alpm.Depend
|
||||
Upgrade = db.Upgrade
|
||||
)
|
||||
|
||||
type DBExecutor struct {
|
||||
db.Executor
|
||||
AlpmArchitecturesFn func() ([]string, error)
|
||||
InstalledRemotePackageNamesFn func() []string
|
||||
InstalledRemotePackagesFn func() map[string]IPackage
|
||||
IsCorrectVersionInstalledFn func(string, string) bool
|
||||
LocalPackageFn func(string) IPackage
|
||||
LocalPackagesFn func() []IPackage
|
||||
LocalSatisfierExistsFn func(string) bool
|
||||
PackageDependsFn func(IPackage) []Depend
|
||||
PackageOptionalDependsFn func(alpm.IPackage) []alpm.Depend
|
||||
PackageProvidesFn func(IPackage) []Depend
|
||||
PackagesFromGroupFn func(string) []IPackage
|
||||
PackagesFromGroupAndDBFn func(string, string) ([]IPackage, error)
|
||||
RefreshHandleFn func() error
|
||||
ReposFn func() []string
|
||||
SyncPackageFn func(string) IPackage
|
||||
SyncPackagesFn func(...string) []IPackage
|
||||
SyncSatisfierFn func(string) IPackage
|
||||
SatisfierFromDBFn func(string, string) (IPackage, error)
|
||||
SyncUpgradesFn func(bool) (map[string]db.SyncUpgrade, error)
|
||||
SetLoggerFn func(*text.Logger)
|
||||
}
|
||||
|
||||
func (t *DBExecutor) InstalledRemotePackageNames() []string {
|
||||
if t.InstalledRemotePackageNamesFn != nil {
|
||||
return t.InstalledRemotePackageNamesFn()
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) InstalledRemotePackages() map[string]IPackage {
|
||||
if t.InstalledRemotePackagesFn != nil {
|
||||
return t.InstalledRemotePackagesFn()
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) AlpmArchitectures() ([]string, error) {
|
||||
if t.AlpmArchitecturesFn != nil {
|
||||
return t.AlpmArchitecturesFn()
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) BiggestPackages() []IPackage {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) Cleanup() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) IsCorrectVersionInstalled(s, s2 string) bool {
|
||||
if t.IsCorrectVersionInstalledFn != nil {
|
||||
return t.IsCorrectVersionInstalledFn(s, s2)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) LastBuildTime() time.Time {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) LocalPackage(s string) IPackage {
|
||||
if t.LocalPackageFn != nil {
|
||||
return t.LocalPackageFn(s)
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) LocalPackages() []IPackage {
|
||||
if t.LocalPackagesFn != nil {
|
||||
return t.LocalPackagesFn()
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) LocalSatisfierExists(s string) bool {
|
||||
if t.LocalSatisfierExistsFn != nil {
|
||||
return t.LocalSatisfierExistsFn(s)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackageConflicts(iPackage IPackage) []Depend {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackageDepends(iPackage IPackage) []Depend {
|
||||
if t.PackageDependsFn != nil {
|
||||
return t.PackageDependsFn(iPackage)
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackageGroups(iPackage IPackage) []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackageOptionalDepends(iPackage IPackage) []Depend {
|
||||
if t.PackageOptionalDependsFn != nil {
|
||||
return t.PackageOptionalDependsFn(iPackage)
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackageProvides(iPackage IPackage) []Depend {
|
||||
if t.PackageProvidesFn != nil {
|
||||
return t.PackageProvidesFn(iPackage)
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackagesFromGroup(s string) []IPackage {
|
||||
if t.PackagesFromGroupFn != nil {
|
||||
return t.PackagesFromGroupFn(s)
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) PackagesFromGroupAndDB(s, s2 string) ([]IPackage, error) {
|
||||
if t.PackagesFromGroupAndDBFn != nil {
|
||||
return t.PackagesFromGroupAndDBFn(s, s2)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) RefreshHandle() error {
|
||||
if t.RefreshHandleFn != nil {
|
||||
return t.RefreshHandleFn()
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SyncUpgrades(b bool) (map[string]db.SyncUpgrade, error) {
|
||||
if t.SyncUpgradesFn != nil {
|
||||
return t.SyncUpgradesFn(b)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) Repos() []string {
|
||||
if t.ReposFn != nil {
|
||||
return t.ReposFn()
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SatisfierFromDB(s, s2 string) (IPackage, error) {
|
||||
if t.SatisfierFromDBFn != nil {
|
||||
return t.SatisfierFromDBFn(s, s2)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SyncPackage(s string) IPackage {
|
||||
if t.SyncPackageFn != nil {
|
||||
return t.SyncPackageFn(s)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SyncPackages(s ...string) []IPackage {
|
||||
if t.SyncPackagesFn != nil {
|
||||
return t.SyncPackagesFn(s...)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SyncSatisfier(s string) IPackage {
|
||||
if t.SyncSatisfierFn != nil {
|
||||
return t.SyncSatisfierFn(s)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SyncSatisfierExists(s string) bool {
|
||||
if t.SyncSatisfierFn != nil {
|
||||
return t.SyncSatisfierFn(s) != nil
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SetLogger(logger *text.Logger) {
|
||||
if t.SetLoggerFn != nil {
|
||||
t.SetLoggerFn(logger)
|
||||
return
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
@ -1,229 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
|
||||
type DependList struct {
|
||||
Depends []Depend
|
||||
}
|
||||
|
||||
func (d DependList) Slice() []alpm.Depend {
|
||||
return d.Depends
|
||||
}
|
||||
|
||||
func (d DependList) ForEach(f func(*alpm.Depend) error) error {
|
||||
for i := range d.Depends {
|
||||
dep := &d.Depends[i]
|
||||
err := f(dep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type Package struct {
|
||||
PBase string
|
||||
PBuildDate time.Time
|
||||
PDB *DB
|
||||
PDescription string
|
||||
PISize int64
|
||||
PName string
|
||||
PShouldIgnore bool
|
||||
PSize int64
|
||||
PVersion string
|
||||
PReason alpm.PkgReason
|
||||
PDepends alpm.IDependList
|
||||
PProvides alpm.IDependList
|
||||
}
|
||||
|
||||
func (p *Package) Base() string {
|
||||
return p.PBase
|
||||
}
|
||||
|
||||
func (p *Package) BuildDate() time.Time {
|
||||
return p.PBuildDate
|
||||
}
|
||||
|
||||
func (p *Package) DB() alpm.IDB {
|
||||
return p.PDB
|
||||
}
|
||||
|
||||
func (p *Package) Description() string {
|
||||
return p.PDescription
|
||||
}
|
||||
|
||||
func (p *Package) ISize() int64 {
|
||||
return p.PISize
|
||||
}
|
||||
|
||||
func (p *Package) Name() string {
|
||||
return p.PName
|
||||
}
|
||||
|
||||
func (p *Package) ShouldIgnore() bool {
|
||||
return p.PShouldIgnore
|
||||
}
|
||||
|
||||
func (p *Package) Size() int64 {
|
||||
return p.PSize
|
||||
}
|
||||
|
||||
func (p *Package) Version() string {
|
||||
return p.PVersion
|
||||
}
|
||||
|
||||
func (p *Package) Reason() alpm.PkgReason {
|
||||
return p.PReason
|
||||
}
|
||||
|
||||
func (p *Package) FileName() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (p *Package) Base64Signature() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (p *Package) Validation() alpm.Validation {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Architecture returns the package target Architecture.
|
||||
func (p *Package) Architecture() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Backup returns a list of package backups.
|
||||
func (p *Package) Backup() alpm.BackupList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Conflicts returns the conflicts of the package as a DependList.
|
||||
func (p *Package) Conflicts() alpm.IDependList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Depends returns the package's dependency list.
|
||||
func (p *Package) Depends() alpm.IDependList {
|
||||
if p.PDepends != nil {
|
||||
return p.PDepends
|
||||
}
|
||||
return alpm.DependList{}
|
||||
}
|
||||
|
||||
// Depends returns the package's optional dependency list.
|
||||
func (p *Package) OptionalDepends() alpm.IDependList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Depends returns the package's check dependency list.
|
||||
func (p *Package) CheckDepends() alpm.IDependList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Depends returns the package's make dependency list.
|
||||
func (p *Package) MakeDepends() alpm.IDependList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Files returns the file list of the package.
|
||||
func (p *Package) Files() []alpm.File {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// ContainsFile checks if the path is in the package filelist.
|
||||
func (p *Package) ContainsFile(path string) (alpm.File, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Groups returns the groups the package belongs to.
|
||||
func (p *Package) Groups() alpm.StringList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// InstallDate returns the package install date.
|
||||
func (p *Package) InstallDate() time.Time {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Licenses returns the package license list.
|
||||
func (p *Package) Licenses() alpm.StringList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// SHA256Sum returns package SHA256Sum.
|
||||
func (p *Package) SHA256Sum() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// MD5Sum returns package MD5Sum.
|
||||
func (p *Package) MD5Sum() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Packager returns package packager name.
|
||||
func (p *Package) Packager() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Provides returns DependList of packages provides by package.
|
||||
func (p *Package) Provides() alpm.IDependList {
|
||||
if p.PProvides == nil {
|
||||
return alpm.DependList{}
|
||||
}
|
||||
return p.PProvides
|
||||
}
|
||||
|
||||
// Origin returns package origin.
|
||||
func (p *Package) Origin() alpm.PkgFrom {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Replaces returns a DependList with the packages this package replaces.
|
||||
func (p *Package) Replaces() alpm.IDependList {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// URL returns the upstream URL of the package.
|
||||
func (p *Package) URL() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// ComputeRequiredBy returns the names of reverse dependencies of a package.
|
||||
func (p *Package) ComputeRequiredBy() []string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// ComputeOptionalFor returns the names of packages that optionally
|
||||
// require the given package.
|
||||
func (p *Package) ComputeOptionalFor() []string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// SyncNewVersion checks if there is a new version of the
|
||||
// package in a given DBlist.
|
||||
func (p *Package) SyncNewVersion(l alpm.IDBList) alpm.IPackage {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (p *Package) Type() string {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
type DB struct {
|
||||
alpm.IDB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewDB(name string) *DB {
|
||||
return &DB{name: name}
|
||||
}
|
||||
|
||||
func (d *DB) Name() string {
|
||||
return d.name
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package db
|
||||
|
||||
func ArchIsSupported(alpmArch []string, arch string) bool {
|
||||
if arch == "any" {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, a := range alpmArch {
|
||||
if a == arch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
aur "github.com/Jguer/yay/v12/pkg/query"
|
||||
)
|
||||
|
||||
func splitDep(dep string) (pkg, mod, ver string) {
|
||||
split := strings.FieldsFunc(dep, func(c rune) bool {
|
||||
match := c == '>' || c == '<' || c == '='
|
||||
|
||||
if match {
|
||||
mod += string(c)
|
||||
}
|
||||
|
||||
return match
|
||||
})
|
||||
|
||||
if len(split) == 0 {
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
if len(split) == 1 {
|
||||
return split[0], "", ""
|
||||
}
|
||||
|
||||
return split[0], mod, split[1]
|
||||
}
|
||||
|
||||
func pkgSatisfies(name, version, dep string) bool {
|
||||
depName, depMod, depVersion := splitDep(dep)
|
||||
|
||||
if depName != name {
|
||||
return false
|
||||
}
|
||||
|
||||
return verSatisfies(version, depMod, depVersion)
|
||||
}
|
||||
|
||||
func provideSatisfies(provide, dep, pkgVersion string) bool {
|
||||
depName, depMod, depVersion := splitDep(dep)
|
||||
provideName, provideMod, provideVersion := splitDep(provide)
|
||||
|
||||
if provideName != depName {
|
||||
return false
|
||||
}
|
||||
|
||||
// Unversioned provides can not satisfy a versioned dep
|
||||
if provideMod == "" && depMod != "" {
|
||||
provideVersion = pkgVersion // Example package: pagure
|
||||
}
|
||||
|
||||
return verSatisfies(provideVersion, depMod, depVersion)
|
||||
}
|
||||
|
||||
func verSatisfies(ver1, mod, ver2 string) bool {
|
||||
switch mod {
|
||||
case "=":
|
||||
return db.VerCmp(ver1, ver2) == 0
|
||||
case "<":
|
||||
return db.VerCmp(ver1, ver2) < 0
|
||||
case "<=":
|
||||
return db.VerCmp(ver1, ver2) <= 0
|
||||
case ">":
|
||||
return db.VerCmp(ver1, ver2) > 0
|
||||
case ">=":
|
||||
return db.VerCmp(ver1, ver2) >= 0
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func satisfiesAur(dep string, pkg *aur.Pkg) bool {
|
||||
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, provide := range pkg.Provides {
|
||||
if provideSatisfies(provide, dep, pkg.Version) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -1,853 +0,0 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
aurc "github.com/Jguer/aur"
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/dep/topo"
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
aur "github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type InstallInfo struct {
|
||||
Source Source
|
||||
Reason Reason
|
||||
Version string
|
||||
LocalVersion string
|
||||
SrcinfoPath *string
|
||||
AURBase *string
|
||||
SyncDBName *string
|
||||
|
||||
IsGroup bool
|
||||
Upgrade bool
|
||||
Devel bool
|
||||
}
|
||||
|
||||
func (i *InstallInfo) String() string {
|
||||
return fmt.Sprintf("InstallInfo{Source: %v, Reason: %v}", i.Source, i.Reason)
|
||||
}
|
||||
|
||||
type (
|
||||
Reason uint
|
||||
Source int
|
||||
)
|
||||
|
||||
func (r Reason) String() string {
|
||||
return ReasonNames[r]
|
||||
}
|
||||
|
||||
func (s Source) String() string {
|
||||
return SourceNames[s]
|
||||
}
|
||||
|
||||
const (
|
||||
Explicit Reason = iota // 0
|
||||
Dep // 1
|
||||
MakeDep // 2
|
||||
CheckDep // 3
|
||||
)
|
||||
|
||||
var ReasonNames = map[Reason]string{
|
||||
Explicit: gotext.Get("Explicit"),
|
||||
Dep: gotext.Get("Dependency"),
|
||||
MakeDep: gotext.Get("Make Dependency"),
|
||||
CheckDep: gotext.Get("Check Dependency"),
|
||||
}
|
||||
|
||||
const (
|
||||
AUR Source = iota
|
||||
Sync
|
||||
Local
|
||||
SrcInfo
|
||||
Missing
|
||||
)
|
||||
|
||||
var SourceNames = map[Source]string{
|
||||
AUR: gotext.Get("AUR"),
|
||||
Sync: gotext.Get("Sync"),
|
||||
Local: gotext.Get("Local"),
|
||||
SrcInfo: gotext.Get("SRCINFO"),
|
||||
Missing: gotext.Get("Missing"),
|
||||
}
|
||||
|
||||
var bgColorMap = map[Source]string{
|
||||
AUR: "lightblue",
|
||||
Sync: "lemonchiffon",
|
||||
Local: "darkolivegreen1",
|
||||
Missing: "tomato",
|
||||
}
|
||||
|
||||
var colorMap = map[Reason]string{
|
||||
Explicit: "black",
|
||||
Dep: "deeppink",
|
||||
MakeDep: "navyblue",
|
||||
CheckDep: "forestgreen",
|
||||
}
|
||||
|
||||
type Grapher struct {
|
||||
logger *text.Logger
|
||||
providerCache map[string][]aur.Pkg
|
||||
|
||||
dbExecutor db.Executor
|
||||
aurClient aurc.QueryClient
|
||||
fullGraph bool // If true, the graph will include all dependencies including already installed ones or repo
|
||||
noConfirm bool // If true, the graph will not prompt for confirmation
|
||||
noDeps bool // If true, the graph will not include dependencies
|
||||
noCheckDeps bool // If true, the graph will not include check dependencies
|
||||
needed bool // If true, the graph will only include packages that are not installed
|
||||
}
|
||||
|
||||
func NewGrapher(dbExecutor db.Executor, aurCache aurc.QueryClient,
|
||||
fullGraph, noConfirm, noDeps, noCheckDeps, needed bool,
|
||||
logger *text.Logger,
|
||||
) *Grapher {
|
||||
return &Grapher{
|
||||
dbExecutor: dbExecutor,
|
||||
aurClient: aurCache,
|
||||
fullGraph: fullGraph,
|
||||
noConfirm: noConfirm,
|
||||
noDeps: noDeps,
|
||||
noCheckDeps: noCheckDeps,
|
||||
needed: needed,
|
||||
providerCache: make(map[string][]aurc.Pkg, 5),
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func NewGraph() *topo.Graph[string, *InstallInfo] {
|
||||
return topo.New[string, *InstallInfo]()
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphFromTargets(ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo], targets []string,
|
||||
) (*topo.Graph[string, *InstallInfo], error) {
|
||||
if graph == nil {
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
aurTargets := make([]string, 0, len(targets))
|
||||
|
||||
for _, targetString := range targets {
|
||||
target := ToTarget(targetString)
|
||||
|
||||
switch target.DB {
|
||||
case "": // unspecified db
|
||||
if pkg := g.dbExecutor.SyncSatisfier(target.Name); pkg != nil {
|
||||
g.GraphSyncPkg(ctx, graph, pkg, nil)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
groupPackages := g.dbExecutor.PackagesFromGroup(target.Name)
|
||||
if len(groupPackages) > 0 {
|
||||
dbName := groupPackages[0].DB().Name()
|
||||
g.GraphSyncGroup(ctx, graph, target.Name, dbName)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
fallthrough
|
||||
case "aur":
|
||||
aurTargets = append(aurTargets, target.Name)
|
||||
default:
|
||||
pkg, err := g.dbExecutor.SatisfierFromDB(target.Name, target.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pkg != nil {
|
||||
g.GraphSyncPkg(ctx, graph, pkg, nil)
|
||||
continue
|
||||
}
|
||||
|
||||
groupPackages, err := g.dbExecutor.PackagesFromGroupAndDB(target.Name, target.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(groupPackages) > 0 {
|
||||
g.GraphSyncGroup(ctx, graph, target.Name, target.DB)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
g.logger.Errorln(gotext.Get("No package found for"), " ", target)
|
||||
}
|
||||
}
|
||||
|
||||
var errA error
|
||||
graph, errA = g.GraphFromAUR(ctx, graph, aurTargets)
|
||||
if errA != nil {
|
||||
return nil, errA
|
||||
}
|
||||
|
||||
return graph, nil
|
||||
}
|
||||
|
||||
func (g *Grapher) pickSrcInfoPkgs(pkgs []*aurc.Pkg) ([]*aurc.Pkg, error) {
|
||||
final := make([]*aurc.Pkg, 0, len(pkgs))
|
||||
for i := range pkgs {
|
||||
g.logger.Println(text.Magenta(strconv.Itoa(i+1)+" ") + text.Bold(pkgs[i].Name) +
|
||||
" " + text.Cyan(pkgs[i].Version))
|
||||
g.logger.Println(" " + pkgs[i].Description)
|
||||
}
|
||||
g.logger.Infoln(gotext.Get("Packages to exclude") + " (eg: \"1 2 3\", \"1-3\", \"^4\"):")
|
||||
|
||||
numberBuf, err := g.logger.GetInput("", g.noConfirm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
include, exclude, _, otherExclude := intrange.ParseNumberMenu(numberBuf)
|
||||
isInclude := len(exclude) == 0 && otherExclude.Cardinality() == 0
|
||||
|
||||
for i := 1; i <= len(pkgs); i++ {
|
||||
target := i - 1
|
||||
|
||||
if isInclude && !include.Get(i) {
|
||||
final = append(final, pkgs[target])
|
||||
}
|
||||
|
||||
if !isInclude && (exclude.Get(i)) {
|
||||
final = append(final, pkgs[target])
|
||||
}
|
||||
}
|
||||
|
||||
return final, nil
|
||||
}
|
||||
|
||||
func (g *Grapher) addAurPkgProvides(pkg *aurc.Pkg, graph *topo.Graph[string, *InstallInfo]) {
|
||||
for i := range pkg.Provides {
|
||||
depName, mod, version := splitDep(pkg.Provides[i])
|
||||
g.logger.Debugln(pkg.String() + " provides: " + depName)
|
||||
graph.Provides(depName, &alpm.Depend{
|
||||
Name: depName,
|
||||
Version: version,
|
||||
Mod: aurDepModToAlpmDep(mod),
|
||||
}, pkg.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphFromSrcInfos(ctx context.Context, graph *topo.Graph[string, *InstallInfo],
|
||||
srcInfos map[string]*gosrc.Srcinfo,
|
||||
) (*topo.Graph[string, *InstallInfo], error) {
|
||||
if graph == nil {
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
aurPkgsAdded := []*aurc.Pkg{}
|
||||
for pkgBuildDir, pkgbuild := range srcInfos {
|
||||
pkgBuildDir := pkgBuildDir
|
||||
|
||||
aurPkgs, err := makeAURPKGFromSrcinfo(g.dbExecutor, pkgbuild)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(aurPkgs) > 1 {
|
||||
var errPick error
|
||||
aurPkgs, errPick = g.pickSrcInfoPkgs(aurPkgs)
|
||||
if errPick != nil {
|
||||
return nil, errPick
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range aurPkgs {
|
||||
pkg := pkg
|
||||
|
||||
reason := Explicit
|
||||
if pkg := g.dbExecutor.LocalPackage(pkg.Name); pkg != nil {
|
||||
reason = Reason(pkg.Reason())
|
||||
}
|
||||
|
||||
graph.AddNode(pkg.Name)
|
||||
|
||||
g.addAurPkgProvides(pkg, graph)
|
||||
|
||||
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[reason],
|
||||
Background: bgColorMap[AUR],
|
||||
Value: &InstallInfo{
|
||||
Source: SrcInfo,
|
||||
Reason: reason,
|
||||
SrcinfoPath: &pkgBuildDir,
|
||||
AURBase: &pkg.PackageBase,
|
||||
Version: pkg.Version,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
aurPkgsAdded = append(aurPkgsAdded, aurPkgs...)
|
||||
}
|
||||
|
||||
g.AddDepsForPkgs(ctx, aurPkgsAdded, graph)
|
||||
|
||||
return graph, nil
|
||||
}
|
||||
|
||||
func (g *Grapher) AddDepsForPkgs(ctx context.Context, pkgs []*aur.Pkg, graph *topo.Graph[string, *InstallInfo]) {
|
||||
for _, pkg := range pkgs {
|
||||
g.addDepNodes(ctx, pkg, graph)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Grapher) addDepNodes(ctx context.Context, pkg *aur.Pkg, graph *topo.Graph[string, *InstallInfo]) {
|
||||
if len(pkg.MakeDepends) > 0 {
|
||||
g.addNodes(ctx, graph, pkg.Name, pkg.MakeDepends, MakeDep)
|
||||
}
|
||||
|
||||
if !g.noDeps && len(pkg.Depends) > 0 {
|
||||
g.addNodes(ctx, graph, pkg.Name, pkg.Depends, Dep)
|
||||
}
|
||||
|
||||
if !g.noCheckDeps && !g.noDeps && len(pkg.CheckDepends) > 0 {
|
||||
g.addNodes(ctx, graph, pkg.Name, pkg.CheckDepends, CheckDep)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphSyncPkg(ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo],
|
||||
pkg alpm.IPackage, upgradeInfo *db.SyncUpgrade,
|
||||
) *topo.Graph[string, *InstallInfo] {
|
||||
if graph == nil {
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
graph.AddNode(pkg.Name())
|
||||
_ = pkg.Provides().ForEach(func(p *alpm.Depend) error {
|
||||
g.logger.Debugln(pkg.Name() + " provides: " + p.String())
|
||||
graph.Provides(p.Name, p, pkg.Name())
|
||||
return nil
|
||||
})
|
||||
|
||||
dbName := pkg.DB().Name()
|
||||
info := &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: pkg.Version(),
|
||||
SyncDBName: &dbName,
|
||||
}
|
||||
|
||||
if upgradeInfo == nil {
|
||||
if localPkg := g.dbExecutor.LocalPackage(pkg.Name()); localPkg != nil {
|
||||
info.Reason = Reason(localPkg.Reason())
|
||||
}
|
||||
} else {
|
||||
info.Upgrade = true
|
||||
info.Reason = Reason(upgradeInfo.Reason)
|
||||
info.LocalVersion = upgradeInfo.LocalVersion
|
||||
}
|
||||
|
||||
g.ValidateAndSetNodeInfo(graph, pkg.Name(), &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[info.Reason],
|
||||
Background: bgColorMap[info.Source],
|
||||
Value: info,
|
||||
})
|
||||
|
||||
return graph
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphSyncGroup(ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo],
|
||||
groupName, dbName string,
|
||||
) *topo.Graph[string, *InstallInfo] {
|
||||
if graph == nil {
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
graph.AddNode(groupName)
|
||||
|
||||
g.ValidateAndSetNodeInfo(graph, groupName, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[Explicit],
|
||||
Background: bgColorMap[Sync],
|
||||
Value: &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: "",
|
||||
SyncDBName: &dbName,
|
||||
IsGroup: true,
|
||||
},
|
||||
})
|
||||
|
||||
return graph
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphAURTarget(ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo],
|
||||
pkg *aurc.Pkg, instalInfo *InstallInfo,
|
||||
) *topo.Graph[string, *InstallInfo] {
|
||||
if graph == nil {
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
graph.AddNode(pkg.Name)
|
||||
|
||||
g.addAurPkgProvides(pkg, graph)
|
||||
|
||||
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[instalInfo.Reason],
|
||||
Background: bgColorMap[AUR],
|
||||
Value: instalInfo,
|
||||
})
|
||||
|
||||
return graph
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphFromAUR(ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo],
|
||||
targets []string,
|
||||
) (*topo.Graph[string, *InstallInfo], error) {
|
||||
if graph == nil {
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
if len(targets) == 0 {
|
||||
return graph, nil
|
||||
}
|
||||
|
||||
aurPkgs, errCache := g.aurClient.Get(ctx, &aurc.Query{By: aurc.Name, Needles: targets})
|
||||
if errCache != nil {
|
||||
g.logger.Errorln(errCache)
|
||||
}
|
||||
|
||||
for i := range aurPkgs {
|
||||
pkg := &aurPkgs[i]
|
||||
if _, ok := g.providerCache[pkg.Name]; !ok {
|
||||
g.providerCache[pkg.Name] = []aurc.Pkg{*pkg}
|
||||
}
|
||||
}
|
||||
|
||||
aurPkgsAdded := []*aurc.Pkg{}
|
||||
|
||||
for _, target := range targets {
|
||||
if cachedProvidePkg, ok := g.providerCache[target]; ok {
|
||||
aurPkgs = cachedProvidePkg
|
||||
} else {
|
||||
var errA error
|
||||
aurPkgs, errA = g.aurClient.Get(ctx, &aurc.Query{By: aurc.Provides, Needles: []string{target}, Contains: true})
|
||||
if errA != nil {
|
||||
g.logger.Errorln(gotext.Get("Failed to find AUR package for"), " ", target, ":", errA)
|
||||
}
|
||||
}
|
||||
|
||||
if len(aurPkgs) == 0 {
|
||||
g.logger.Errorln(gotext.Get("No AUR package found for"), " ", target)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
aurPkg := &aurPkgs[0]
|
||||
if len(aurPkgs) > 1 {
|
||||
chosen := g.provideMenu(target, aurPkgs)
|
||||
aurPkg = chosen
|
||||
g.providerCache[target] = []aurc.Pkg{*aurPkg}
|
||||
}
|
||||
|
||||
reason := Explicit
|
||||
if pkg := g.dbExecutor.LocalPackage(aurPkg.Name); pkg != nil {
|
||||
reason = Reason(pkg.Reason())
|
||||
|
||||
if g.needed {
|
||||
if db.VerCmp(pkg.Version(), aurPkg.Version) >= 0 {
|
||||
g.logger.Warnln(gotext.Get("%s is up to date -- skipping", text.Cyan(pkg.Name()+"-"+pkg.Version())))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
graph = g.GraphAURTarget(ctx, graph, aurPkg, &InstallInfo{
|
||||
AURBase: &aurPkg.PackageBase,
|
||||
Reason: reason,
|
||||
Source: AUR,
|
||||
Version: aurPkg.Version,
|
||||
})
|
||||
aurPkgsAdded = append(aurPkgsAdded, aurPkg)
|
||||
}
|
||||
|
||||
g.AddDepsForPkgs(ctx, aurPkgsAdded, graph)
|
||||
|
||||
return graph, nil
|
||||
}
|
||||
|
||||
// Removes found deps from the deps mapset and returns the found deps.
|
||||
func (g *Grapher) findDepsFromAUR(ctx context.Context,
|
||||
deps mapset.Set[string],
|
||||
) []aurc.Pkg {
|
||||
pkgsToAdd := make([]aurc.Pkg, 0, deps.Cardinality())
|
||||
if deps.Cardinality() == 0 {
|
||||
return []aurc.Pkg{}
|
||||
}
|
||||
|
||||
missingNeedles := make([]string, 0, deps.Cardinality())
|
||||
for _, depString := range deps.ToSlice() {
|
||||
if _, ok := g.providerCache[depString]; !ok {
|
||||
depName, _, _ := splitDep(depString)
|
||||
missingNeedles = append(missingNeedles, depName)
|
||||
}
|
||||
}
|
||||
|
||||
if len(missingNeedles) != 0 {
|
||||
g.logger.Debugln("deps to find", missingNeedles)
|
||||
// provider search is more demanding than a simple search
|
||||
// try to find name match if possible and then try to find provides.
|
||||
aurPkgs, errCache := g.aurClient.Get(ctx, &aurc.Query{
|
||||
By: aurc.Name, Needles: missingNeedles, Contains: false,
|
||||
})
|
||||
if errCache != nil {
|
||||
g.logger.Errorln(errCache)
|
||||
}
|
||||
|
||||
for i := range aurPkgs {
|
||||
pkg := &aurPkgs[i]
|
||||
if deps.Contains(pkg.Name) {
|
||||
g.providerCache[pkg.Name] = append(g.providerCache[pkg.Name], *pkg)
|
||||
}
|
||||
|
||||
for _, val := range pkg.Provides {
|
||||
if val == pkg.Name {
|
||||
continue
|
||||
}
|
||||
if deps.Contains(val) {
|
||||
g.providerCache[val] = append(g.providerCache[val], *pkg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, depString := range deps.ToSlice() {
|
||||
var aurPkgs []aurc.Pkg
|
||||
depName, _, _ := splitDep(depString)
|
||||
|
||||
if cachedProvidePkg, ok := g.providerCache[depString]; ok {
|
||||
aurPkgs = cachedProvidePkg
|
||||
} else {
|
||||
var errA error
|
||||
aurPkgs, errA = g.aurClient.Get(ctx, &aurc.Query{By: aurc.Provides, Needles: []string{depName}, Contains: true})
|
||||
if errA != nil {
|
||||
g.logger.Errorln(gotext.Get("Failed to find AUR package for"), depString, ":", errA)
|
||||
}
|
||||
}
|
||||
|
||||
// remove packages that don't satisfy the dependency
|
||||
satisfyingPkgs := make([]aurc.Pkg, 0, len(aurPkgs))
|
||||
for i := range aurPkgs {
|
||||
if satisfiesAur(depString, &aurPkgs[i]) {
|
||||
satisfyingPkgs = append(satisfyingPkgs, aurPkgs[i])
|
||||
}
|
||||
}
|
||||
aurPkgs = satisfyingPkgs
|
||||
|
||||
if len(aurPkgs) == 0 {
|
||||
g.logger.Errorln(gotext.Get("No AUR package found for"), " ", depString)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
pkg := aurPkgs[0]
|
||||
if len(aurPkgs) > 1 {
|
||||
chosen := g.provideMenu(depString, aurPkgs)
|
||||
pkg = *chosen
|
||||
}
|
||||
|
||||
g.providerCache[depString] = []aurc.Pkg{pkg}
|
||||
deps.Remove(depString)
|
||||
pkgsToAdd = append(pkgsToAdd, pkg)
|
||||
}
|
||||
|
||||
return pkgsToAdd
|
||||
}
|
||||
|
||||
func (g *Grapher) ValidateAndSetNodeInfo(graph *topo.Graph[string, *InstallInfo],
|
||||
node string, nodeInfo *topo.NodeInfo[*InstallInfo],
|
||||
) {
|
||||
info := graph.GetNodeInfo(node)
|
||||
if info != nil && info.Value != nil {
|
||||
if info.Value.Reason < nodeInfo.Value.Reason {
|
||||
return // refuse to downgrade reason
|
||||
}
|
||||
|
||||
if info.Value.Upgrade {
|
||||
return // refuse to overwrite an upgrade
|
||||
}
|
||||
}
|
||||
|
||||
graph.SetNodeInfo(node, nodeInfo)
|
||||
}
|
||||
|
||||
func (g *Grapher) addNodes(
|
||||
ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo],
|
||||
parentPkgName string,
|
||||
deps []string,
|
||||
depType Reason,
|
||||
) {
|
||||
targetsToFind := mapset.NewThreadUnsafeSet(deps...)
|
||||
// Check if in graph already
|
||||
for _, depString := range targetsToFind.ToSlice() {
|
||||
depName, _, _ := splitDep(depString)
|
||||
if !graph.Exists(depName) && !graph.ProvidesExists(depName) {
|
||||
continue
|
||||
}
|
||||
|
||||
if graph.Exists(depName) {
|
||||
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
||||
g.logger.Warnln(depString, parentPkgName, err)
|
||||
}
|
||||
|
||||
targetsToFind.Remove(depString)
|
||||
}
|
||||
|
||||
if p := graph.GetProviderNode(depName); p != nil {
|
||||
if provideSatisfies(p.String(), depString, p.Version) {
|
||||
if err := graph.DependOn(p.Provider, parentPkgName); err != nil {
|
||||
g.logger.Warnln(p.Provider, parentPkgName, err)
|
||||
}
|
||||
|
||||
targetsToFind.Remove(depString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check installed
|
||||
for _, depString := range targetsToFind.ToSlice() {
|
||||
depName, _, _ := splitDep(depString)
|
||||
if !g.dbExecutor.LocalSatisfierExists(depString) {
|
||||
continue
|
||||
}
|
||||
|
||||
if g.fullGraph {
|
||||
g.ValidateAndSetNodeInfo(
|
||||
graph,
|
||||
depName,
|
||||
&topo.NodeInfo[*InstallInfo]{Color: colorMap[depType], Background: bgColorMap[Local]})
|
||||
|
||||
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
||||
g.logger.Warnln(depName, parentPkgName, err)
|
||||
}
|
||||
}
|
||||
|
||||
targetsToFind.Remove(depString)
|
||||
}
|
||||
|
||||
// Check Sync
|
||||
for _, depString := range targetsToFind.ToSlice() {
|
||||
alpmPkg := g.dbExecutor.SyncSatisfier(depString)
|
||||
if alpmPkg == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := graph.DependOn(alpmPkg.Name(), parentPkgName); err != nil {
|
||||
g.logger.Warnln("repo dep warn:", depString, parentPkgName, err)
|
||||
}
|
||||
|
||||
dbName := alpmPkg.DB().Name()
|
||||
g.ValidateAndSetNodeInfo(
|
||||
graph,
|
||||
alpmPkg.Name(),
|
||||
&topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[depType],
|
||||
Background: bgColorMap[Sync],
|
||||
Value: &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: depType,
|
||||
Version: alpmPkg.Version(),
|
||||
SyncDBName: &dbName,
|
||||
},
|
||||
})
|
||||
|
||||
if newDeps := alpmPkg.Depends().Slice(); len(newDeps) != 0 && g.fullGraph {
|
||||
newDepsSlice := make([]string, 0, len(newDeps))
|
||||
for _, newDep := range newDeps {
|
||||
newDepsSlice = append(newDepsSlice, newDep.Name)
|
||||
}
|
||||
|
||||
g.addNodes(ctx, graph, alpmPkg.Name(), newDepsSlice, Dep)
|
||||
}
|
||||
|
||||
targetsToFind.Remove(depString)
|
||||
}
|
||||
|
||||
// Check AUR
|
||||
pkgsToAdd := g.findDepsFromAUR(ctx, targetsToFind)
|
||||
for i := range pkgsToAdd {
|
||||
aurPkg := &pkgsToAdd[i]
|
||||
if err := graph.DependOn(aurPkg.Name, parentPkgName); err != nil {
|
||||
g.logger.Warnln("aur dep warn:", aurPkg.Name, parentPkgName, err)
|
||||
}
|
||||
|
||||
graph.SetNodeInfo(
|
||||
aurPkg.Name,
|
||||
&topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[depType],
|
||||
Background: bgColorMap[AUR],
|
||||
Value: &InstallInfo{
|
||||
Source: AUR,
|
||||
Reason: depType,
|
||||
AURBase: &aurPkg.PackageBase,
|
||||
Version: aurPkg.Version,
|
||||
},
|
||||
})
|
||||
|
||||
g.addDepNodes(ctx, aurPkg, graph)
|
||||
}
|
||||
|
||||
// Add missing to graph
|
||||
for _, depString := range targetsToFind.ToSlice() {
|
||||
depName, mod, ver := splitDep(depString)
|
||||
// no dep found. add as missing
|
||||
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
||||
g.logger.Warnln("missing dep warn:", depString, parentPkgName, err)
|
||||
}
|
||||
graph.SetNodeInfo(depName, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[depType],
|
||||
Background: bgColorMap[Missing],
|
||||
Value: &InstallInfo{
|
||||
Source: Missing,
|
||||
Reason: depType,
|
||||
Version: fmt.Sprintf("%s%s", mod, ver),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Grapher) provideMenu(dep string, options []aur.Pkg) *aur.Pkg {
|
||||
size := len(options)
|
||||
if size == 1 {
|
||||
return &options[0]
|
||||
}
|
||||
|
||||
str := text.Bold(gotext.Get("There are %[1]d providers available for %[2]s:", size, dep))
|
||||
str += "\n"
|
||||
|
||||
size = 1
|
||||
str += g.logger.SprintOperationInfo(gotext.Get("Repository AUR"), "\n ")
|
||||
|
||||
for i := range options {
|
||||
str += fmt.Sprintf("%d) %s ", size, options[i].Name)
|
||||
size++
|
||||
}
|
||||
|
||||
g.logger.OperationInfoln(str)
|
||||
|
||||
for {
|
||||
g.logger.Println(gotext.Get("\nEnter a number (default=1): "))
|
||||
|
||||
if g.noConfirm {
|
||||
g.logger.Println("1")
|
||||
|
||||
return &options[0]
|
||||
}
|
||||
|
||||
numberBuf, err := g.logger.GetInput("", false)
|
||||
if err != nil {
|
||||
g.logger.Errorln(err)
|
||||
|
||||
return &options[0]
|
||||
}
|
||||
|
||||
if numberBuf == "" {
|
||||
return &options[0]
|
||||
}
|
||||
|
||||
num, err := strconv.Atoi(numberBuf)
|
||||
if err != nil {
|
||||
g.logger.Errorln(gotext.Get("invalid number: %s", numberBuf))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if num < 1 || num >= size {
|
||||
g.logger.Errorln(gotext.Get("invalid value: %d is not between %d and %d",
|
||||
num, 1, size-1))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
return &options[num-1]
|
||||
}
|
||||
}
|
||||
|
||||
func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]*aur.Pkg, error) {
|
||||
pkgs := make([]*aur.Pkg, 0, 1)
|
||||
|
||||
alpmArch, err := dbExecutor.AlpmArchitectures()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
alpmArch = append(alpmArch, "") // srcinfo assumes no value as ""
|
||||
|
||||
getDesc := func(pkg *gosrc.Package) string {
|
||||
if pkg.Pkgdesc != "" {
|
||||
return pkg.Pkgdesc
|
||||
}
|
||||
|
||||
return srcInfo.Pkgdesc
|
||||
}
|
||||
|
||||
for i := range srcInfo.Packages {
|
||||
pkg := &srcInfo.Packages[i]
|
||||
|
||||
pkgs = append(pkgs, &aur.Pkg{
|
||||
ID: 0,
|
||||
Name: pkg.Pkgname,
|
||||
PackageBaseID: 0,
|
||||
PackageBase: srcInfo.Pkgbase,
|
||||
Version: srcInfo.Version(),
|
||||
Description: getDesc(pkg),
|
||||
URL: pkg.URL,
|
||||
Depends: append(archStringToString(alpmArch, pkg.Depends),
|
||||
archStringToString(alpmArch, srcInfo.Depends)...),
|
||||
MakeDepends: archStringToString(alpmArch, srcInfo.MakeDepends),
|
||||
CheckDepends: archStringToString(alpmArch, srcInfo.CheckDepends),
|
||||
Conflicts: append(archStringToString(alpmArch, pkg.Conflicts),
|
||||
archStringToString(alpmArch, srcInfo.Conflicts)...),
|
||||
Provides: append(archStringToString(alpmArch, pkg.Provides),
|
||||
archStringToString(alpmArch, srcInfo.Provides)...),
|
||||
Replaces: append(archStringToString(alpmArch, pkg.Replaces),
|
||||
archStringToString(alpmArch, srcInfo.Replaces)...),
|
||||
OptDepends: append(archStringToString(alpmArch, pkg.OptDepends),
|
||||
archStringToString(alpmArch, srcInfo.OptDepends)...),
|
||||
Groups: pkg.Groups,
|
||||
License: pkg.License,
|
||||
Keywords: []string{},
|
||||
})
|
||||
}
|
||||
|
||||
return pkgs, nil
|
||||
}
|
||||
|
||||
func archStringToString(alpmArches []string, archString []gosrc.ArchString) []string {
|
||||
pkgs := make([]string, 0, len(archString))
|
||||
|
||||
for _, arch := range archString {
|
||||
if db.ArchIsSupported(alpmArches, arch.Arch) {
|
||||
pkgs = append(pkgs, arch.Value)
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs
|
||||
}
|
||||
|
||||
func aurDepModToAlpmDep(mod string) alpm.DepMod {
|
||||
switch mod {
|
||||
case "=":
|
||||
return alpm.DepModEq
|
||||
case ">=":
|
||||
return alpm.DepModGE
|
||||
case "<=":
|
||||
return alpm.DepModLE
|
||||
case ">":
|
||||
return alpm.DepModGT
|
||||
case "<":
|
||||
return alpm.DepModLT
|
||||
}
|
||||
return alpm.DepModAny
|
||||
}
|
@ -1,811 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package dep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
aurc "github.com/Jguer/aur"
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
aur "github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func ptrString(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func getFromFile(t *testing.T, filePath string) mockaur.GetFunc {
|
||||
f, err := os.Open(filePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
fBytes, err := io.ReadAll(f)
|
||||
require.NoError(t, err)
|
||||
|
||||
pkgs := []aur.Pkg{}
|
||||
err = json.Unmarshal(fBytes, &pkgs)
|
||||
require.NoError(t, err)
|
||||
|
||||
return func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
return pkgs, nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) {
|
||||
mockDB := &mock.DBExecutor{
|
||||
SyncPackageFn: func(string) mock.IPackage { return nil },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "jellyfin":
|
||||
return nil
|
||||
case "dotnet-runtime-6.0":
|
||||
return &mock.Package{
|
||||
PName: "dotnet-runtime-6.0",
|
||||
PBase: "dotnet-runtime-6.0",
|
||||
PVersion: "6.0.100-1",
|
||||
PDB: mock.NewDB("community"),
|
||||
}
|
||||
case "dotnet-sdk-6.0":
|
||||
return &mock.Package{
|
||||
PName: "dotnet-sdk-6.0",
|
||||
PBase: "dotnet-sdk-6.0",
|
||||
PVersion: "6.0.100-1",
|
||||
PDB: mock.NewDB("community"),
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
PackagesFromGroupFn: func(string) []mock.IPackage { return nil },
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "dotnet-sdk-6.0", "dotnet-runtime-6.0", "jellyfin-server=10.8.8", "jellyfin-web=10.8.8":
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
if query.Needles[0] == "jellyfin" {
|
||||
jfinFn := getFromFile(t, "testdata/jellyfin.json")
|
||||
return jfinFn(ctx, query)
|
||||
}
|
||||
|
||||
if query.Needles[0] == "jellyfin-web" {
|
||||
jfinWebFn := getFromFile(t, "testdata/jellyfin-web.json")
|
||||
return jfinWebFn(ctx, query)
|
||||
}
|
||||
|
||||
if query.Needles[0] == "jellyfin-server" {
|
||||
jfinServerFn := getFromFile(t, "testdata/jellyfin-server.json")
|
||||
return jfinServerFn(ctx, query)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("implement me %v", query.Needles))
|
||||
}}
|
||||
|
||||
type fields struct {
|
||||
dbExecutor db.Executor
|
||||
aurCache aurc.QueryClient
|
||||
noDeps bool
|
||||
noCheckDeps bool
|
||||
}
|
||||
type args struct {
|
||||
targets []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []map[string]*InstallInfo
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "noDeps",
|
||||
fields: fields{
|
||||
dbExecutor: mockDB,
|
||||
aurCache: mockAUR,
|
||||
noDeps: true,
|
||||
noCheckDeps: false,
|
||||
},
|
||||
args: args{
|
||||
targets: []string{"jellyfin"},
|
||||
},
|
||||
want: []map[string]*InstallInfo{
|
||||
{
|
||||
"jellyfin": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "10.8.8-1",
|
||||
AURBase: ptrString("jellyfin"),
|
||||
},
|
||||
},
|
||||
{
|
||||
"dotnet-sdk-6.0": {
|
||||
Source: Sync,
|
||||
Reason: MakeDep,
|
||||
Version: "6.0.100-1",
|
||||
SyncDBName: ptrString("community"),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "deps",
|
||||
fields: fields{
|
||||
dbExecutor: mockDB,
|
||||
aurCache: mockAUR,
|
||||
noDeps: false,
|
||||
noCheckDeps: false,
|
||||
},
|
||||
args: args{
|
||||
targets: []string{"jellyfin"},
|
||||
},
|
||||
want: []map[string]*InstallInfo{
|
||||
{
|
||||
"jellyfin": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "10.8.8-1",
|
||||
AURBase: ptrString("jellyfin"),
|
||||
},
|
||||
},
|
||||
{
|
||||
"jellyfin-web": {
|
||||
Source: AUR,
|
||||
Reason: Dep,
|
||||
Version: "10.8.8-1",
|
||||
AURBase: ptrString("jellyfin"),
|
||||
},
|
||||
"jellyfin-server": {
|
||||
Source: AUR,
|
||||
Reason: Dep,
|
||||
Version: "10.8.8-1",
|
||||
AURBase: ptrString("jellyfin"),
|
||||
},
|
||||
},
|
||||
{
|
||||
"dotnet-sdk-6.0": {
|
||||
Source: Sync,
|
||||
Reason: MakeDep,
|
||||
Version: "6.0.100-1",
|
||||
SyncDBName: ptrString("community"),
|
||||
},
|
||||
"dotnet-runtime-6.0": {
|
||||
Source: Sync,
|
||||
Reason: Dep,
|
||||
Version: "6.0.100-1",
|
||||
SyncDBName: ptrString("community"),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := NewGrapher(tt.fields.dbExecutor,
|
||||
tt.fields.aurCache, false, true,
|
||||
tt.fields.noDeps, tt.fields.noCheckDeps, false,
|
||||
text.NewLogger(io.Discard, io.Discard, &os.File{}, true, "test"))
|
||||
got, err := g.GraphFromTargets(context.Background(), nil, tt.args.targets)
|
||||
require.NoError(t, err)
|
||||
layers := got.TopoSortedLayerMap(nil)
|
||||
require.EqualValues(t, tt.want, layers, layers)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrapher_GraphProvides_androidsdk(t *testing.T) {
|
||||
mockDB := &mock.DBExecutor{
|
||||
SyncPackageFn: func(string) mock.IPackage { return nil },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "android-sdk":
|
||||
return nil
|
||||
case "jdk11-openjdk":
|
||||
return &mock.Package{
|
||||
PName: "jdk11-openjdk",
|
||||
PVersion: "11.0.12.u7-1",
|
||||
PDB: mock.NewDB("community"),
|
||||
PProvides: mock.DependList{
|
||||
Depends: []alpm.Depend{
|
||||
{Name: "java-environment", Version: "11", Mod: alpm.DepModEq},
|
||||
{Name: "java-environment-openjdk", Version: "11", Mod: alpm.DepModEq},
|
||||
{Name: "jdk11-openjdk", Version: "11.0.19.u7-1", Mod: alpm.DepModEq},
|
||||
},
|
||||
},
|
||||
}
|
||||
case "java-environment":
|
||||
panic("not supposed to be called")
|
||||
}
|
||||
panic("implement me " + s)
|
||||
},
|
||||
PackagesFromGroupFn: func(string) []mock.IPackage { return nil },
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "java-environment":
|
||||
return false
|
||||
}
|
||||
|
||||
switch s {
|
||||
case "libxtst", "fontconfig", "freetype2", "lib32-gcc-libs", "lib32-glibc", "libx11", "libxext", "libxrender", "zlib", "gcc-libs":
|
||||
return true
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
if query.Needles[0] == "android-sdk" {
|
||||
jfinFn := getFromFile(t, "testdata/android-sdk.json")
|
||||
return jfinFn(ctx, query)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("implement me %v", query.Needles))
|
||||
}}
|
||||
|
||||
type fields struct {
|
||||
dbExecutor db.Executor
|
||||
aurCache aurc.QueryClient
|
||||
noDeps bool
|
||||
noCheckDeps bool
|
||||
}
|
||||
type args struct {
|
||||
targets []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []map[string]*InstallInfo
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "explicit dep",
|
||||
fields: fields{
|
||||
dbExecutor: mockDB,
|
||||
aurCache: mockAUR,
|
||||
noDeps: false,
|
||||
noCheckDeps: false,
|
||||
},
|
||||
args: args{
|
||||
targets: []string{"android-sdk", "jdk11-openjdk"},
|
||||
},
|
||||
want: []map[string]*InstallInfo{
|
||||
{
|
||||
"android-sdk": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "26.1.1-2",
|
||||
AURBase: ptrString("android-sdk"),
|
||||
},
|
||||
},
|
||||
{
|
||||
"jdk11-openjdk": {
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: "11.0.12.u7-1",
|
||||
SyncDBName: ptrString("community"),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := NewGrapher(tt.fields.dbExecutor,
|
||||
tt.fields.aurCache, false, true,
|
||||
tt.fields.noDeps, tt.fields.noCheckDeps, false,
|
||||
text.NewLogger(io.Discard, io.Discard, &os.File{}, true, "test"))
|
||||
got, err := g.GraphFromTargets(context.Background(), nil, tt.args.targets)
|
||||
require.NoError(t, err)
|
||||
layers := got.TopoSortedLayerMap(nil)
|
||||
require.EqualValues(t, tt.want, layers, layers)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrapher_GraphFromAUR_Deps_ceph_bin(t *testing.T) {
|
||||
mockDB := &mock.DBExecutor{
|
||||
SyncPackageFn: func(string) mock.IPackage { return nil },
|
||||
PackagesFromGroupFn: func(string) []mock.IPackage { return []mock.IPackage{} },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "ceph-bin", "ceph-libs-bin":
|
||||
return nil
|
||||
case "ceph", "ceph-libs", "ceph-libs=17.2.6-2":
|
||||
return nil
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "ceph-libs", "ceph-libs=17.2.6-2":
|
||||
return false
|
||||
case "dep1", "dep2", "dep3", "makedep1", "makedep2", "checkdep1":
|
||||
return true
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
mockPkgs := map[string]aur.Pkg{
|
||||
"ceph-bin": {
|
||||
Name: "ceph-bin",
|
||||
PackageBase: "ceph-bin",
|
||||
Version: "17.2.6-2",
|
||||
Depends: []string{"ceph-libs=17.2.6-2", "dep1"},
|
||||
Provides: []string{"ceph=17.2.6-2"},
|
||||
},
|
||||
"ceph-libs-bin": {
|
||||
Name: "ceph-libs-bin",
|
||||
PackageBase: "ceph-bin",
|
||||
Version: "17.2.6-2",
|
||||
Depends: []string{"dep1", "dep2"},
|
||||
Provides: []string{"ceph-libs=17.2.6-2"},
|
||||
},
|
||||
"ceph": {
|
||||
Name: "ceph",
|
||||
PackageBase: "ceph",
|
||||
Version: "17.2.6-2",
|
||||
Depends: []string{"ceph-libs=17.2.6-2", "dep1"},
|
||||
MakeDepends: []string{"makedep1"},
|
||||
CheckDepends: []string{"checkdep1"},
|
||||
Provides: []string{"ceph=17.2.6-2"},
|
||||
},
|
||||
"ceph-libs": {
|
||||
Name: "ceph-libs",
|
||||
PackageBase: "ceph",
|
||||
Version: "17.2.6-2",
|
||||
Depends: []string{"dep1", "dep2", "dep3"},
|
||||
MakeDepends: []string{"makedep1", "makedep2"},
|
||||
CheckDepends: []string{"checkdep1"},
|
||||
Provides: []string{"ceph-libs=17.2.6-2"},
|
||||
},
|
||||
}
|
||||
|
||||
pkgs := []aur.Pkg{}
|
||||
for _, needle := range query.Needles {
|
||||
if pkg, ok := mockPkgs[needle]; ok {
|
||||
pkgs = append(pkgs, pkg)
|
||||
} else {
|
||||
panic(fmt.Sprintf("implement me %v", needle))
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs, nil
|
||||
}}
|
||||
|
||||
installInfos := map[string]*InstallInfo{
|
||||
"ceph-bin exp": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "17.2.6-2",
|
||||
AURBase: ptrString("ceph-bin"),
|
||||
},
|
||||
"ceph-libs-bin exp": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "17.2.6-2",
|
||||
AURBase: ptrString("ceph-bin"),
|
||||
},
|
||||
"ceph exp": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "17.2.6-2",
|
||||
AURBase: ptrString("ceph"),
|
||||
},
|
||||
"ceph-libs exp": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "17.2.6-2",
|
||||
AURBase: ptrString("ceph"),
|
||||
},
|
||||
"ceph-libs dep": {
|
||||
Source: AUR,
|
||||
Reason: Dep,
|
||||
Version: "17.2.6-2",
|
||||
AURBase: ptrString("ceph"),
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
targets []string
|
||||
wantLayers []map[string]*InstallInfo
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "ceph-bin ceph-libs-bin",
|
||||
targets: []string{"ceph-bin", "ceph-libs-bin"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph-bin": installInfos["ceph-bin exp"]},
|
||||
{"ceph-libs-bin": installInfos["ceph-libs-bin exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph-libs-bin ceph-bin (reversed order)",
|
||||
targets: []string{"ceph-libs-bin", "ceph-bin"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph-bin": installInfos["ceph-bin exp"]},
|
||||
{"ceph-libs-bin": installInfos["ceph-libs-bin exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph",
|
||||
targets: []string{"ceph"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph": installInfos["ceph exp"]},
|
||||
{"ceph-libs": installInfos["ceph-libs dep"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph-bin",
|
||||
targets: []string{"ceph-bin"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph-bin": installInfos["ceph-bin exp"]},
|
||||
{"ceph-libs": installInfos["ceph-libs dep"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph-bin ceph-libs",
|
||||
targets: []string{"ceph-bin", "ceph-libs"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph-bin": installInfos["ceph-bin exp"]},
|
||||
{"ceph-libs": installInfos["ceph-libs exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph-libs ceph-bin (reversed order)",
|
||||
targets: []string{"ceph-libs", "ceph-bin"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph-bin": installInfos["ceph-bin exp"]},
|
||||
{"ceph-libs": installInfos["ceph-libs exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph ceph-libs-bin",
|
||||
targets: []string{"ceph", "ceph-libs-bin"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph": installInfos["ceph exp"]},
|
||||
{"ceph-libs-bin": installInfos["ceph-libs-bin exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ceph-libs-bin ceph (reversed order)",
|
||||
targets: []string{"ceph-libs-bin", "ceph"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"ceph": installInfos["ceph exp"]},
|
||||
{"ceph-libs-bin": installInfos["ceph-libs-bin exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := NewGrapher(mockDB, mockAUR,
|
||||
false, true, false, false, false,
|
||||
text.NewLogger(io.Discard, io.Discard, &os.File{}, true, "test"))
|
||||
got, err := g.GraphFromTargets(context.Background(), nil, tt.targets)
|
||||
require.NoError(t, err)
|
||||
layers := got.TopoSortedLayerMap(nil)
|
||||
require.EqualValues(t, tt.wantLayers, layers, layers)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrapher_GraphFromAUR_Deps_gourou(t *testing.T) {
|
||||
mockDB := &mock.DBExecutor{
|
||||
SyncPackageFn: func(string) mock.IPackage { return nil },
|
||||
PackagesFromGroupFn: func(string) []mock.IPackage { return []mock.IPackage{} },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "gourou", "libzip-git":
|
||||
return nil
|
||||
case "libzip":
|
||||
return &mock.Package{
|
||||
PName: "libzip",
|
||||
PVersion: "1.9.2-1",
|
||||
PDB: mock.NewDB("extra"),
|
||||
}
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "gourou", "libzip", "libzip-git":
|
||||
return false
|
||||
case "dep1", "dep2":
|
||||
return true
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
mockPkgs := map[string]aur.Pkg{
|
||||
"gourou": {
|
||||
Name: "gourou",
|
||||
PackageBase: "gourou",
|
||||
Version: "0.8.1",
|
||||
Depends: []string{"libzip"},
|
||||
},
|
||||
"libzip-git": {
|
||||
Name: "libzip-git",
|
||||
PackageBase: "libzip-git",
|
||||
Version: "1.9.2.r159.gb3ac716c-1",
|
||||
Depends: []string{"dep1", "dep2"},
|
||||
Provides: []string{"libzip=1.9.2.r159.gb3ac716c"},
|
||||
},
|
||||
}
|
||||
|
||||
pkgs := []aur.Pkg{}
|
||||
for _, needle := range query.Needles {
|
||||
if pkg, ok := mockPkgs[needle]; ok {
|
||||
pkgs = append(pkgs, pkg)
|
||||
} else {
|
||||
panic(fmt.Sprintf("implement me %v", needle))
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs, nil
|
||||
}}
|
||||
|
||||
installInfos := map[string]*InstallInfo{
|
||||
"gourou exp": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "0.8.1",
|
||||
AURBase: ptrString("gourou"),
|
||||
},
|
||||
"libzip dep": {
|
||||
Source: Sync,
|
||||
Reason: Dep,
|
||||
Version: "1.9.2-1",
|
||||
SyncDBName: ptrString("extra"),
|
||||
},
|
||||
"libzip exp": {
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: "1.9.2-1",
|
||||
SyncDBName: ptrString("extra"),
|
||||
},
|
||||
"libzip-git exp": {
|
||||
Source: AUR,
|
||||
Reason: Explicit,
|
||||
Version: "1.9.2.r159.gb3ac716c-1",
|
||||
AURBase: ptrString("libzip-git"),
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
targets []string
|
||||
wantLayers []map[string]*InstallInfo
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "gourou",
|
||||
targets: []string{"gourou"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"gourou": installInfos["gourou exp"]},
|
||||
{"libzip": installInfos["libzip dep"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "gourou libzip",
|
||||
targets: []string{"gourou", "libzip"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"gourou": installInfos["gourou exp"]},
|
||||
{"libzip": installInfos["libzip exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "gourou libzip-git",
|
||||
targets: []string{"gourou", "libzip-git"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"gourou": installInfos["gourou exp"]},
|
||||
{"libzip-git": installInfos["libzip-git exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "libzip-git gourou (reversed order)",
|
||||
targets: []string{"libzip-git", "gourou"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"gourou": installInfos["gourou exp"]},
|
||||
{"libzip-git": installInfos["libzip-git exp"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := NewGrapher(mockDB, mockAUR,
|
||||
false, true, false, false, false,
|
||||
text.NewLogger(io.Discard, io.Discard, &os.File{}, true, "test"))
|
||||
got, err := g.GraphFromTargets(context.Background(), nil, tt.targets)
|
||||
require.NoError(t, err)
|
||||
layers := got.TopoSortedLayerMap(nil)
|
||||
require.EqualValues(t, tt.wantLayers, layers, layers)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrapher_GraphFromTargets_ReinstalledDeps(t *testing.T) {
|
||||
mockDB := &mock.DBExecutor{
|
||||
SyncPackageFn: func(string) mock.IPackage { return nil },
|
||||
PackagesFromGroupFn: func(string) []mock.IPackage { return []mock.IPackage{} },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "gourou":
|
||||
return nil
|
||||
case "libzip":
|
||||
return &mock.Package{
|
||||
PName: "libzip",
|
||||
PVersion: "1.9.2-1",
|
||||
PDB: mock.NewDB("extra"),
|
||||
}
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
SatisfierFromDBFn: func(s, s2 string) (mock.IPackage, error) {
|
||||
if s2 == "extra" {
|
||||
switch s {
|
||||
case "libzip":
|
||||
return &mock.Package{
|
||||
PName: "libzip",
|
||||
PVersion: "1.9.2-1",
|
||||
PDB: mock.NewDB("extra"),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
panic("implement me " + s2 + "/" + s)
|
||||
},
|
||||
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "gourou", "libzip":
|
||||
return true
|
||||
}
|
||||
|
||||
panic("implement me " + s)
|
||||
},
|
||||
LocalPackageFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "libzip":
|
||||
return &mock.Package{
|
||||
PName: "libzip",
|
||||
PVersion: "1.9.2-1",
|
||||
PDB: mock.NewDB("extra"),
|
||||
PReason: alpm.PkgReasonDepend,
|
||||
}
|
||||
case "gourou":
|
||||
return &mock.Package{
|
||||
PName: "gourou",
|
||||
PVersion: "0.8.1",
|
||||
PDB: mock.NewDB("aur"),
|
||||
PReason: alpm.PkgReasonDepend,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
mockPkgs := map[string]aur.Pkg{
|
||||
"gourou": {
|
||||
Name: "gourou",
|
||||
PackageBase: "gourou",
|
||||
Version: "0.8.1",
|
||||
Depends: []string{"libzip"},
|
||||
},
|
||||
}
|
||||
|
||||
pkgs := []aur.Pkg{}
|
||||
for _, needle := range query.Needles {
|
||||
if pkg, ok := mockPkgs[needle]; ok {
|
||||
pkgs = append(pkgs, pkg)
|
||||
} else {
|
||||
panic(fmt.Sprintf("implement me %v", needle))
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs, nil
|
||||
}}
|
||||
|
||||
installInfos := map[string]*InstallInfo{
|
||||
"gourou dep": {
|
||||
Source: AUR,
|
||||
Reason: Dep,
|
||||
Version: "0.8.1",
|
||||
AURBase: ptrString("gourou"),
|
||||
},
|
||||
"libzip dep": {
|
||||
Source: Sync,
|
||||
Reason: Dep,
|
||||
Version: "1.9.2-1",
|
||||
SyncDBName: ptrString("extra"),
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
targets []string
|
||||
wantLayers []map[string]*InstallInfo
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "gourou libzip",
|
||||
targets: []string{"gourou", "libzip"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"gourou": installInfos["gourou dep"]},
|
||||
{"libzip": installInfos["libzip dep"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "aur/gourou extra/libzip",
|
||||
targets: []string{"aur/gourou", "extra/libzip"},
|
||||
wantLayers: []map[string]*InstallInfo{
|
||||
{"gourou": installInfos["gourou dep"]},
|
||||
{"libzip": installInfos["libzip dep"]},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := NewGrapher(mockDB, mockAUR,
|
||||
false, true, false, false, false,
|
||||
text.NewLogger(io.Discard, io.Discard, &os.File{}, true, "test"))
|
||||
got, err := g.GraphFromTargets(context.Background(), nil, tt.targets)
|
||||
require.NoError(t, err)
|
||||
layers := got.TopoSortedLayerMap(nil)
|
||||
require.EqualValues(t, tt.wantLayers, layers, layers)
|
||||
})
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
)
|
||||
|
||||
type GetFunc func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error)
|
||||
|
||||
type MockAUR struct {
|
||||
GetFn GetFunc
|
||||
}
|
||||
|
||||
func (m *MockAUR) Get(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
if m.GetFn != nil {
|
||||
return m.GetFn(ctx, query)
|
||||
}
|
||||
|
||||
panic("implement me")
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package dep
|
||||
|
||||
import "github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
type Target struct {
|
||||
DB string
|
||||
Name string
|
||||
Mod string
|
||||
Version string
|
||||
}
|
||||
|
||||
func ToTarget(pkg string) Target {
|
||||
dbName, depString := text.SplitDBFromName(pkg)
|
||||
name, mod, depVersion := splitDep(depString)
|
||||
|
||||
return Target{
|
||||
DB: dbName,
|
||||
Name: name,
|
||||
Mod: mod,
|
||||
Version: depVersion,
|
||||
}
|
||||
}
|
||||
|
||||
func (t Target) DepString() string {
|
||||
return t.Name + t.Mod + t.Version
|
||||
}
|
||||
|
||||
func (t Target) String() string {
|
||||
if t.DB != "" {
|
||||
return t.DB + "/" + t.DepString()
|
||||
}
|
||||
|
||||
return t.DepString()
|
||||
}
|
3
pkg/dep/testdata/android-sdk.json
vendored
3
pkg/dep/testdata/android-sdk.json
vendored
@ -1,3 +0,0 @@
|
||||
[
|
||||
{"ID":1055234,"Name":"android-sdk","PackageBaseID":13751,"PackageBase":"android-sdk","Version":"26.1.1-2","Description":"Google Android SDK","URL":"https://developer.android.com/studio/releases/sdk-tools.html","NumVotes":1487,"Popularity":0.802316,"OutOfDate":null,"Maintainer":"dreamingincode","Submitter":null,"FirstSubmitted":1194895596,"LastModified":1647982720,"URLPath":"/cgit/aur.git/snapshot/android-sdk.tar.gz","Depends":["java-environment","libxtst","fontconfig","freetype2","lib32-gcc-libs","lib32-glibc","libx11","libxext","libxrender","zlib","gcc-libs"],"OptDepends":["android-emulator","android-sdk-platform-tools","android-udev"],"License":["custom"],"Keywords":["android","development"]}
|
||||
]
|
3
pkg/dep/testdata/jellyfin-server.json
vendored
3
pkg/dep/testdata/jellyfin-server.json
vendored
@ -1,3 +0,0 @@
|
||||
[
|
||||
{"ID":1176791,"Name":"jellyfin-server","PackageBaseID":138631,"PackageBase":"jellyfin","Version":"10.8.8-1","Description":"Jellyfin server component","URL":"https://github.com/jellyfin/jellyfin","NumVotes":84,"Popularity":1.272964,"OutOfDate":null,"Maintainer":"z3ntu","Submitter":"z3ntu","FirstSubmitted":1547053171,"LastModified":1669830147,"URLPath":"/cgit/aur.git/snapshot/jellyfin-server.tar.gz","Depends":["dotnet-runtime-6.0","aspnet-runtime-6.0","ffmpeg","sqlite"],"MakeDepends":["dotnet-sdk-6.0","nodejs","npm","git"],"License":["GPL2"]}
|
||||
]
|
3
pkg/dep/testdata/jellyfin-web.json
vendored
3
pkg/dep/testdata/jellyfin-web.json
vendored
@ -1,3 +0,0 @@
|
||||
[
|
||||
{"ID":1176790,"Name":"jellyfin-web","PackageBaseID":138631,"PackageBase":"jellyfin","Version":"10.8.8-1","Description":"Jellyfin web client","URL":"https://github.com/jellyfin/jellyfin","NumVotes":84,"Popularity":1.272964,"OutOfDate":null,"Maintainer":"z3ntu","Submitter":"z3ntu","FirstSubmitted":1547053171,"LastModified":1669830147,"URLPath":"/cgit/aur.git/snapshot/jellyfin-web.tar.gz","MakeDepends":["dotnet-sdk-6.0","nodejs","npm","git"],"License":["GPL2"]}
|
||||
]
|
3
pkg/dep/testdata/jellyfin.json
vendored
3
pkg/dep/testdata/jellyfin.json
vendored
@ -1,3 +0,0 @@
|
||||
[
|
||||
{"ID":1176789,"Name":"jellyfin","PackageBaseID":138631,"PackageBase":"jellyfin","Version":"10.8.8-1","Description":"The Free Software Media System","URL":"https://github.com/jellyfin/jellyfin","NumVotes":84,"Popularity":1.272964,"OutOfDate":null,"Maintainer":"z3ntu","Submitter":"z3ntu","FirstSubmitted":1547053171,"LastModified":1669830147,"URLPath":"/cgit/aur.git/snapshot/jellyfin.tar.gz","Depends":["jellyfin-web=10.8.8","jellyfin-server=10.8.8"],"MakeDepends":["dotnet-sdk-6.0","nodejs","npm","git"],"License":["GPL2"]}
|
||||
]
|
@ -1,371 +0,0 @@
|
||||
package topo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
NodeSet[T comparable] map[T]bool
|
||||
ProvidesMap[T comparable] map[T]*DependencyInfo[T]
|
||||
DepMap[T comparable] map[T]NodeSet[T]
|
||||
)
|
||||
|
||||
func (n NodeSet[T]) Slice() []T {
|
||||
var slice []T
|
||||
|
||||
for node := range n {
|
||||
slice = append(slice, node)
|
||||
}
|
||||
|
||||
return slice
|
||||
}
|
||||
|
||||
type NodeInfo[V any] struct {
|
||||
Color string
|
||||
Background string
|
||||
Value V
|
||||
}
|
||||
|
||||
type DependencyInfo[T comparable] struct {
|
||||
Provider T
|
||||
alpm.Depend
|
||||
}
|
||||
|
||||
type CheckFn[T comparable, V any] func(T, V) error
|
||||
|
||||
type Graph[T comparable, V any] struct {
|
||||
nodes NodeSet[T]
|
||||
|
||||
// node info map
|
||||
nodeInfo map[T]*NodeInfo[V]
|
||||
|
||||
// `provides` tracks provides -> node.
|
||||
provides ProvidesMap[T]
|
||||
|
||||
// `dependencies` tracks child -> parents.
|
||||
dependencies DepMap[T]
|
||||
// `dependents` tracks parent -> children.
|
||||
dependents DepMap[T]
|
||||
}
|
||||
|
||||
func New[T comparable, V any]() *Graph[T, V] {
|
||||
return &Graph[T, V]{
|
||||
nodes: make(NodeSet[T]),
|
||||
dependencies: make(DepMap[T]),
|
||||
dependents: make(DepMap[T]),
|
||||
nodeInfo: make(map[T]*NodeInfo[V]),
|
||||
provides: make(ProvidesMap[T]),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) Len() int {
|
||||
return len(g.nodes)
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) Exists(node T) bool {
|
||||
_, ok := g.nodes[node]
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) AddNode(node T) {
|
||||
g.nodes[node] = true
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) ProvidesExists(provides T) bool {
|
||||
_, ok := g.provides[provides]
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) GetProviderNode(provides T) *DependencyInfo[T] {
|
||||
return g.provides[provides]
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) Provides(provides T, depInfo *alpm.Depend, node T) {
|
||||
g.provides[provides] = &DependencyInfo[T]{
|
||||
Provider: node,
|
||||
Depend: *depInfo,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) ForEach(f CheckFn[T, V]) error {
|
||||
for node := range g.nodes {
|
||||
if err := f(node, g.nodeInfo[node].Value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) SetNodeInfo(node T, nodeInfo *NodeInfo[V]) {
|
||||
g.nodeInfo[node] = nodeInfo
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) GetNodeInfo(node T) *NodeInfo[V] {
|
||||
return g.nodeInfo[node]
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) DependOn(child, parent T) error {
|
||||
if child == parent {
|
||||
return ErrSelfReferential
|
||||
}
|
||||
|
||||
if g.DependsOn(parent, child) {
|
||||
return ErrCircular
|
||||
}
|
||||
|
||||
g.AddNode(parent)
|
||||
g.AddNode(child)
|
||||
|
||||
// Add edges.
|
||||
g.dependents.addNodeToNodeset(parent, child)
|
||||
g.dependencies.addNodeToNodeset(child, parent)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) String() string {
|
||||
var sb strings.Builder
|
||||
|
||||
sb.WriteString("digraph {\n")
|
||||
sb.WriteString("compound=true;\n")
|
||||
sb.WriteString("concentrate=true;\n")
|
||||
sb.WriteString("node [shape = record, ordering=out];\n")
|
||||
|
||||
for node := range g.nodes {
|
||||
extra := ""
|
||||
|
||||
if info, ok := g.nodeInfo[node]; ok {
|
||||
if info.Background != "" || info.Color != "" {
|
||||
extra = fmt.Sprintf("[color = %s, style = filled, fillcolor = %s]", info.Color, info.Background)
|
||||
}
|
||||
}
|
||||
|
||||
sb.WriteString(fmt.Sprintf("\t\"%v\"%s;\n", node, extra))
|
||||
}
|
||||
|
||||
for parent, children := range g.dependencies {
|
||||
for child := range children {
|
||||
sb.WriteString(fmt.Sprintf("\t\"%v\" -> \"%v\";\n", parent, child))
|
||||
}
|
||||
}
|
||||
|
||||
sb.WriteString("}")
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) DependsOn(child, parent T) bool {
|
||||
deps := g.Dependencies(child)
|
||||
_, ok := deps[parent]
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) HasDependent(parent, child T) bool {
|
||||
deps := g.Dependents(parent)
|
||||
_, ok := deps[child]
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
// leavesMap returns a map of leaves with the node as key and the node info value as value.
|
||||
func (g *Graph[T, V]) leavesMap() map[T]V {
|
||||
leaves := make(map[T]V, 0)
|
||||
|
||||
for node := range g.nodes {
|
||||
if _, ok := g.dependencies[node]; !ok {
|
||||
nodeInfo := g.GetNodeInfo(node)
|
||||
if nodeInfo == nil {
|
||||
nodeInfo = &NodeInfo[V]{}
|
||||
}
|
||||
|
||||
leaves[node] = nodeInfo.Value
|
||||
}
|
||||
}
|
||||
|
||||
return leaves
|
||||
}
|
||||
|
||||
// TopoSortedLayerMap returns a slice of all of the graph nodes in topological sort order with their node info.
|
||||
func (g *Graph[T, V]) TopoSortedLayerMap(checkFn CheckFn[T, V]) []map[T]V {
|
||||
layers := []map[T]V{}
|
||||
|
||||
// Copy the graph
|
||||
shrinkingGraph := g.clone()
|
||||
|
||||
for {
|
||||
leaves := shrinkingGraph.leavesMap()
|
||||
if len(leaves) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
layers = append(layers, leaves)
|
||||
|
||||
for leafNode := range leaves {
|
||||
if checkFn != nil {
|
||||
if err := checkFn(leafNode, leaves[leafNode]); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
shrinkingGraph.remove(leafNode)
|
||||
}
|
||||
}
|
||||
|
||||
return layers
|
||||
}
|
||||
|
||||
// returns if it was the last
|
||||
func (dm DepMap[T]) removeFromDepmap(key, node T) bool {
|
||||
if nodes := dm[key]; len(nodes) == 1 {
|
||||
// The only element in the nodeset must be `node`, so we
|
||||
// can delete the entry entirely.
|
||||
delete(dm, key)
|
||||
return true
|
||||
} else {
|
||||
// Otherwise, remove the single node from the nodeset.
|
||||
delete(nodes, node)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Prune removes the node,
|
||||
// its dependencies if there are no other dependents
|
||||
// and its dependents
|
||||
func (g *Graph[T, V]) Prune(node T) []T {
|
||||
pruned := []T{node}
|
||||
// Remove edges from things that depend on `node`.
|
||||
for dependent := range g.dependents[node] {
|
||||
last := g.dependencies.removeFromDepmap(dependent, node)
|
||||
if last {
|
||||
pruned = append(pruned, g.Prune(dependent)...)
|
||||
}
|
||||
}
|
||||
|
||||
delete(g.dependents, node)
|
||||
|
||||
// Remove all edges from node to the things it depends on.
|
||||
for dependency := range g.dependencies[node] {
|
||||
last := g.dependents.removeFromDepmap(dependency, node)
|
||||
if last {
|
||||
pruned = append(pruned, g.Prune(dependency)...)
|
||||
}
|
||||
}
|
||||
|
||||
delete(g.dependencies, node)
|
||||
|
||||
// Finally, remove the node itself.
|
||||
delete(g.nodes, node)
|
||||
return pruned
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) remove(node T) {
|
||||
// Remove edges from things that depend on `node`.
|
||||
for dependent := range g.dependents[node] {
|
||||
g.dependencies.removeFromDepmap(dependent, node)
|
||||
}
|
||||
|
||||
delete(g.dependents, node)
|
||||
|
||||
// Remove all edges from node to the things it depends on.
|
||||
for dependency := range g.dependencies[node] {
|
||||
g.dependents.removeFromDepmap(dependency, node)
|
||||
}
|
||||
|
||||
delete(g.dependencies, node)
|
||||
|
||||
// Finally, remove the node itself.
|
||||
delete(g.nodes, node)
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) Dependencies(child T) NodeSet[T] {
|
||||
return g.buildTransitive(child, g.ImmediateDependencies)
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) ImmediateDependencies(node T) NodeSet[T] {
|
||||
return g.dependencies[node]
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) Dependents(parent T) NodeSet[T] {
|
||||
return g.buildTransitive(parent, g.immediateDependents)
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) immediateDependents(node T) NodeSet[T] {
|
||||
return g.dependents[node]
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) clone() *Graph[T, V] {
|
||||
return &Graph[T, V]{
|
||||
dependencies: g.dependencies.copy(),
|
||||
dependents: g.dependents.copy(),
|
||||
nodes: g.nodes.copy(),
|
||||
nodeInfo: g.nodeInfo, // not copied, as it is not modified
|
||||
}
|
||||
}
|
||||
|
||||
// buildTransitive starts at `root` and continues calling `nextFn` to keep discovering more nodes until
|
||||
// the graph cannot produce any more. It returns the set of all discovered nodes.
|
||||
func (g *Graph[T, V]) buildTransitive(root T, nextFn func(T) NodeSet[T]) NodeSet[T] {
|
||||
if _, ok := g.nodes[root]; !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make(NodeSet[T])
|
||||
searchNext := []T{root}
|
||||
|
||||
for len(searchNext) > 0 {
|
||||
// List of new nodes from this layer of the dependency graph. This is
|
||||
// assigned to `searchNext` at the end of the outer "discovery" loop.
|
||||
discovered := []T{}
|
||||
|
||||
for _, node := range searchNext {
|
||||
// For each node to discover, find the next nodes.
|
||||
for nextNode := range nextFn(node) {
|
||||
// If we have not seen the node before, add it to the output as well
|
||||
// as the list of nodes to traverse in the next iteration.
|
||||
if _, ok := out[nextNode]; !ok {
|
||||
out[nextNode] = true
|
||||
|
||||
discovered = append(discovered, nextNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
searchNext = discovered
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (s NodeSet[T]) copy() NodeSet[T] {
|
||||
out := make(NodeSet[T], len(s))
|
||||
for k, v := range s {
|
||||
out[k] = v
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (dm DepMap[T]) copy() DepMap[T] {
|
||||
out := make(DepMap[T], len(dm))
|
||||
for k := range dm {
|
||||
out[k] = dm[k].copy()
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (dm DepMap[T]) addNodeToNodeset(key, node T) {
|
||||
nodes, ok := dm[key]
|
||||
if !ok {
|
||||
nodes = make(NodeSet[T])
|
||||
dm[key] = nodes
|
||||
}
|
||||
|
||||
nodes[node] = true
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package topo
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrSelfReferential = errors.New(" self-referential dependencies not allowed")
|
||||
ErrConflictingAlias = errors.New(" alias already defined")
|
||||
ErrCircular = errors.New(" circular dependencies not allowed")
|
||||
)
|
@ -1,92 +0,0 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxConcurrentFetch = 20
|
||||
absPackageURL = "https://gitlab.archlinux.org/archlinux/packaging/packages"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidRepository = errors.New(gotext.Get("invalid repository"))
|
||||
ErrABSPackageNotFound = errors.New(gotext.Get("package not found in repos"))
|
||||
)
|
||||
|
||||
type regexReplace struct {
|
||||
repl string
|
||||
match *regexp.Regexp
|
||||
}
|
||||
|
||||
// regex replacements for Gitlab URLs
|
||||
// info: https://gitlab.archlinux.org/archlinux/devtools/-/blob/6ce666a1669235749c17d5c44d8a24dea4a135da/src/lib/api/gitlab.sh#L84
|
||||
var gitlabRepl = []regexReplace{
|
||||
{repl: `$1-$2`, match: regexp.MustCompile(`([a-zA-Z0-9]+)\+([a-zA-Z]+)`)},
|
||||
{repl: `plus`, match: regexp.MustCompile(`\+`)},
|
||||
{repl: `-`, match: regexp.MustCompile(`[^a-zA-Z0-9_\-.]`)},
|
||||
{repl: `-`, match: regexp.MustCompile(`[_\-]{2,}`)},
|
||||
{repl: `unix-tree`, match: regexp.MustCompile(`^tree$`)},
|
||||
}
|
||||
|
||||
// Return format for pkgbuild
|
||||
// https://gitlab.archlinux.org/archlinux/packaging/packages/0ad/-/raw/main/PKGBUILD
|
||||
func getPackagePKGBUILDURL(pkgName string) string {
|
||||
return fmt.Sprintf("%s/%s/-/raw/main/PKGBUILD", absPackageURL, convertPkgNameForURL(pkgName))
|
||||
}
|
||||
|
||||
// Return format for pkgbuild repo
|
||||
// https://gitlab.archlinux.org/archlinux/packaging/packages/0ad.git
|
||||
func getPackageRepoURL(pkgName string) string {
|
||||
return fmt.Sprintf("%s/%s.git", absPackageURL, convertPkgNameForURL(pkgName))
|
||||
}
|
||||
|
||||
// convert pkgName for Gitlab URL path (repo name)
|
||||
func convertPkgNameForURL(pkgName string) string {
|
||||
for _, regex := range gitlabRepl {
|
||||
pkgName = regex.match.ReplaceAllString(pkgName, regex.repl)
|
||||
}
|
||||
return pkgName
|
||||
}
|
||||
|
||||
// ABSPKGBUILD retrieves the PKGBUILD file to a dest directory.
|
||||
func ABSPKGBUILD(httpClient httpRequestDoer, dbName, pkgName string) ([]byte, error) {
|
||||
packageURL := getPackagePKGBUILDURL(pkgName)
|
||||
|
||||
resp, err := httpClient.Get(packageURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, ErrABSPackageNotFound
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
pkgBuild, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pkgBuild, nil
|
||||
}
|
||||
|
||||
// ABSPKGBUILDRepo retrieves the PKGBUILD repository to a dest directory.
|
||||
func ABSPKGBUILDRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder,
|
||||
dbName, pkgName, dest string, force bool,
|
||||
) (bool, error) {
|
||||
pkgURL := getPackageRepoURL(pkgName)
|
||||
|
||||
return downloadGitRepo(ctx, cmdBuilder, pkgURL,
|
||||
pkgName, dest, force, "--single-branch")
|
||||
}
|
@ -1,331 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
)
|
||||
|
||||
const gitExtrasPKGBUILD = `pkgname=git-extras
|
||||
pkgver=6.1.0
|
||||
pkgrel=1
|
||||
pkgdesc="GIT utilities -- repo summary, commit counting, repl, changelog population and more"
|
||||
arch=('any')
|
||||
url="https://github.com/tj/${pkgname}"
|
||||
license=('MIT')
|
||||
depends=('git')
|
||||
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
|
||||
sha256sums=('7be0b15ee803d76d2c2e8036f5d9db6677f2232bb8d2c4976691ff7ae026a22f')
|
||||
b2sums=('3450edecb3116e19ffcf918b118aee04f025c06d812e29e8701f35a3c466b13d2578d41c8e1ee93327743d0019bf98bb3f397189e19435f89e3a259ff1b82747')
|
||||
|
||||
package() {
|
||||
cd "${srcdir}/${pkgname}-${pkgver}"
|
||||
|
||||
# avoid annoying interactive prompts if an alias is in your gitconfig
|
||||
export GIT_CONFIG=/dev/null
|
||||
make DESTDIR="${pkgdir}" PREFIX=/usr SYSCONFDIR=/etc install
|
||||
install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||
}`
|
||||
|
||||
func Test_getPackageURL(t *testing.T) {
|
||||
t.Parallel()
|
||||
type args struct {
|
||||
db string
|
||||
pkgName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "extra package",
|
||||
args: args{
|
||||
db: "extra",
|
||||
pkgName: "kitty",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/kitty/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "core package",
|
||||
args: args{
|
||||
db: "core",
|
||||
pkgName: "linux",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "personal repo package",
|
||||
args: args{
|
||||
db: "sweswe",
|
||||
pkgName: "zabix",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/zabix/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name +",
|
||||
args: args{
|
||||
db: "core",
|
||||
pkgName: "my+package",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/my-package/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name %",
|
||||
args: args{
|
||||
db: "core",
|
||||
pkgName: "my%package",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/my-package/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name _-",
|
||||
args: args{
|
||||
db: "core",
|
||||
pkgName: "my_-package",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/my-package/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name ++",
|
||||
args: args{
|
||||
db: "core",
|
||||
pkgName: "my++package",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/mypluspluspackage/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name tree",
|
||||
args: args{
|
||||
db: "sweswe",
|
||||
pkgName: "tree",
|
||||
},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/unix-tree/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := getPackagePKGBUILDURL(tt.args.pkgName)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetABSPkgbuild(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type args struct {
|
||||
dbName string
|
||||
body string
|
||||
status int
|
||||
pkgName string
|
||||
wantURL string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "found package",
|
||||
args: args{
|
||||
dbName: "core",
|
||||
body: gitExtrasPKGBUILD,
|
||||
status: 200,
|
||||
pkgName: "git-extras",
|
||||
wantURL: "https://gitlab.archlinux.org/archlinux/packaging/packages/git-extras/-/raw/main/PKGBUILD",
|
||||
},
|
||||
want: gitExtrasPKGBUILD,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "not found package",
|
||||
args: args{
|
||||
dbName: "core",
|
||||
body: "",
|
||||
status: 404,
|
||||
pkgName: "git-git",
|
||||
wantURL: "https://gitlab.archlinux.org/archlinux/packaging/packages/git-git/-/raw/main/PKGBUILD",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
httpClient := &testClient{
|
||||
t: t,
|
||||
wantURL: tt.args.wantURL,
|
||||
body: tt.args.body,
|
||||
status: tt.args.status,
|
||||
}
|
||||
got, err := ABSPKGBUILD(httpClient, tt.args.dbName, tt.args.pkgName)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, string(got))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getPackageRepoURL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type args struct {
|
||||
pkgName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "extra package",
|
||||
args: args{pkgName: "zoxide"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/zoxide.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "core package",
|
||||
args: args{pkgName: "linux"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "personal repo package",
|
||||
args: args{pkgName: "sweswe"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/sweswe.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name +",
|
||||
args: args{pkgName: "my+package"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/my-package.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name %",
|
||||
args: args{pkgName: "my%package"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/my-package.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name _-",
|
||||
args: args{pkgName: "my_-package"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/my-package.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name ++",
|
||||
args: args{pkgName: "my++package"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/mypluspluspackage.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "special name tree",
|
||||
args: args{pkgName: "tree"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/unix-tree.git",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := getPackageRepoURL(tt.args.pkgName)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// GIVEN no previous existing folder
|
||||
// WHEN ABSPKGBUILDRepo is called
|
||||
// THEN a clone command should be formed
|
||||
func TestABSPKGBUILDRepo(t *testing.T) {
|
||||
t.Parallel()
|
||||
cmdRunner := &testRunner{}
|
||||
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux"
|
||||
if os.Getuid() == 0 {
|
||||
ld := "systemd-run"
|
||||
if path, _ := exec.LookPath(ld); path != "" {
|
||||
ld = path
|
||||
}
|
||||
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux", ld)
|
||||
}
|
||||
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
want: want,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{"--no-replace-objects"},
|
||||
},
|
||||
}
|
||||
newClone, err := ABSPKGBUILDRepo(context.Background(), cmdBuilder, "core", "linux", "/tmp/doesnt-exist", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, newClone)
|
||||
}
|
||||
|
||||
// GIVEN a previous existing folder with permissions
|
||||
// WHEN ABSPKGBUILDRepo is called
|
||||
// THEN a pull command should be formed
|
||||
func TestABSPKGBUILDRepoExistsPerms(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
os.MkdirAll(filepath.Join(dir, "linux", ".git"), 0o777)
|
||||
|
||||
want := fmt.Sprintf("/usr/local/bin/git --no-replace-objects -C %s/linux pull --rebase --autostash", dir)
|
||||
if os.Getuid() == 0 {
|
||||
ld := "systemd-run"
|
||||
if path, _ := exec.LookPath(ld); path != "" {
|
||||
ld = path
|
||||
}
|
||||
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C %s/linux pull --rebase --autostash", ld, dir)
|
||||
}
|
||||
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
want: want,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{"--no-replace-objects"},
|
||||
},
|
||||
}
|
||||
newClone, err := ABSPKGBUILDRepo(context.Background(), cmdBuilder, "core", "linux", dir, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, false, newClone)
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func AURPKGBUILD(httpClient httpRequestDoer, pkgName, aurURL string) ([]byte, error) {
|
||||
values := url.Values{}
|
||||
values.Set("h", pkgName)
|
||||
pkgURL := aurURL + "/cgit/aur.git/plain/PKGBUILD?" + values.Encode()
|
||||
|
||||
resp, err := httpClient.Get(pkgURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, ErrAURPackageNotFound{pkgName: pkgName}
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
pkgBuild, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pkgBuild, nil
|
||||
}
|
||||
|
||||
// AURPkgbuildRepo retrieves the PKGBUILD repository to a dest directory.
|
||||
func AURPKGBUILDRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder, aurURL, pkgName, dest string, force bool) (bool, error) {
|
||||
pkgURL := fmt.Sprintf("%s/%s.git", aurURL, pkgName)
|
||||
|
||||
return downloadGitRepo(ctx, cmdBuilder, pkgURL, pkgName, dest, force)
|
||||
}
|
||||
|
||||
func AURPKGBUILDRepos(
|
||||
ctx context.Context,
|
||||
cmdBuilder exe.GitCmdBuilder, logger *text.Logger,
|
||||
targets []string, aurURL, dest string, force bool,
|
||||
) (map[string]bool, error) {
|
||||
cloned := make(map[string]bool, len(targets))
|
||||
|
||||
var (
|
||||
mux sync.Mutex
|
||||
errs multierror.MultiError
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
sem := make(chan uint8, MaxConcurrentFetch)
|
||||
|
||||
for _, target := range targets {
|
||||
sem <- 1
|
||||
wg.Add(1)
|
||||
|
||||
go func(target string) {
|
||||
defer func() {
|
||||
<-sem
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
newClone, err := AURPKGBUILDRepo(ctx, cmdBuilder, aurURL, target, dest, force)
|
||||
|
||||
mux.Lock()
|
||||
progress := len(cloned)
|
||||
if err != nil {
|
||||
errs.Add(err)
|
||||
mux.Unlock()
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Failed to download PKGBUILD: %s",
|
||||
progress, len(targets), text.Cyan(target)))
|
||||
return
|
||||
}
|
||||
|
||||
cloned[target] = newClone
|
||||
progress = len(cloned)
|
||||
mux.Unlock()
|
||||
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Downloaded PKGBUILD: %s",
|
||||
progress, len(targets), text.Cyan(target)))
|
||||
}(target)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return cloned, errs.Return()
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
)
|
||||
|
||||
func TestGetAURPkgbuild(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type args struct {
|
||||
body string
|
||||
status int
|
||||
pkgName string
|
||||
wantURL string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "found package",
|
||||
args: args{
|
||||
body: gitExtrasPKGBUILD,
|
||||
status: 200,
|
||||
pkgName: "git-extras",
|
||||
wantURL: "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=git-extras",
|
||||
},
|
||||
want: gitExtrasPKGBUILD,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "not found package",
|
||||
args: args{
|
||||
body: "",
|
||||
status: 404,
|
||||
pkgName: "git-git",
|
||||
wantURL: "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=git-git",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
httpClient := &testClient{
|
||||
t: t,
|
||||
wantURL: tt.args.wantURL,
|
||||
body: tt.args.body,
|
||||
status: tt.args.status,
|
||||
}
|
||||
got, err := AURPKGBUILD(httpClient, tt.args.pkgName, "https://aur.archlinux.org")
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, string(got))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// GIVEN no previous existing folder
|
||||
// WHEN AURPKGBUILDRepo is called
|
||||
// THEN a clone command should be formed
|
||||
func TestAURPKGBUILDRepo(t *testing.T) {
|
||||
t.Parallel()
|
||||
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin"
|
||||
if os.Getuid() == 0 {
|
||||
ld := "systemd-run"
|
||||
if path, _ := exec.LookPath(ld); path != "" {
|
||||
ld = path
|
||||
}
|
||||
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin", ld)
|
||||
}
|
||||
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
want: want,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{"--no-replace-objects"},
|
||||
},
|
||||
}
|
||||
newCloned, err := AURPKGBUILDRepo(context.Background(), cmdBuilder, "https://aur.archlinux.org", "yay-bin", "/tmp/doesnt-exist", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, newCloned)
|
||||
}
|
||||
|
||||
// GIVEN a previous existing folder with permissions
|
||||
// WHEN AURPKGBUILDRepo is called
|
||||
// THEN a pull command should be formed
|
||||
func TestAURPKGBUILDRepoExistsPerms(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
||||
|
||||
want := fmt.Sprintf("/usr/local/bin/git --no-replace-objects -C %s/yay-bin pull --rebase --autostash", dir)
|
||||
if os.Getuid() == 0 {
|
||||
ld := "systemd-run"
|
||||
if path, _ := exec.LookPath(ld); path != "" {
|
||||
ld = path
|
||||
}
|
||||
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C %s/yay-bin pull --rebase --autostash", ld, dir)
|
||||
}
|
||||
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
want: want,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{"--no-replace-objects"},
|
||||
},
|
||||
}
|
||||
cloned, err := AURPKGBUILDRepo(context.Background(), cmdBuilder, "https://aur.archlinux.org", "yay-bin", dir, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, false, cloned)
|
||||
}
|
||||
|
||||
func TestAURPKGBUILDRepos(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
||||
|
||||
targets := []string{"yay", "yay-bin", "yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
want: "",
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
cloned, err := AURPKGBUILDRepos(context.Background(), cmdBuilder, newTestLogger(), targets, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"yay": true, "yay-bin": false, "yay-git": true}, cloned)
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
)
|
||||
|
||||
// ErrAURPackageNotFound means that package was not found in AUR.
|
||||
type ErrAURPackageNotFound struct {
|
||||
pkgName string
|
||||
}
|
||||
|
||||
func (e ErrAURPackageNotFound) Error() string {
|
||||
return fmt.Sprintln(gotext.Get("package not found in AUR"), ":", e.pkgName)
|
||||
}
|
||||
|
||||
type ErrGetPKGBUILDRepo struct {
|
||||
inner error
|
||||
pkgName string
|
||||
errOut string
|
||||
}
|
||||
|
||||
func (e ErrGetPKGBUILDRepo) Error() string {
|
||||
return fmt.Sprintln(gotext.Get("error fetching %s: %s", e.pkgName, e.errOut),
|
||||
"\n\t context:", e.inner.Error())
|
||||
}
|
||||
|
||||
func (e *ErrGetPKGBUILDRepo) Unwrap() error {
|
||||
return e.inner
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type httpRequestDoer interface {
|
||||
Get(string) (*http.Response, error)
|
||||
}
|
||||
|
||||
type DBSearcher interface {
|
||||
SyncPackage(string) db.IPackage
|
||||
SyncPackageFromDB(string, string) db.IPackage
|
||||
}
|
||||
|
||||
func downloadGitRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder,
|
||||
pkgURL, pkgName, dest string, force bool, gitArgs ...string,
|
||||
) (bool, error) {
|
||||
finalDir := filepath.Join(dest, pkgName)
|
||||
newClone := true
|
||||
|
||||
switch _, err := os.Stat(filepath.Join(finalDir, ".git")); {
|
||||
case os.IsNotExist(err) || (err == nil && force):
|
||||
if _, errD := os.Stat(finalDir); force && errD == nil {
|
||||
if errR := os.RemoveAll(finalDir); errR != nil {
|
||||
return false, ErrGetPKGBUILDRepo{inner: errR, pkgName: pkgName, errOut: ""}
|
||||
}
|
||||
}
|
||||
|
||||
gitArgs = append(gitArgs, pkgURL, pkgName)
|
||||
|
||||
cloneArgs := make([]string, 0, len(gitArgs)+4)
|
||||
cloneArgs = append(cloneArgs, "clone", "--no-progress")
|
||||
cloneArgs = append(cloneArgs, gitArgs...)
|
||||
cmd := cmdBuilder.BuildGitCmd(ctx, dest, cloneArgs...)
|
||||
|
||||
_, stderr, errCapture := cmdBuilder.Capture(cmd)
|
||||
if errCapture != nil {
|
||||
return false, ErrGetPKGBUILDRepo{inner: errCapture, pkgName: pkgName, errOut: stderr}
|
||||
}
|
||||
case err != nil:
|
||||
return false, ErrGetPKGBUILDRepo{
|
||||
inner: err,
|
||||
pkgName: pkgName,
|
||||
errOut: gotext.Get("error reading %s", filepath.Join(dest, pkgName, ".git")),
|
||||
}
|
||||
default:
|
||||
cmd := cmdBuilder.BuildGitCmd(ctx, filepath.Join(dest, pkgName), "pull", "--rebase", "--autostash")
|
||||
|
||||
_, stderr, errCmd := cmdBuilder.Capture(cmd)
|
||||
if errCmd != nil {
|
||||
return false, ErrGetPKGBUILDRepo{inner: errCmd, pkgName: pkgName, errOut: stderr}
|
||||
}
|
||||
|
||||
newClone = false
|
||||
}
|
||||
|
||||
return newClone, nil
|
||||
}
|
||||
|
||||
func getURLName(pkg db.IPackage) string {
|
||||
name := pkg.Base()
|
||||
if name == "" {
|
||||
name = pkg.Name()
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func PKGBUILDs(dbExecutor DBSearcher, aurClient aur.QueryClient, httpClient *http.Client,
|
||||
logger *text.Logger, targets []string, aurURL string, mode parser.TargetMode,
|
||||
) (map[string][]byte, error) {
|
||||
pkgbuilds := make(map[string][]byte, len(targets))
|
||||
|
||||
var (
|
||||
mux sync.Mutex
|
||||
errs multierror.MultiError
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
sem := make(chan uint8, MaxConcurrentFetch)
|
||||
|
||||
for _, target := range targets {
|
||||
// Probably replaceable by something in query.
|
||||
dbName, name, isAUR, toSkip := getPackageUsableName(dbExecutor, aurClient, logger, target, mode)
|
||||
if toSkip {
|
||||
continue
|
||||
}
|
||||
|
||||
sem <- 1
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func(target, dbName, pkgName string, aur bool) {
|
||||
var (
|
||||
err error
|
||||
pkgbuild []byte
|
||||
)
|
||||
|
||||
if aur {
|
||||
pkgbuild, err = AURPKGBUILD(httpClient, pkgName, aurURL)
|
||||
} else {
|
||||
pkgbuild, err = ABSPKGBUILD(httpClient, dbName, pkgName)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
mux.Lock()
|
||||
pkgbuilds[target] = pkgbuild
|
||||
mux.Unlock()
|
||||
} else {
|
||||
errs.Add(err)
|
||||
}
|
||||
|
||||
<-sem
|
||||
wg.Done()
|
||||
}(target, dbName, name, isAUR)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return pkgbuilds, errs.Return()
|
||||
}
|
||||
|
||||
func PKGBUILDRepos(ctx context.Context, dbExecutor DBSearcher, aurClient aur.QueryClient,
|
||||
cmdBuilder exe.GitCmdBuilder, logger *text.Logger,
|
||||
targets []string, mode parser.TargetMode, aurURL, dest string, force bool,
|
||||
) (map[string]bool, error) {
|
||||
cloned := make(map[string]bool, len(targets))
|
||||
|
||||
var (
|
||||
mux sync.Mutex
|
||||
errs multierror.MultiError
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
sem := make(chan uint8, MaxConcurrentFetch)
|
||||
|
||||
for _, target := range targets {
|
||||
// Probably replaceable by something in query.
|
||||
dbName, name, isAUR, toSkip := getPackageUsableName(dbExecutor, aurClient, logger, target, mode)
|
||||
if toSkip {
|
||||
continue
|
||||
}
|
||||
|
||||
sem <- 1
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func(target, dbName, pkgName string, aur bool) {
|
||||
var (
|
||||
err error
|
||||
newClone bool
|
||||
)
|
||||
|
||||
if aur {
|
||||
newClone, err = AURPKGBUILDRepo(ctx, cmdBuilder, aurURL, pkgName, dest, force)
|
||||
} else {
|
||||
newClone, err = ABSPKGBUILDRepo(ctx, cmdBuilder, dbName, pkgName, dest, force)
|
||||
}
|
||||
|
||||
progress := 0
|
||||
|
||||
if err != nil {
|
||||
errs.Add(err)
|
||||
} else {
|
||||
mux.Lock()
|
||||
cloned[target] = newClone
|
||||
progress = len(cloned)
|
||||
mux.Unlock()
|
||||
}
|
||||
|
||||
if aur {
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Downloaded PKGBUILD: %s",
|
||||
progress, len(targets), text.Cyan(pkgName)))
|
||||
} else {
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Downloaded PKGBUILD from ABS: %s",
|
||||
progress, len(targets), text.Cyan(pkgName)))
|
||||
}
|
||||
|
||||
<-sem
|
||||
|
||||
wg.Done()
|
||||
}(target, dbName, name, isAUR)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return cloned, errs.Return()
|
||||
}
|
||||
|
||||
// TODO: replace with dep.ResolveTargets.
|
||||
func getPackageUsableName(dbExecutor DBSearcher, aurClient aur.QueryClient,
|
||||
logger *text.Logger, target string, mode parser.TargetMode,
|
||||
) (dbname, pkgname string, isAUR, toSkip bool) {
|
||||
dbName, name := text.SplitDBFromName(target)
|
||||
if dbName != "aur" && mode.AtLeastRepo() {
|
||||
var pkg db.IPackage
|
||||
if dbName != "" {
|
||||
pkg = dbExecutor.SyncPackageFromDB(name, dbName)
|
||||
} else {
|
||||
pkg = dbExecutor.SyncPackage(name)
|
||||
}
|
||||
|
||||
if pkg != nil {
|
||||
name = getURLName(pkg)
|
||||
dbName = pkg.DB().Name()
|
||||
return dbName, name, false, false
|
||||
}
|
||||
|
||||
// If the package is not found in the database and it was expected to be
|
||||
if pkg == nil && dbName != "" {
|
||||
return dbName, name, true, true
|
||||
}
|
||||
}
|
||||
|
||||
if mode == parser.ModeRepo {
|
||||
return dbName, name, true, true
|
||||
}
|
||||
|
||||
pkgs, err := aurClient.Get(context.Background(), &aur.Query{
|
||||
By: aur.Name,
|
||||
Contains: false,
|
||||
Needles: []string{name},
|
||||
})
|
||||
if err != nil {
|
||||
logger.Warnln(err)
|
||||
return dbName, name, true, true
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
return dbName, name, true, true
|
||||
}
|
||||
|
||||
return "aur", name, true, false
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func TestIntegrationPKGBUILDReposDefinedDBClone(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"core/linux", "yay-bin", "yay-git"}
|
||||
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
cmdRunner := &exe.OSRunner{Log: testLogger}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "git",
|
||||
GitFlags: []string{},
|
||||
Log: testLogger,
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"linux": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, testLogger.Child("test"),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"core/linux": true, "yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
func TestIntegrationPKGBUILDReposNotExist(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
cmdRunner := &exe.OSRunner{Log: testLogger}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "git",
|
||||
GitFlags: []string{},
|
||||
Log: testLogger,
|
||||
}
|
||||
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, testLogger.Child("test"),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN defining as specified targets
|
||||
// THEN all aur be found and cloned
|
||||
func TestIntegrationPKGBUILDFull(t *testing.T) {
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
targets := []string{"core/linux", "aur/yay-bin", "yay-git"}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"linux": "core"},
|
||||
}
|
||||
|
||||
fetched, err := PKGBUILDs(searcher, mockClient, &http.Client{}, testLogger.Child("test"),
|
||||
targets, "https://aur.archlinux.org", parser.ModeAny)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
for _, target := range targets {
|
||||
assert.Contains(t, fetched, target)
|
||||
assert.NotEmpty(t, fetched[target])
|
||||
}
|
||||
}
|
@ -1,281 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func newTestLogger() *text.Logger {
|
||||
return text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), true, "test")
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// GIVEN package in repo is already present
|
||||
// WHEN defining package db as a target
|
||||
// THEN all should be found and cloned, except the repo one
|
||||
func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
|
||||
os.MkdirAll(filepath.Join(dir, "yay", ".git"), 0o777)
|
||||
|
||||
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
Log: testLogger,
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"core/yay": false, "yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN defining package db as a target
|
||||
// THEN all should be found and cloned
|
||||
func TestPKGBUILDReposDefinedDBClone(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"core/yay": true, "yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN defining as non specified targets
|
||||
// THEN all should be found and cloned
|
||||
func TestPKGBUILDReposClone(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"yay", "yay-bin", "yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"yay": true, "yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo but wrong db
|
||||
// WHEN defining as non specified targets
|
||||
// THEN all aur be found and cloned
|
||||
func TestPKGBUILDReposNotFound(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"extra/yay", "yay-bin", "yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN defining as non specified targets in repo mode
|
||||
// THEN only repo should be cloned
|
||||
func TestPKGBUILDReposRepoMode(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"yay", "yay-bin", "yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeRepo, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"yay": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN defining as specified targets
|
||||
// THEN all aur be found and cloned
|
||||
func TestPKGBUILDFull(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil
|
||||
},
|
||||
}
|
||||
gock.New("https://aur.archlinux.org").
|
||||
Get("/cgit/aur.git/plain/PKGBUILD").MatchParam("h", "yay-git").
|
||||
Reply(200).
|
||||
BodyString("example_yay-git")
|
||||
gock.New("https://aur.archlinux.org").
|
||||
Get("/cgit/aur.git/plain/PKGBUILD").MatchParam("h", "yay-bin").
|
||||
Reply(200).
|
||||
BodyString("example_yay-bin")
|
||||
|
||||
gock.New("https://gitlab.archlinux.org/").
|
||||
Get("archlinux/packaging/packages/yay/-/raw/main/PKGBUILD").
|
||||
Reply(200).
|
||||
BodyString("example_yay")
|
||||
|
||||
defer gock.Off()
|
||||
targets := []string{"core/yay", "aur/yay-bin", "yay-git"}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
|
||||
fetched, err := PKGBUILDs(searcher, mockClient, &http.Client{}, newTestLogger(),
|
||||
targets, "https://aur.archlinux.org", parser.ModeAny)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string][]byte{
|
||||
"core/yay": []byte("example_yay"),
|
||||
"aur/yay-bin": []byte("example_yay-bin"),
|
||||
"yay-git": []byte("example_yay-git"),
|
||||
}, fetched)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN aur packages are not found
|
||||
// only repo should be cloned
|
||||
func TestPKGBUILDReposMissingAUR(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"core/yay", "aur/yay-bin", "aur/yay-git"}
|
||||
cmdRunner := &testRunner{}
|
||||
cmdBuilder := &testGitBuilder{
|
||||
index: 0,
|
||||
test: t,
|
||||
parentBuilder: &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"core/yay": true}, cloned)
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
)
|
||||
|
||||
type testRunner struct{}
|
||||
|
||||
func (t *testRunner) Capture(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return "", "", nil
|
||||
}
|
||||
|
||||
func (t *testRunner) Show(cmd *exec.Cmd) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type testGitBuilder struct {
|
||||
index int
|
||||
test *testing.T
|
||||
want string
|
||||
parentBuilder *exe.CmdBuilder
|
||||
}
|
||||
|
||||
func (t *testGitBuilder) BuildGitCmd(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd {
|
||||
cmd := t.parentBuilder.BuildGitCmd(ctx, dir, extraArgs...)
|
||||
|
||||
if t.want != "" {
|
||||
assert.Equal(t.test, t.want, cmd.String())
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *testGitBuilder) Show(cmd *exec.Cmd) error {
|
||||
return c.parentBuilder.Show(cmd)
|
||||
}
|
||||
|
||||
func (c *testGitBuilder) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) {
|
||||
return c.parentBuilder.Capture(cmd)
|
||||
}
|
||||
|
||||
type (
|
||||
testDB struct {
|
||||
alpm.IDB
|
||||
name string
|
||||
}
|
||||
testPackage struct {
|
||||
db.IPackage
|
||||
name string
|
||||
base string
|
||||
db *testDB
|
||||
}
|
||||
testDBSearcher struct {
|
||||
absPackagesDB map[string]string
|
||||
}
|
||||
|
||||
testClient struct {
|
||||
t *testing.T
|
||||
wantURL string
|
||||
body string
|
||||
status int
|
||||
}
|
||||
)
|
||||
|
||||
func (d *testDB) Name() string {
|
||||
return d.name
|
||||
}
|
||||
|
||||
func (p *testPackage) Name() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
func (p *testPackage) Base() string {
|
||||
return p.base
|
||||
}
|
||||
|
||||
func (p *testPackage) DB() alpm.IDB {
|
||||
return p.db
|
||||
}
|
||||
|
||||
func (d *testDBSearcher) SyncPackage(name string) db.IPackage {
|
||||
if v, ok := d.absPackagesDB[name]; ok {
|
||||
return &testPackage{
|
||||
name: name,
|
||||
base: name,
|
||||
db: &testDB{name: v},
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *testDBSearcher) SyncPackageFromDB(name string, db string) db.IPackage {
|
||||
if v, ok := d.absPackagesDB[name]; ok && v == db {
|
||||
return &testPackage{
|
||||
name: name,
|
||||
base: name,
|
||||
db: &testDB{name: v},
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *testClient) Get(url string) (*http.Response, error) {
|
||||
assert.Equal(t.t, t.wantURL, url)
|
||||
return &http.Response{StatusCode: t.status, Body: io.NopCloser(strings.NewReader(t.body))}, nil
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package intrange
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
)
|
||||
|
||||
// IntRange stores a max and min amount for range.
|
||||
type IntRange struct {
|
||||
min int
|
||||
max int
|
||||
}
|
||||
|
||||
// IntRanges is a slice of IntRange.
|
||||
type IntRanges []IntRange
|
||||
|
||||
func makeIntRange(minVal, maxVal int) IntRange {
|
||||
return IntRange{
|
||||
min: minVal,
|
||||
max: maxVal,
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns true if the argument n is included in the closed range
|
||||
// between min and max.
|
||||
func (r IntRange) Get(n int) bool {
|
||||
return n >= r.min && n <= r.max
|
||||
}
|
||||
|
||||
// Get returns true if the argument n is included in the closed range
|
||||
// between min and max of any of the provided IntRanges.
|
||||
func (rs IntRanges) Get(n int) bool {
|
||||
for _, r := range rs {
|
||||
if r.Get(n) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ParseNumberMenu parses input for number menus split by spaces or commas
|
||||
// supports individual selection: 1 2 3 4
|
||||
// supports range selections: 1-4 10-20
|
||||
// supports negation: ^1 ^1-4
|
||||
//
|
||||
// include and excule holds numbers that should be added and should not be added
|
||||
// respectively. other holds anything that can't be parsed as an int. This is
|
||||
// intended to allow words inside of number menus. e.g. 'all' 'none' 'abort'
|
||||
// of course the implementation is up to the caller, this function mearley parses
|
||||
// the input and organizes it.
|
||||
func ParseNumberMenu(input string) (include, exclude IntRanges,
|
||||
otherInclude, otherExclude mapset.Set[string],
|
||||
) {
|
||||
include = make(IntRanges, 0)
|
||||
exclude = make(IntRanges, 0)
|
||||
otherInclude = mapset.NewThreadUnsafeSet[string]()
|
||||
otherExclude = mapset.NewThreadUnsafeSet[string]()
|
||||
|
||||
words := strings.FieldsFunc(input, func(c rune) bool {
|
||||
return unicode.IsSpace(c) || c == ','
|
||||
})
|
||||
|
||||
for _, word := range words {
|
||||
var (
|
||||
num1 int
|
||||
num2 int
|
||||
err error
|
||||
)
|
||||
|
||||
invert := false
|
||||
other := otherInclude
|
||||
|
||||
if word[0] == '^' {
|
||||
invert = true
|
||||
other = otherExclude
|
||||
word = word[1:]
|
||||
}
|
||||
|
||||
ranges := strings.SplitN(word, "-", 2)
|
||||
|
||||
num1, err = strconv.Atoi(ranges[0])
|
||||
if err != nil {
|
||||
other.Add(strings.ToLower(word))
|
||||
continue
|
||||
}
|
||||
|
||||
if len(ranges) == 2 {
|
||||
num2, err = strconv.Atoi(ranges[1])
|
||||
if err != nil {
|
||||
other.Add(strings.ToLower(word))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
num2 = num1
|
||||
}
|
||||
|
||||
mi := min(num1, num2)
|
||||
ma := max(num1, num2)
|
||||
|
||||
if !invert {
|
||||
include = append(include, makeIntRange(mi, ma))
|
||||
} else {
|
||||
exclude = append(exclude, makeIntRange(mi, ma))
|
||||
}
|
||||
}
|
||||
|
||||
return include, exclude, otherInclude, otherExclude
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package intrange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseNumberMenu(t *testing.T) {
|
||||
t.Parallel()
|
||||
type result struct {
|
||||
Include IntRanges
|
||||
Exclude IntRanges
|
||||
OtherInclude mapset.Set[string]
|
||||
OtherExclude mapset.Set[string]
|
||||
}
|
||||
|
||||
inputs := []string{
|
||||
"1 2 3 4 5",
|
||||
"1-10 5-15",
|
||||
"10-5 90-85",
|
||||
"1 ^2 ^10-5 99 ^40-38 ^123 60-62",
|
||||
"abort all none",
|
||||
"a-b ^a-b ^abort",
|
||||
"-9223372036854775809-9223372036854775809",
|
||||
"1\t2 3 4\t\t \t 5",
|
||||
"1 2,3, 4, 5,6 ,7 ,8",
|
||||
"",
|
||||
" \t ",
|
||||
"A B C D E",
|
||||
}
|
||||
|
||||
expected := []result{
|
||||
{IntRanges{
|
||||
makeIntRange(1, 1),
|
||||
makeIntRange(2, 2),
|
||||
makeIntRange(3, 3),
|
||||
makeIntRange(4, 4),
|
||||
makeIntRange(5, 5),
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(1, 10),
|
||||
makeIntRange(5, 15),
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(5, 10),
|
||||
makeIntRange(85, 90),
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{
|
||||
IntRanges{
|
||||
makeIntRange(1, 1),
|
||||
makeIntRange(99, 99),
|
||||
makeIntRange(60, 62),
|
||||
},
|
||||
IntRanges{
|
||||
makeIntRange(2, 2),
|
||||
makeIntRange(5, 10),
|
||||
makeIntRange(38, 40),
|
||||
makeIntRange(123, 123),
|
||||
},
|
||||
mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string](),
|
||||
},
|
||||
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("abort", "all", "none"), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("a-b"), mapset.NewThreadUnsafeSet("abort", "a-b")},
|
||||
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("-9223372036854775809-9223372036854775809"), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(1, 1),
|
||||
makeIntRange(2, 2),
|
||||
makeIntRange(3, 3),
|
||||
makeIntRange(4, 4),
|
||||
makeIntRange(5, 5),
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(1, 1),
|
||||
makeIntRange(2, 2),
|
||||
makeIntRange(3, 3),
|
||||
makeIntRange(4, 4),
|
||||
makeIntRange(5, 5),
|
||||
makeIntRange(6, 6),
|
||||
makeIntRange(7, 7),
|
||||
makeIntRange(8, 8),
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("a", "b", "c", "d", "e"), mapset.NewThreadUnsafeSet[string]()},
|
||||
}
|
||||
|
||||
for n, in := range inputs {
|
||||
res := expected[n]
|
||||
include, exclude, otherInclude, otherExclude := ParseNumberMenu(in)
|
||||
|
||||
assert.True(t, intRangesEqual(include, res.Include), "Test %d Failed: Expected: include=%+v got include=%+v", n+1, res.Include, include)
|
||||
assert.True(t, intRangesEqual(exclude, res.Exclude), "Test %d Failed: Expected: exclude=%+v got exclude=%+v", n+1, res.Exclude, exclude)
|
||||
assert.True(t, otherInclude.Equal(res.OtherInclude), "Test %d Failed: Expected: otherInclude=%+v got otherInclude=%+v", n+1, res.OtherInclude, otherInclude)
|
||||
assert.True(t, otherExclude.Equal(res.OtherExclude), "Test %d Failed: Expected: otherExclude=%+v got otherExclude=%+v", n+1, res.OtherExclude, otherExclude)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntRange_Get(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
min int
|
||||
max int
|
||||
}
|
||||
type args struct {
|
||||
n int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{name: "normal range true", fields: fields{0, 10}, args: args{5}, want: true},
|
||||
{name: "normal start range true", fields: fields{0, 10}, args: args{0}, want: true},
|
||||
{name: "normal end range true", fields: fields{0, 10}, args: args{10}, want: true},
|
||||
{name: "small range true", fields: fields{1, 1}, args: args{1}, want: true},
|
||||
{name: "normal start range false", fields: fields{1, 2}, args: args{0}, want: false},
|
||||
{name: "normal end range false", fields: fields{1, 2}, args: args{3}, want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
r := IntRange{
|
||||
min: tt.fields.min,
|
||||
max: tt.fields.max,
|
||||
}
|
||||
if got := r.Get(tt.args.n); got != tt.want {
|
||||
t.Errorf("IntRange.Get() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func intRangesEqual(a, b IntRanges) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for n := range a {
|
||||
r1 := a[n]
|
||||
r2 := b[n]
|
||||
|
||||
if r1.min != r2.min || r1.max != r2.max {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func TestIntRanges_Get(t *testing.T) {
|
||||
t.Parallel()
|
||||
type args struct {
|
||||
n int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
rs IntRanges
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{name: "normal range true", rs: IntRanges{{0, 10}}, args: args{5}, want: true},
|
||||
{name: "normal ranges in between true", rs: IntRanges{{0, 4}, {5, 10}}, args: args{5}, want: true},
|
||||
{name: "normal ranges in between false", rs: IntRanges{{0, 4}, {6, 10}}, args: args{5}, want: false},
|
||||
{name: "normal start range true", rs: IntRanges{{0, 10}}, args: args{0}, want: true},
|
||||
{name: "normal end range true", rs: IntRanges{{0, 10}}, args: args{10}, want: true},
|
||||
{name: "small range true", rs: IntRanges{{1, 1}, {3, 3}}, args: args{1}, want: true},
|
||||
{name: "normal start range false", rs: IntRanges{{1, 2}}, args: args{0}, want: false},
|
||||
{name: "normal end range false", rs: IntRanges{{1, 2}}, args: args{3}, want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := tt.rs.Get(tt.args.n); got != tt.want {
|
||||
t.Errorf("IntRanges.Get() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
// Clean Build Menu functions
|
||||
package menus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func anyExistInCache(pkgbuildDirs map[string]string) bool {
|
||||
for _, dir := range pkgbuildDirs {
|
||||
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func CleanFn(ctx context.Context, run *runtime.Runtime, w io.Writer,
|
||||
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
|
||||
) error {
|
||||
if len(pkgbuildDirsByBase) == 0 {
|
||||
return nil // no work to do
|
||||
}
|
||||
|
||||
if !anyExistInCache(pkgbuildDirsByBase) {
|
||||
return nil
|
||||
}
|
||||
|
||||
skipFunc := func(pkg string) bool {
|
||||
dir := pkgbuildDirsByBase[pkg]
|
||||
// TOFIX: new install engine dir will always exist, check if unclean instead
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
bases := make([]string, 0, len(pkgbuildDirsByBase))
|
||||
for pkg := range pkgbuildDirsByBase {
|
||||
bases = append(bases, pkg)
|
||||
}
|
||||
|
||||
toClean, errClean := selectionMenu(run.Logger, pkgbuildDirsByBase, bases, installed,
|
||||
gotext.Get("Packages to cleanBuild?"),
|
||||
settings.NoConfirm, run.Cfg.AnswerClean, skipFunc)
|
||||
if errClean != nil {
|
||||
return errClean
|
||||
}
|
||||
|
||||
for i, base := range toClean {
|
||||
dir := pkgbuildDirsByBase[base]
|
||||
run.Logger.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(toClean), text.Cyan(dir)))
|
||||
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildGitCmd(ctx, dir, "reset", "--hard", "origin/HEAD")); err != nil {
|
||||
run.Logger.Warnln(gotext.Get("Unable to clean:"), dir)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildGitCmd(ctx, dir, "clean", "-fdx")); err != nil {
|
||||
run.Logger.Warnln(gotext.Get("Unable to clean:"), dir)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
// file dedicated to diff menu
|
||||
package menus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
const (
|
||||
gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||
gitDiffRefName = "AUR_SEEN"
|
||||
)
|
||||
|
||||
func showPkgbuildDiffs(ctx context.Context, cmdBuilder exe.ICmdBuilder, logger *text.Logger,
|
||||
pkgbuildDirs map[string]string, bases []string,
|
||||
) error {
|
||||
var errMulti multierror.MultiError
|
||||
|
||||
for _, pkg := range bases {
|
||||
dir := pkgbuildDirs[pkg]
|
||||
|
||||
start, err := getLastSeenHash(ctx, cmdBuilder, dir)
|
||||
if err != nil {
|
||||
errMulti.Add(err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if start != gitEmptyTree {
|
||||
hasDiff, err := gitHasDiff(ctx, cmdBuilder, dir)
|
||||
if err != nil {
|
||||
errMulti.Add(err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if !hasDiff {
|
||||
logger.Warnln(gotext.Get("%s: No changes -- skipping", text.Cyan(pkg)))
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"diff",
|
||||
start + "..HEAD@{upstream}", "--src-prefix",
|
||||
dir + "/", "--dst-prefix", dir + "/", "--", ".", ":(exclude).SRCINFO",
|
||||
}
|
||||
if text.UseColor {
|
||||
args = append(args, "--color=always")
|
||||
} else {
|
||||
args = append(args, "--color=never")
|
||||
}
|
||||
|
||||
_ = cmdBuilder.Show(cmdBuilder.BuildGitCmd(ctx, dir, args...))
|
||||
}
|
||||
|
||||
return errMulti.Return()
|
||||
}
|
||||
|
||||
// Check whether or not a diff exists between the last reviewed diff and
|
||||
// HEAD@{upstream}.
|
||||
func gitHasDiff(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) (bool, error) {
|
||||
if gitHasLastSeenRef(ctx, cmdBuilder, dir) {
|
||||
stdout, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(ctx, dir, "rev-parse", gitDiffRefName, "HEAD@{upstream}"))
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%s%w", stderr, err)
|
||||
}
|
||||
|
||||
lines := strings.Split(stdout, "\n")
|
||||
lastseen := lines[0]
|
||||
upstream := lines[1]
|
||||
|
||||
return lastseen != upstream, nil
|
||||
}
|
||||
// If AUR_SEEN does not exists, we have never reviewed a diff for this package
|
||||
// and should display it.
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Return whether or not we have reviewed a diff yet. It checks for the existence of
|
||||
// AUR_SEEN in the git ref-list.
|
||||
func gitHasLastSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) bool {
|
||||
_, _, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(ctx,
|
||||
dir, "rev-parse", "--quiet", "--verify", gitDiffRefName))
|
||||
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Returns the last reviewed hash. If AUR_SEEN exists it will return this hash.
|
||||
// If it does not it will return empty tree as no diff have been reviewed yet.
|
||||
func getLastSeenHash(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) (string, error) {
|
||||
if gitHasLastSeenRef(ctx, cmdBuilder, dir) {
|
||||
stdout, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(ctx,
|
||||
dir, "rev-parse", gitDiffRefName))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s %w", stderr, err)
|
||||
}
|
||||
|
||||
lines := strings.Split(stdout, "\n")
|
||||
|
||||
return lines[0], nil
|
||||
}
|
||||
|
||||
return gitEmptyTree, nil
|
||||
}
|
||||
|
||||
// Update the AUR_SEEN ref to HEAD. We use this ref to determine which diff were
|
||||
// reviewed by the user.
|
||||
func gitUpdateSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) error {
|
||||
_, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(ctx,
|
||||
dir, "update-ref", gitDiffRefName, "HEAD"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s %w", stderr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func updatePkgbuildSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgbuildDirs map[string]string, bases []string) error {
|
||||
var errMulti multierror.MultiError
|
||||
|
||||
for _, pkg := range bases {
|
||||
dir := pkgbuildDirs[pkg]
|
||||
if err := gitUpdateSeenRef(ctx, cmdBuilder, dir); err != nil {
|
||||
errMulti.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
return errMulti.Return()
|
||||
}
|
||||
|
||||
func DiffFn(ctx context.Context, run *runtime.Runtime, w io.Writer,
|
||||
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
|
||||
) error {
|
||||
if len(pkgbuildDirsByBase) == 0 {
|
||||
return nil // no work to do
|
||||
}
|
||||
|
||||
bases := make([]string, 0, len(pkgbuildDirsByBase))
|
||||
for base := range pkgbuildDirsByBase {
|
||||
bases = append(bases, base)
|
||||
}
|
||||
|
||||
toDiff, errMenu := selectionMenu(run.Logger, pkgbuildDirsByBase, bases, installed, gotext.Get("Diffs to show?"),
|
||||
settings.NoConfirm, run.Cfg.AnswerDiff, nil)
|
||||
if errMenu != nil || len(toDiff) == 0 {
|
||||
return errMenu
|
||||
}
|
||||
|
||||
if errD := showPkgbuildDiffs(ctx, run.CmdBuilder, run.Logger, pkgbuildDirsByBase, toDiff); errD != nil {
|
||||
return errD
|
||||
}
|
||||
|
||||
run.Logger.Println()
|
||||
|
||||
if !run.Logger.ContinueTask(gotext.Get("Proceed with install?"), true, false) {
|
||||
return settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
if errUpd := updatePkgbuildSeenRef(ctx, run.CmdBuilder, pkgbuildDirsByBase, toDiff); errUpd != nil {
|
||||
return errUpd
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
// edit menu
|
||||
package menus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
// Editor returns the preferred system editor.
|
||||
func editor(log *text.Logger, editorConfig, editorFlags string, noConfirm bool) (editor string, args []string) {
|
||||
switch {
|
||||
case editorConfig != "":
|
||||
editor, err := exec.LookPath(editorConfig)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
} else {
|
||||
return editor, strings.Fields(editorFlags)
|
||||
}
|
||||
|
||||
fallthrough
|
||||
case os.Getenv("VISUAL") != "":
|
||||
if editorArgs := strings.Fields(os.Getenv("VISUAL")); len(editorArgs) != 0 {
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
} else {
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
}
|
||||
|
||||
fallthrough
|
||||
case os.Getenv("EDITOR") != "":
|
||||
if editorArgs := strings.Fields(os.Getenv("EDITOR")); len(editorArgs) != 0 {
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
} else {
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
}
|
||||
|
||||
fallthrough
|
||||
default:
|
||||
log.Errorln("\n", gotext.Get("%s is not set", text.Bold(text.Cyan("$EDITOR"))))
|
||||
log.Warnln(gotext.Get("Add %s or %s to your environment variables", text.Bold(text.Cyan("$EDITOR")), text.Bold(text.Cyan("$VISUAL"))))
|
||||
|
||||
for {
|
||||
log.Infoln(gotext.Get("Edit PKGBUILD with?"))
|
||||
|
||||
editorInput, err := log.GetInput("", noConfirm)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
editorArgs := strings.Fields(editorInput)
|
||||
if len(editorArgs) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func editPkgbuilds(log *text.Logger, pkgbuildDirs map[string]string, bases []string, editorConfig,
|
||||
editorFlags string, srcinfos map[string]*gosrc.Srcinfo, noConfirm bool,
|
||||
) error {
|
||||
pkgbuilds := make([]string, 0, len(bases))
|
||||
|
||||
for _, pkg := range bases {
|
||||
dir := pkgbuildDirs[pkg]
|
||||
pkgbuilds = append(pkgbuilds, filepath.Join(dir, "PKGBUILD"))
|
||||
|
||||
if srcinfos != nil {
|
||||
for _, splitPkg := range srcinfos[pkg].SplitPackages() {
|
||||
if splitPkg.Install != "" {
|
||||
pkgbuilds = append(pkgbuilds, filepath.Join(dir, splitPkg.Install))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(pkgbuilds) > 0 {
|
||||
editor, editorArgs := editor(log, editorConfig, editorFlags, noConfirm)
|
||||
editorArgs = append(editorArgs, pkgbuilds...)
|
||||
editcmd := exec.Command(editor, editorArgs...)
|
||||
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||
|
||||
if err := editcmd.Run(); err != nil {
|
||||
return errors.New(gotext.Get("editor did not exit successfully, aborting: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func EditFn(ctx context.Context, run *runtime.Runtime, w io.Writer,
|
||||
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
|
||||
) error {
|
||||
if len(pkgbuildDirsByBase) == 0 {
|
||||
return nil // no work to do
|
||||
}
|
||||
|
||||
bases := make([]string, 0, len(pkgbuildDirsByBase))
|
||||
for pkg := range pkgbuildDirsByBase {
|
||||
bases = append(bases, pkg)
|
||||
}
|
||||
|
||||
toEdit, errMenu := selectionMenu(run.Logger, pkgbuildDirsByBase, bases, installed,
|
||||
gotext.Get("PKGBUILDs to edit?"), settings.NoConfirm, run.Cfg.AnswerEdit, nil)
|
||||
if errMenu != nil || len(toEdit) == 0 {
|
||||
return errMenu
|
||||
}
|
||||
|
||||
// TOFIX: remove or use srcinfo data
|
||||
if errEdit := editPkgbuilds(run.Logger, pkgbuildDirsByBase,
|
||||
toEdit, run.Cfg.Editor, run.Cfg.EditorFlags, nil, settings.NoConfirm); errEdit != nil {
|
||||
return errEdit
|
||||
}
|
||||
|
||||
run.Logger.Println()
|
||||
|
||||
if !run.Logger.ContinueTask(gotext.Get("Proceed with install?"), true, false) {
|
||||
return settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
package menus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
)
|
||||
|
||||
func pkgbuildNumberMenu(logger *text.Logger, pkgbuildDirs map[string]string,
|
||||
bases []string, installed mapset.Set[string],
|
||||
) {
|
||||
toPrint := ""
|
||||
|
||||
for n, pkgBase := range bases {
|
||||
dir := pkgbuildDirs[pkgBase]
|
||||
toPrint += fmt.Sprintf(text.Magenta("%3d")+" %-40s", len(pkgbuildDirs)-n,
|
||||
text.Bold(pkgBase))
|
||||
|
||||
if installed.Contains(pkgBase) {
|
||||
toPrint += text.Bold(text.Green(gotext.Get(" (Installed)")))
|
||||
}
|
||||
|
||||
// TODO: remove or refactor to check if git dir is unclean
|
||||
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
||||
toPrint += text.Bold(text.Green(gotext.Get(" (Build Files Exist)")))
|
||||
}
|
||||
|
||||
toPrint += "\n"
|
||||
}
|
||||
|
||||
logger.Print(toPrint)
|
||||
}
|
||||
|
||||
func selectionMenu(logger *text.Logger, pkgbuildDirs map[string]string, bases []string, installed mapset.Set[string],
|
||||
message string, noConfirm bool, defaultAnswer string, skipFunc func(string) bool,
|
||||
) ([]string, error) {
|
||||
selected := make([]string, 0)
|
||||
|
||||
pkgbuildNumberMenu(logger, pkgbuildDirs, bases, installed)
|
||||
|
||||
logger.Infoln(message)
|
||||
logger.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
|
||||
|
||||
selectInput, err := logger.GetInput(defaultAnswer, noConfirm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
eInclude, eExclude, eOtherInclude, eOtherExclude := intrange.ParseNumberMenu(selectInput)
|
||||
eIsInclude := len(eExclude) == 0 && eOtherExclude.Cardinality() == 0
|
||||
|
||||
if eOtherInclude.Contains("abort") || eOtherInclude.Contains("ab") {
|
||||
return nil, settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
if eOtherInclude.Contains("n") || eOtherInclude.Contains("none") {
|
||||
return selected, nil
|
||||
}
|
||||
|
||||
for i, pkgBase := range bases {
|
||||
if skipFunc != nil && skipFunc(pkgBase) {
|
||||
continue
|
||||
}
|
||||
|
||||
anyInstalled := installed.Contains(pkgBase)
|
||||
|
||||
if !eIsInclude && eExclude.Get(len(bases)-i) {
|
||||
continue
|
||||
}
|
||||
|
||||
if anyInstalled && (eOtherInclude.Contains("i") || eOtherInclude.Contains("installed")) {
|
||||
selected = append(selected, pkgBase)
|
||||
continue
|
||||
}
|
||||
|
||||
if !anyInstalled && (eOtherInclude.Contains("no") || eOtherInclude.Contains("notinstalled")) {
|
||||
selected = append(selected, pkgBase)
|
||||
continue
|
||||
}
|
||||
|
||||
if eOtherInclude.Contains("a") || eOtherInclude.Contains("all") {
|
||||
selected = append(selected, pkgBase)
|
||||
continue
|
||||
}
|
||||
|
||||
if eIsInclude && (eInclude.Get(len(bases)-i) || eOtherInclude.Contains(pkgBase)) {
|
||||
selected = append(selected, pkgBase)
|
||||
}
|
||||
|
||||
if !eIsInclude && (!eExclude.Get(len(bases)-i) && !eOtherExclude.Contains(pkgBase)) {
|
||||
selected = append(selected, pkgBase)
|
||||
}
|
||||
}
|
||||
|
||||
return selected, nil
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package multierror
|
||||
|
||||
import "sync"
|
||||
|
||||
// MultiError type handles error accumulation from goroutines.
|
||||
type MultiError struct {
|
||||
Errors []error
|
||||
mux sync.Mutex
|
||||
}
|
||||
|
||||
// Error turns the MultiError structure into a string.
|
||||
func (err *MultiError) Error() string {
|
||||
str := ""
|
||||
|
||||
for _, e := range err.Errors {
|
||||
str += e.Error() + "\n"
|
||||
}
|
||||
|
||||
return str[:len(str)-1]
|
||||
}
|
||||
|
||||
// Add adds an error to the Multierror structure.
|
||||
func (err *MultiError) Add(e error) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
|
||||
err.mux.Lock()
|
||||
err.Errors = append(err.Errors, e)
|
||||
err.mux.Unlock()
|
||||
}
|
||||
|
||||
// Return is used as a wrapper on return on whether to return the
|
||||
// MultiError Structure if errors exist or nil instead of delivering an empty structure.
|
||||
func (err *MultiError) Return() error {
|
||||
if len(err.Errors) > 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
[1m[35m2019-12-20[0m[0m [1mXorg cleanup requires manual intervention[0m
|
||||
[1m[35m2020-01-04[0m[0m [1mNow using Zstandard instead of xz for package compression[0m
|
||||
[1m[35m2020-01-15[0m[0m [1mrsync compatibility[0m
|
||||
[1m[35m2020-02-17[0m[0m [1msshd needs restarting after upgrading to openssh-8.2p1[0m
|
||||
[1m[35m2020-02-22[0m[0m [1mPlanet Arch Linux migration[0m
|
||||
[1m[35m2020-02-24[0m[0m [1mThe Future of the Arch Linux Project Leader[0m
|
||||
[1m[35m2020-03-01[0m[0m [1mfirewalld>=0.8.1-2 update requires manual intervention[0m
|
||||
[1m[35m2020-03-19[0m[0m [1mhplip 3.20.3-2 update requires manual intervention[0m
|
||||
[1m[35m2020-04-13[0m[0m [1mnss>=3.51.1-1 and lib32-nss>=3.51.1-1 updates require manual intervention[0m
|
||||
[1m[35m2020-04-14[0m[0m [1mzn_poly 0.9.2-2 update requires manual intervention[0m
|
||||
|
@ -1,114 +0,0 @@
|
||||
[1m[35m2019-12-20[0m[0m [1mXorg cleanup requires manual intervention[0m
|
||||
In the process of Xorg cleanup the update requires manual
|
||||
intervention when you hit this message:
|
||||
|
||||
[36m:: installing xorgproto (2019.2-2) breaks dependency 'inputproto' required by lib32-libxi
|
||||
:: installing xorgproto (2019.2-2) breaks dependency 'dmxproto' required by libdmx
|
||||
:: installing xorgproto (2019.2-2) breaks dependency 'xf86dgaproto' required by libxxf86dga
|
||||
:: installing xorgproto (2019.2-2) breaks dependency 'xf86miscproto' required by libxxf86misc
|
||||
[0m
|
||||
when updating, use: [36mpacman -Rdd libdmx libxxf86dga libxxf86misc && pacman -Syu[0m to perform the upgrade.
|
||||
[0m
|
||||
[1m[35m2020-01-04[0m[0m [1mNow using Zstandard instead of xz for package compression[0m
|
||||
As announced on the mailing list, on Friday, Dec 27 2019, our package compression scheme has changed from xz (.pkg.tar.xz) to zstd (.pkg.tar.zst).
|
||||
|
||||
zstd and xz trade blows in their compression ratio. Recompressing all packages to zstd with our options yields a total ~0.8% increase in package size on all of our packages combined, but the decompression time for all packages saw a ~1300% speedup.
|
||||
|
||||
We already have more than 545 zstd-compressed packages in our repositories, and as packages get updated more will keep rolling in. We have not found any user-facing issues as of yet, so things appear to be working.
|
||||
|
||||
As a packager, you will automatically start building .pkg.tar.zst packages if you are using the latest version of devtools (>= 20191227).
|
||||
As an end-user no manual intervention is required, assuming that you have read and followed the news post from late last year.
|
||||
|
||||
If you nevertheless haven't updated libarchive since 2018, all hope is not lost! Binary builds of pacman-static are available from Eli Schwartz' personal repository (or direct link to binary), signed with their Trusted User keys, with which you can perform the update.
|
||||
[0m
|
||||
[1m[35m2020-01-15[0m[0m [1mrsync compatibility[0m
|
||||
Our [36mrsync[0m package was shipped with bundled [36mzlib[0m to provide compatibility
|
||||
with the old-style [36m--compress[0m option up to version 3.1.0. Version 3.1.1 was
|
||||
released on 2014-06-22 and is shipped by all major distributions now.
|
||||
|
||||
So we decided to finally drop the bundled library and ship a package with
|
||||
system [36mzlib[0m. This also fixes security issues, actual ones and in future. Go
|
||||
and blame those running old versions if you encounter errors with [36mrsync
|
||||
3.1.3-3[0m.
|
||||
[0m
|
||||
[1m[35m2020-02-17[0m[0m [1msshd needs restarting after upgrading to openssh-8.2p1[0m
|
||||
After upgrading to openssh-8.2p1, the existing SSH daemon will be unable to accept new connections. (See FS#65517.) When upgrading remote hosts, please make sure to restart the SSH daemon using [36msystemctl restart sshd[0m right after running [36mpacman -Syu[0m. If you are upgrading to openssh-8.2p1-3 or higher, this restart will happen automatically.
|
||||
[0m
|
||||
[1m[35m2020-02-22[0m[0m [1mPlanet Arch Linux migration[0m
|
||||
The software behind planet.archlinux.org was implemented in Python 2 and is no longer maintained upstream. This functionality has now been implemented in archlinux.org's archweb backend which is actively maintained but offers a slightly different experience.
|
||||
|
||||
The most notable changes are the offered feeds and the feed location. Archweb only offers an Atom feed which is located at here.
|
||||
[0m
|
||||
[1m[35m2020-02-24[0m[0m [1mThe Future of the Arch Linux Project Leader[0m
|
||||
Hello everyone,
|
||||
|
||||
Some of you may know me from the days when I was much more involved in Arch, but most of you probably just know me as a name on the website. I’ve been with Arch for some time, taking the leadership of this beast over from Judd back in 2007. But, as these things often go, my involvement has slid down to minimal levels over time. It’s high time that changes.
|
||||
|
||||
Arch Linux needs involved leadership to make hard decisions and direct the project where it needs to go. And I am not in a position to do this.
|
||||
|
||||
In a team effort, the Arch Linux staff devised a new process for determining future leaders. From now on, leaders will be elected by the staff for a term length of two years. Details of this new process can be found here
|
||||
|
||||
In the first official vote with Levente Polyak (anthraxx), Gaetan Bisson (vesath), Giancarlo Razzolini (grazzolini), and Sven-Hendrik Haase (svenstaro) as candidates, and through 58 verified votes, a winner was chosen:
|
||||
|
||||
Levente Polyak (anthraxx) will be taking over the reins of this ship. Congratulations!
|
||||
|
||||
Thanks for everything over all these years,
|
||||
Aaron Griffin (phrakture)
|
||||
[0m
|
||||
[1m[35m2020-03-01[0m[0m [1mfirewalld>=0.8.1-2 update requires manual intervention[0m
|
||||
The firewalld package prior to version 0.8.1-2 was missing the compiled python modules. This has been fixed in 0.8.1-2, so the upgrade will need to overwrite the untracked pyc files created. If you get errors like these
|
||||
|
||||
[36mfirewalld: /usr/lib/python3.8/site-packages/firewall/__pycache__/__init__.cpython-38.pyc exists in filesystem
|
||||
firewalld: /usr/lib/python3.8/site-packages/firewall/__pycache__/client.cpython-38.pyc exists in filesystem
|
||||
firewalld: /usr/lib/python3.8/site-packages/firewall/__pycache__/dbus_utils.cpython-38.pyc exists in filesystem
|
||||
...many more...
|
||||
[0m
|
||||
when updating, use
|
||||
|
||||
[36mpacman -Suy --overwrite /usr/lib/python3.8/site-packages/firewall/\*
|
||||
[0m
|
||||
to perform the upgrade.
|
||||
[0m
|
||||
[1m[35m2020-03-19[0m[0m [1mhplip 3.20.3-2 update requires manual intervention[0m
|
||||
The hplip package prior to version 3.20.3-2 was missing the compiled
|
||||
python modules. This has been fixed in 3.20.3-2, so the upgrade will
|
||||
need to overwrite the untracked pyc files that were created. If you get errors
|
||||
such as these
|
||||
|
||||
[36mhplip: /usr/share/hplip/base/__pycache__/__init__.cpython-38.pyc exists in filesystem
|
||||
hplip: /usr/share/hplip/base/__pycache__/avahi.cpython-38.pyc exists in filesystem
|
||||
hplip: /usr/share/hplip/base/__pycache__/codes.cpython-38.pyc exists in filesystem
|
||||
...many more...
|
||||
[0m
|
||||
when updating, use
|
||||
|
||||
[36mpacman -Suy --overwrite /usr/share/hplip/\*
|
||||
[0m
|
||||
to perform the upgrade.
|
||||
[0m
|
||||
[1m[35m2020-04-13[0m[0m [1mnss>=3.51.1-1 and lib32-nss>=3.51.1-1 updates require manual intervention[0m
|
||||
The nss and lib32-nss packages prior to version 3.51.1-1 were missing a soname link each. This has been fixed in 3.51.1-1, so the upgrade will need to overwrite the untracked files created by ldconfig. If you get any of these errors
|
||||
|
||||
[36mnss: /usr/lib/p11-kit-trust.so exists in filesystem
|
||||
lib32-nss: /usr/lib32/p11-kit-trust.so exists in filesystem
|
||||
[0m
|
||||
when updating, use
|
||||
|
||||
[36mpacman -Syu --overwrite /usr/lib\*/p11-kit-trust.so
|
||||
[0m
|
||||
to perform the upgrade.
|
||||
[0m
|
||||
[1m[35m2020-04-14[0m[0m [1mzn_poly 0.9.2-2 update requires manual intervention[0m
|
||||
The zn_poly package prior to version 0.9.2-2 was missing a soname link.
|
||||
This has been fixed in 0.9.2-2, so the upgrade will need to overwrite the
|
||||
untracked files created by ldconfig. If you get an error
|
||||
|
||||
[36mzn_poly: /usr/lib/libzn_poly-0.9.so exists in filesystem
|
||||
[0m
|
||||
when updating, use
|
||||
|
||||
[36mpacman -Syu --overwrite usr/lib/libzn_poly-0.9.so
|
||||
[0m
|
||||
to perform the upgrade.
|
||||
[0m
|
||||
|
@ -1,3 +0,0 @@
|
||||
[1m[35m2020-04-13[0m[0m [1mnss>=3.51.1-1 and lib32-nss>=3.51.1-1 updates require manual intervention[0m
|
||||
[1m[35m2020-04-14[0m[0m [1mzn_poly 0.9.2-2 update requires manual intervention[0m
|
||||
|
@ -1,3 +0,0 @@
|
||||
[1m[35m2020-04-14[0m[0m [1mzn_poly 0.9.2-2 update requires manual intervention[0m
|
||||
[1m[35m2020-04-13[0m[0m [1mnss>=3.51.1-1 and lib32-nss>=3.51.1-1 updates require manual intervention[0m
|
||||
|
@ -1,3 +0,0 @@
|
||||
[1m[35m2020-04-14[0m[0m [1mzn_poly 0.9.2-2 update requires manual intervention[0m
|
||||
The zn_poly package prior to version 0.9.2-2 was missing a soname link.[0m
|
||||
|
174
pkg/news/news.go
174
pkg/news/news.go
@ -1,174 +0,0 @@
|
||||
package news
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"html"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type item struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
PubDate string `xml:"pubDate"`
|
||||
Creator string `xml:"dc:creator"`
|
||||
}
|
||||
|
||||
func (item *item) printNews(logger *text.Logger, buildTime time.Time, all, quiet bool) {
|
||||
var fd string
|
||||
|
||||
date, err := time.Parse(time.RFC1123Z, item.PubDate)
|
||||
|
||||
if err != nil {
|
||||
logger.Errorln(err)
|
||||
} else {
|
||||
fd = text.FormatTime(int(date.Unix()))
|
||||
if !all && !buildTime.IsZero() {
|
||||
if buildTime.After(date) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.Println(text.Bold(text.Magenta(fd)), text.Bold(strings.TrimSpace(item.Title)))
|
||||
|
||||
if !quiet {
|
||||
desc := strings.TrimSpace(parseNews(item.Description))
|
||||
logger.Println(desc)
|
||||
}
|
||||
}
|
||||
|
||||
type channel struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Language string `xml:"language"`
|
||||
Lastbuilddate string `xml:"lastbuilddate"`
|
||||
Items []item `xml:"item"`
|
||||
}
|
||||
|
||||
type rss struct {
|
||||
Channel channel `xml:"channel"`
|
||||
}
|
||||
|
||||
func PrintNewsFeed(ctx context.Context, client *http.Client, logger *text.Logger,
|
||||
cutOffDate time.Time, bottomUp, all, quiet bool,
|
||||
) error {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://archlinux.org/feeds/news", http.NoBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rssGot := rss{}
|
||||
|
||||
d := xml.NewDecoder(bytes.NewReader(body))
|
||||
if err := d.Decode(&rssGot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if bottomUp {
|
||||
for i := len(rssGot.Channel.Items) - 1; i >= 0; i-- {
|
||||
rssGot.Channel.Items[i].printNews(logger, cutOffDate, all, quiet)
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < len(rssGot.Channel.Items); i++ {
|
||||
rssGot.Channel.Items[i].printNews(logger, cutOffDate, all, quiet)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Crude html parsing, good enough for the arch news
|
||||
// This is only displayed in the terminal so there should be no security
|
||||
// concerns.
|
||||
func parseNews(str string) string {
|
||||
var (
|
||||
buffer bytes.Buffer
|
||||
tagBuffer bytes.Buffer
|
||||
escapeBuffer bytes.Buffer
|
||||
inTag = false
|
||||
inEscape = false
|
||||
)
|
||||
|
||||
for _, char := range str {
|
||||
if inTag {
|
||||
if char == '>' {
|
||||
inTag = false
|
||||
|
||||
switch tagBuffer.String() {
|
||||
case "code":
|
||||
buffer.WriteString(text.CyanCode)
|
||||
case "/code":
|
||||
buffer.WriteString(text.ResetCode)
|
||||
case "/p":
|
||||
buffer.WriteRune('\n')
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
tagBuffer.WriteRune(char)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if inEscape {
|
||||
if char == ';' {
|
||||
inEscape = false
|
||||
|
||||
escapeBuffer.WriteRune(char)
|
||||
s := html.UnescapeString(escapeBuffer.String())
|
||||
buffer.WriteString(s)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
escapeBuffer.WriteRune(char)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if char == '<' {
|
||||
inTag = true
|
||||
|
||||
tagBuffer.Reset()
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if char == '&' {
|
||||
inEscape = true
|
||||
|
||||
escapeBuffer.Reset()
|
||||
escapeBuffer.WriteRune(char)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
buffer.WriteRune(char)
|
||||
}
|
||||
|
||||
buffer.WriteString(text.ResetCode)
|
||||
|
||||
return buffer.String()
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user