mirror of
https://github.com/Jguer/yay.git
synced 2025-06-24 00:02:29 -04:00
Compare commits
245 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6f3bc5cc4c | ||
|
c2caf9c7d7 | ||
|
8615239329 | ||
|
c9a8507654 | ||
|
75e90c3a6d | ||
|
8ab3652846 | ||
|
98be3fec97 | ||
|
c6a2226ce1 | ||
|
3e82496057 | ||
|
a26ac1ba95 | ||
|
b745f87210 | ||
|
b4a41700ee | ||
|
0aa80e521e | ||
|
bce9f2fc72 | ||
|
5a71db2526 | ||
|
535370bca0 | ||
|
9a3be07887 | ||
|
2f205ee96c | ||
|
1982ce0366 | ||
|
2dcf94544c | ||
|
95fc0938fd | ||
|
ff176c0dd2 | ||
|
bf315041b1 | ||
|
559bc06b31 | ||
|
35019f95b6 | ||
|
50cbf70bf4 | ||
|
0b5f5f0ccd | ||
|
a300330b94 | ||
|
670598912e | ||
|
257b230e39 | ||
|
d2c67ae0a4 | ||
|
4432c60246 | ||
|
33ba07fe0d | ||
|
d37e365ac3 | ||
|
6807ecc081 | ||
|
b07d8c1447 | ||
|
3da808847f | ||
|
590a3d3a8c | ||
|
69685d0fb5 | ||
|
5572d1817e | ||
|
2f403a4f28 | ||
|
9322197d0c | ||
|
46f3842e6f | ||
|
76000ae987 | ||
|
e27979d21d | ||
|
c0baacd633 | ||
|
43567b5d85 | ||
|
e18cc87307 | ||
|
81a2a19101 | ||
|
669d7af6d1 | ||
|
65ce4b9f6f | ||
|
5f2b94ce7c | ||
|
3f2f6eae31 | ||
|
da53d3855f | ||
|
f23fe98a66 | ||
|
ec837c831d | ||
|
f100c1d54b | ||
|
3f5d26c4f9 | ||
|
3003f1667c | ||
|
fb168fb176 | ||
|
842067256b | ||
|
a6a6dc0acb | ||
|
2e06552211 | ||
|
138c2dd6cd | ||
|
4872b8b829 | ||
|
1b6ad7b305 | ||
|
d6e961af70 | ||
|
89b32ee9ce | ||
|
f68a57129f | ||
|
bea53a4a09 | ||
|
13df7e79eb | ||
|
0f496c9af9 | ||
|
84d8f1b7b3 | ||
|
3a118b7690 | ||
|
a32f5e7e2c | ||
|
3c881d577f | ||
|
86f5c08ec4 | ||
|
675f0ba3f3 | ||
|
d7d67e3fd3 | ||
|
c28be1d8b0 | ||
|
1b8f823f7c | ||
|
836fc5922a | ||
|
0165486bf4 | ||
|
5149e3714d | ||
|
9ed9b0b4e1 | ||
|
e19700234f | ||
|
965f8956e9 | ||
|
53c9d0ef34 | ||
|
9b41f136d6 | ||
|
d956dd7888 | ||
|
61dd708a4a | ||
|
ff3ad18fa8 | ||
|
803f708106 | ||
|
9b6d40d7f9 | ||
|
779a9f16bd | ||
|
02d3e2e1c0 | ||
|
8de397ed11 | ||
|
de7ad4070f | ||
|
3b18e2197c | ||
|
127b3a5b1a | ||
|
2ff794da32 | ||
|
6c2330528f | ||
|
a1d530cbf4 | ||
|
5d887cbd41 | ||
|
05b76852bd | ||
|
9524cbbaed | ||
|
48d1d3d2d5 | ||
|
741d83c1f0 | ||
|
9c02af429a | ||
|
03e89d660f | ||
|
f7f2169992 | ||
|
e8080f87c2 | ||
|
26aa171b2b | ||
|
92d7cb0faa | ||
|
f3a4fc8987 | ||
|
aa6cad75a3 | ||
|
2078bc936f | ||
|
d778be4f9f | ||
|
aeafe23027 | ||
|
6c31477ccd | ||
|
0a930c9ffc | ||
|
d411524481 | ||
|
15ef062bb5 | ||
|
c2d7d99e43 | ||
|
86207fce64 | ||
|
dc68b1a8fa | ||
|
d02c45e5b6 | ||
|
8d773aa6a3 | ||
|
b81d34d5cc | ||
|
d77dd77141 | ||
|
e34bce003d | ||
|
d23e8925fa | ||
|
643830fccd | ||
|
cb4cd7b451 | ||
|
350ff1c70a | ||
|
26dc74ed67 | ||
|
a00ff6b3cc | ||
|
9e665a98b9 | ||
|
4169f0ee42 | ||
|
5a6b18fe23 | ||
|
c8577bb613 | ||
|
965f41b938 | ||
|
0771ded99b | ||
|
8f98ab3d4b | ||
|
d368f99be0 | ||
|
a1121556be | ||
|
299aa1e123 | ||
|
04c76a404e | ||
|
e60ccdf8b7 | ||
|
b6c72ce7a2 | ||
|
87d1fd1c06 | ||
|
92d50910de | ||
|
a0e6838a5f | ||
|
8916cd174b | ||
|
7483393377 | ||
|
9aefb8440e | ||
|
6c1998f6eb | ||
|
688434b242 | ||
|
5995e55ddb | ||
|
04c82b8112 | ||
|
abd398a787 | ||
|
23b053bccf | ||
|
dadc8c0d98 | ||
|
6dd7933fbe | ||
|
d9029face3 | ||
|
64f5c2b0a9 | ||
|
93afb03738 | ||
|
0dcf911e99 | ||
|
2be57cb312 | ||
|
f070cff9f9 | ||
|
c46f5d31cc | ||
|
74c1cdb254 | ||
|
79b03fdac1 | ||
|
5a3c3ae4d0 | ||
|
710ff0097a | ||
|
ddeaf47a53 | ||
|
4f7b3edefe | ||
|
5b8cc98afa | ||
|
e25d00015a | ||
|
c5a18e5000 | ||
|
adde043514 | ||
|
7dc4fae155 | ||
|
599a5a9073 | ||
|
12282fb28a | ||
|
0607090719 | ||
|
1568e64d55 | ||
|
d08f217b3a | ||
|
29f47a4413 | ||
|
35ee42d343 | ||
|
1335e9b4e0 | ||
|
e28319fece | ||
|
c1aa71bee1 | ||
|
56d1b7ed1c | ||
|
036a53882d | ||
|
330b9ab920 | ||
|
98d5352b78 | ||
|
27f336e68c | ||
|
23937356eb | ||
|
9641d2a608 | ||
|
df3dbfa125 | ||
|
fdcf6ef664 | ||
|
39f0d4e9a1 | ||
|
d33bf8841d | ||
|
bd79057fd9 | ||
|
a0a5e45fe7 | ||
|
ec15a5b363 | ||
|
d568a73ab8 | ||
|
490ebe4f7f | ||
|
4dfee1f82f | ||
|
5cf215a00a | ||
|
f7731d7cf9 | ||
|
966bfb74ee | ||
|
c721fe7f3b | ||
|
b51c10ca3e | ||
|
4832ec59db | ||
|
49267b9cd9 | ||
|
e6344100e6 | ||
|
15400c5fc5 | ||
|
822b11b4d6 | ||
|
71432a447e | ||
|
957292a911 | ||
|
8c69356bd4 | ||
|
64bb346fbe | ||
|
797b7485ab | ||
|
57a3a090f1 | ||
|
f0bfe63ced | ||
|
83214fbc1c | ||
|
161fede450 | ||
|
26c9ab5a87 | ||
|
4a9c736e2a | ||
|
76e5ee1fa6 | ||
|
88008e4eb3 | ||
|
c7a51a1614 | ||
|
6a971df635 | ||
|
511b95769e | ||
|
4e9a865388 | ||
|
9270f00c7e | ||
|
527c3a5058 | ||
|
1ee94f28d3 | ||
|
a64180464b | ||
|
a31ca0d7dc | ||
|
1bc3171abd | ||
|
2d7297ae6d | ||
|
ce0cb35510 | ||
|
d9b57790fa |
26
.devcontainer/Dockerfile
Normal file
26
.devcontainer/Dockerfile
Normal file
@ -0,0 +1,26 @@
|
||||
# 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"]
|
14
.devcontainer/devcontainer.json
Normal file
14
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "Existing Dockerfile",
|
||||
"build": {
|
||||
"context": "..",
|
||||
"dockerfile": "../.devcontainer/Dockerfile"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"golang.go"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
15
.github/dependabot.yml
vendored
Normal file
15
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# 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:
|
||||
- '*'
|
157
.github/workflows/builder-image.yml
vendored
157
.github/workflows/builder-image.yml
vendored
@ -1,40 +1,143 @@
|
||||
name: Builder image
|
||||
name: Builder Image
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 3 * * 1"
|
||||
- cron: "0 3 * * 1" # Every Monday at 3 AM
|
||||
push:
|
||||
paths:
|
||||
- "ci.Dockerfile"
|
||||
- "**/builder-image.yml"
|
||||
- ".github/workflows/builder-image.yml"
|
||||
|
||||
env:
|
||||
REGISTRY_IMAGE: jguer/yay-builder
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Push builder image to Docker Hub
|
||||
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: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- 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@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
- name: Push to Docker Hub
|
||||
uses: docker/build-push-action@v2
|
||||
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_BUILDKIT: 0
|
||||
COMPOSE_DOCKER_CLI_BUILD: 0
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm/v7,linux/arm64
|
||||
file: ci.Dockerfile
|
||||
push: true
|
||||
tags: jguer/yay-builder:latest
|
||||
secrets: |
|
||||
DOCKER_BUILDKIT=0
|
||||
COMPOSE_DOCKER_CLI_BUILD=0
|
||||
cache-from: type=registry,ref=jguer/yay-builder:latest
|
||||
cache-to: type=inline
|
||||
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
|
106
.github/workflows/multiarch-build.yml
vendored
106
.github/workflows/multiarch-build.yml
vendored
@ -1,4 +1,5 @@
|
||||
name: Build Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
@ -8,31 +9,36 @@ jobs:
|
||||
build-releases:
|
||||
strategy:
|
||||
matrix:
|
||||
arch:
|
||||
["linux/amd64 x86_64", "linux/arm/v7 armv7h", "linux/arm64 aarch64"]
|
||||
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@v2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
with:
|
||||
platforms: all
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
version: latest
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Read info
|
||||
id: tags
|
||||
shell: bash
|
||||
run: |
|
||||
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
|
||||
echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
|
||||
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
arch="${{ matrix.arch }}"
|
||||
echo ::set-output name=PLATFORM::${arch%% *}
|
||||
echo ::set-output name=ARCH::${arch##* }
|
||||
echo "PLATFORM=${arch%% *}" >> $GITHUB_OUTPUT
|
||||
echo "ARCH=${arch##* }" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build ${{ matrix.arch }} release
|
||||
run: |
|
||||
mkdir artifacts
|
||||
@ -43,75 +49,45 @@ jobs:
|
||||
-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@v2
|
||||
|
||||
- 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@v2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Read info
|
||||
id: tags
|
||||
shell: bash
|
||||
run: |
|
||||
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
|
||||
echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
|
||||
- uses: actions/download-artifact@v2
|
||||
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: yay_x86_64
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: yay_armv7h
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: yay_aarch64
|
||||
pattern: yay_*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.tags.outputs.tag }}
|
||||
release_name: ${{ steps.tags.outputs.tag }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
- name: Upload x86_64 asset
|
||||
id: upload-release-asset-x86_64
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./yay_${{ steps.tags.outputs.version }}_x86_64.tar.gz
|
||||
asset_name: yay_${{ steps.tags.outputs.version }}_x86_64.tar.gz
|
||||
asset_content_type: application/tar+gzip
|
||||
- name: Upload armv7h asset
|
||||
id: upload-release-asset-armv7h
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./yay_${{ steps.tags.outputs.version }}_armv7h.tar.gz
|
||||
asset_name: yay_${{ steps.tags.outputs.version }}_armv7h.tar.gz
|
||||
asset_content_type: application/tar+gzip
|
||||
- name: Upload aarch64 asset
|
||||
id: upload-release-asset-aarch64
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./yay_${{ steps.tags.outputs.version }}_aarch64.tar.gz
|
||||
asset_name: yay_${{ steps.tags.outputs.version }}_aarch64.tar.gz
|
||||
asset_content_type: application/tar+gzip
|
||||
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 }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
7
.github/workflows/testing-git.yml
vendored
7
.github/workflows/testing-git.yml
vendored
@ -12,9 +12,9 @@ jobs:
|
||||
name: Lint and test yay (-git)
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: jguer/yay-builder:latest
|
||||
image: ghcr.io/jguer/yay-builder:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
@ -35,4 +35,5 @@ jobs:
|
||||
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
|
||||
run: |
|
||||
make test
|
||||
|
28
.github/workflows/testing.yml
vendored
28
.github/workflows/testing.yml
vendored
@ -7,9 +7,9 @@ jobs:
|
||||
name: Lint and test yay
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: jguer/yay-builder:latest
|
||||
image: ghcr.io/jguer/yay-builder:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
@ -17,6 +17,28 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
- name: Lint
|
||||
run: /app/bin/golangci-lint run ./...
|
||||
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
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -28,3 +28,7 @@ qemu-*
|
||||
*.pot
|
||||
*.po~
|
||||
*.pprof
|
||||
|
||||
node_modules/
|
||||
xgotext
|
||||
.devcontainer/
|
154
.golangci.yml
154
.golangci.yml
@ -1,70 +1,18 @@
|
||||
linters-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
|
||||
goimports:
|
||||
local-prefixes: github.com/Jguer/yay/v12
|
||||
gomnd:
|
||||
checks:
|
||||
- argument
|
||||
- case
|
||||
- condition
|
||||
- return
|
||||
ignored-numbers:
|
||||
- "0"
|
||||
- "1"
|
||||
- "2"
|
||||
- "3"
|
||||
ignored-functions:
|
||||
- strings.SplitN
|
||||
govet:
|
||||
check-shadowing: true
|
||||
lll:
|
||||
line-length: 140
|
||||
misspell:
|
||||
locale: US
|
||||
nolintlint:
|
||||
allow-unused: false # report any unused nolint directives
|
||||
require-explanation: false # don't require an explanation for nolint directives
|
||||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
||||
|
||||
version: "2"
|
||||
run:
|
||||
go: "1.20"
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
disable-all: true
|
||||
default: none
|
||||
enable:
|
||||
- bodyclose
|
||||
- depguard
|
||||
- dogsled
|
||||
- dupl
|
||||
- errorlint
|
||||
- errcheck
|
||||
- exportloopref
|
||||
# - funlen # TOFIX
|
||||
- errorlint
|
||||
- gochecknoinits
|
||||
# - goconst # TOFIX
|
||||
- gocritic
|
||||
# - gocyclo # TOFIX
|
||||
- gofmt
|
||||
- goimports
|
||||
# - gomnd # TOFIX
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- lll
|
||||
@ -73,32 +21,74 @@ linters:
|
||||
- noctx
|
||||
- nolintlint
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- whitespace
|
||||
|
||||
run:
|
||||
go: "1.18"
|
||||
timeout: "10m"
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: (.+)_test.go
|
||||
linters:
|
||||
- lll
|
||||
- revive
|
||||
- wsl
|
||||
- govet
|
||||
- godot
|
||||
- errcheck
|
||||
- stylecheck
|
||||
- dupl
|
||||
- gocritic
|
||||
- gochecknoinits
|
||||
- errorlint
|
||||
|
||||
exclude:
|
||||
- G204
|
||||
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$
|
||||
|
@ -5,19 +5,17 @@ repos:
|
||||
rev: v0.5.1
|
||||
hooks:
|
||||
- id: go-fmt
|
||||
- id: go-imports
|
||||
args: [-local=github.com/Jguer/yay/v12/]
|
||||
- id: golangci-lint
|
||||
- id: go-unit-tests
|
||||
- id: go-build
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
rev: v3.0.0-alpha.4 # Use the sha or tag you want to point at
|
||||
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.4.0 # Use the ref you want to point at
|
||||
rev: v4.5.0 # Use the ref you want to point at
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: check-json
|
||||
@ -25,7 +23,7 @@ repos:
|
||||
- id: check-added-large-files
|
||||
|
||||
- repo: https://github.com/commitizen-tools/commitizen
|
||||
rev: v2.38.0
|
||||
rev: v3.15.0
|
||||
hooks:
|
||||
- id: commitizen
|
||||
stages: [commit-msg]
|
||||
|
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"go.lintTool": "golangci-lint",
|
||||
"gopls": {
|
||||
"formatting.gofumpt": true,
|
||||
"formatting.local": "github.com/Jguer/yay/v12"
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
FROM docker.io/jguer/yay-builder:latest
|
||||
LABEL maintainer="Jguer,joaogg3 at google mail"
|
||||
FROM ghcr.io/jguer/yay-builder:latest
|
||||
LABEL maintainer="Jguer,docker@jguer.space"
|
||||
|
||||
ARG VERSION
|
||||
ARG PREFIX
|
||||
@ -9,4 +9,4 @@ WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN make release VERSION=${VERSION} PREFIX=${PREFIX} ARCH=${ARCH}
|
||||
RUN make release VERSION=${VERSION} PREFIX=${PREFIX} ARCH=${ARCH}
|
16
Makefile
16
Makefile
@ -26,8 +26,7 @@ MOFILES := $(POFILES:.po=.mo)
|
||||
|
||||
FLAGS ?= -trimpath -mod=readonly -modcacherw
|
||||
EXTRA_FLAGS ?= -buildmode=pie
|
||||
LDFLAGS := -X "main.yayVersion=${VERSION}" -X "main.localePath=${SYSTEMLOCALEPATH}" -linkmode=external
|
||||
FLAGS += $(shell pacman -T 'pacman-git' >/dev/null 2>&1 && echo "-tags next")
|
||||
LDFLAGS := -X "main.yayVersion=${VERSION}" -X "main.localePath=${SYSTEMLOCALEPATH}" -linkmode=external -compressdwarf=false
|
||||
|
||||
RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
|
||||
PACKAGE := $(RELEASE_DIR).tar.gz
|
||||
@ -53,6 +52,10 @@ test_lint: test lint
|
||||
test:
|
||||
$(GO) test -race -covermode=atomic $(FLAGS) ./...
|
||||
|
||||
.PHONY: test-integration
|
||||
test-integration:
|
||||
$(GO) test -tags=integration $(FLAGS) ./...
|
||||
|
||||
.PHONY: build
|
||||
build: $(BIN)
|
||||
|
||||
@ -66,7 +69,7 @@ docker-release-all:
|
||||
make docker-release-aarch64 ARCH=aarch64
|
||||
|
||||
docker-release:
|
||||
docker create --name yay-$(ARCH) yay:${ARCH}
|
||||
docker create --name yay-$(ARCH) yay:${ARCH} /bin/sh
|
||||
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
|
||||
docker container rm yay-$(ARCH)
|
||||
|
||||
@ -79,9 +82,7 @@ docker-build:
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
$(GO) vet $(FLAGS) ./...
|
||||
@test -z "$$(gofmt -l $(SOURCES))" || (echo "Files need to be linted. Use make fmt" && false)
|
||||
golangci-lint run ./...
|
||||
GOFLAGS="$(FLAGS)" golangci-lint run ./...
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
@ -122,8 +123,9 @@ $(PACKAGE): $(BIN) $(RELEASE_DIR) ${MOFILES}
|
||||
|
||||
locale:
|
||||
xgotext -in . -out po
|
||||
mv po/default.pot po/en.po
|
||||
for lang in ${LANGS}; do \
|
||||
test -f po/$$lang.po || msginit -l po/$$lang.po -i po/${POTFILE} -o po/$$lang.po \
|
||||
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
|
||||
|
65
README.md
65
README.md
@ -30,15 +30,18 @@ Yet Another Yogurt - An AUR Helper Written in Go
|
||||
|
||||
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
|
||||
building with makepkg:
|
||||
|
||||
Before you begin, make sure you have the `base-devel` package group installed.
|
||||
We make sure we have the `base-devel` package group installed.
|
||||
|
||||
```sh
|
||||
pacman -S --needed git base-devel
|
||||
sudo pacman -S --needed git base-devel
|
||||
git clone https://aur.archlinux.org/yay.git
|
||||
cd yay
|
||||
makepkg -si
|
||||
@ -47,7 +50,7 @@ makepkg -si
|
||||
If you want to do all of this at once, we can chain the commands like so:
|
||||
|
||||
```sh
|
||||
pacman -S --needed git base-devel && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si
|
||||
sudo pacman -S --needed git base-devel && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si
|
||||
```
|
||||
|
||||
### Binary
|
||||
@ -56,12 +59,18 @@ If you do not want to compile yay yourself you can use the builds generated by
|
||||
GitHub Actions.
|
||||
|
||||
```sh
|
||||
pacman -S --needed git base-devel
|
||||
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)
|
||||
@ -70,8 +79,8 @@ you can simply install yay using pacman (as root):
|
||||
```sh
|
||||
pacman -S --needed git base-devel yay
|
||||
```
|
||||
|
||||
⚠️ distributions sometimes lag updating yay on their repositories.
|
||||
> [!WARNING]
|
||||
> distributions sometimes lag updating yay on their repositories.
|
||||
|
||||
## First Use
|
||||
|
||||
@ -111,17 +120,6 @@ pacman -S --needed git base-devel yay
|
||||
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
|
||||
@ -130,14 +128,14 @@ pacman -S --needed git base-devel yay
|
||||
|
||||
- **Yay is not asking me to edit PKGBUILDS, and I don't like the diff menu! What can I do?**
|
||||
|
||||
`yay --editmenu --nodiffmenu --save`
|
||||
`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`
|
||||
|
||||
- **An `Out Of Date AUR Packages` message is displayed. Why doesn't Yay update them?**
|
||||
- **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
|
||||
@ -152,28 +150,13 @@ pacman -S --needed git base-devel yay
|
||||
|
||||
- **I know my `-git` package has updates but yay doesn't offer to update it**
|
||||
|
||||
Yay uses an hash cache for development packages. Normally it is updated at the end of the package install with the message `Found git repo`.
|
||||
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.
|
||||
|
||||
- **What settings do you use?**
|
||||
|
||||
```sh
|
||||
yay -Y --devel --combinedupgrade --batchinstall --save
|
||||
```
|
||||
|
||||
Pacman conf options:
|
||||
|
||||
```conf
|
||||
UseSyslog
|
||||
Color
|
||||
CheckSpace
|
||||
VerbosePkgLists
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
All support related to Yay should be requested via GitHub issues. Since Yay is not
|
||||
@ -189,14 +172,14 @@ tools.
|
||||
|
||||
## Images
|
||||
|
||||
<p float="left">
|
||||
<img src="https://rawcdn.githack.com/Jguer/jguer.github.io/77647f396cb7156fd32e30970dbeaf6d6dc7f983/yay/yay.png" width="42%"/>
|
||||
<img src="https://rawcdn.githack.com/Jguer/jguer.github.io/77647f396cb7156fd32e30970dbeaf6d6dc7f983/yay/yay-s.png" width="42%"/>
|
||||
<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 float="left">
|
||||
<img src="https://rawcdn.githack.com/Jguer/jguer.github.io/77647f396cb7156fd32e30970dbeaf6d6dc7f983/yay/yay-y.png" width="42%"/>
|
||||
<img src="https://rawcdn.githack.com/Jguer/jguer.github.io/77647f396cb7156fd32e30970dbeaf6d6dc7f983/yay/yay-ps.png" width="42%"/>
|
||||
<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
|
||||
|
13
SECURITY.md
Normal file
13
SECURITY.md
Normal file
@ -0,0 +1,13 @@
|
||||
# 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.
|
@ -1,12 +1,15 @@
|
||||
FROM docker.io/jguer/yay-builder:latest
|
||||
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 doxygen meson asciidoc go git gcc make sudo base-devel && \
|
||||
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 v1.52.2 && \
|
||||
go mod download
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.1.5 && \
|
||||
go mod download
|
||||
|
106
clean.go
106
clean.go
@ -2,19 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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/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/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
// CleanDependencies removes all dangling dependencies in system.
|
||||
@ -49,28 +48,29 @@ func cleanRemove(ctx context.Context, cfg *settings.Configuration,
|
||||
arguments, cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
func syncClean(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
func syncClean(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
keepInstalled := false
|
||||
keepCurrent := false
|
||||
|
||||
_, removeAll, _ := cmdArgs.GetArg("c", "clean")
|
||||
|
||||
for _, v := range cfg.Runtime.PacmanConf.CleanMethod {
|
||||
if v == "KeepInstalled" {
|
||||
for _, v := range run.PacmanConf.CleanMethod {
|
||||
switch v {
|
||||
case "KeepInstalled":
|
||||
keepInstalled = true
|
||||
} else if v == "KeepCurrent" {
|
||||
case "KeepCurrent":
|
||||
keepCurrent = true
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Mode.AtLeastRepo() {
|
||||
if err := cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm)); err != nil {
|
||||
if run.Cfg.Mode.AtLeastRepo() {
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !cfg.Mode.AtLeastAUR() {
|
||||
if !run.Cfg.Mode.AtLeastAUR() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -81,10 +81,10 @@ func syncClean(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser
|
||||
question = gotext.Get("Do you want to remove all other AUR packages from cache?")
|
||||
}
|
||||
|
||||
fmt.Println(gotext.Get("\nBuild directory:"), cfg.BuildDir)
|
||||
run.Logger.Println(gotext.Get("\nBuild directory:"), run.Cfg.BuildDir)
|
||||
|
||||
if text.ContinueTask(os.Stdin, question, true, settings.NoConfirm) {
|
||||
if err := cleanAUR(ctx, cfg, keepInstalled, keepCurrent, removeAll, dbExecutor); err != nil {
|
||||
if run.Logger.ContinueTask(question, true, settings.NoConfirm) {
|
||||
if err := cleanAUR(ctx, run, keepInstalled, keepCurrent, removeAll, dbExecutor); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -93,24 +93,24 @@ func syncClean(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser
|
||||
return nil
|
||||
}
|
||||
|
||||
if text.ContinueTask(os.Stdin, gotext.Get("Do you want to remove ALL untracked AUR files?"), true, settings.NoConfirm) {
|
||||
return cleanUntracked(ctx, cfg)
|
||||
if run.Logger.ContinueTask(gotext.Get("Do you want to remove ALL untracked AUR files?"), true, settings.NoConfirm) {
|
||||
return cleanUntracked(ctx, run)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanAUR(ctx context.Context, config *settings.Configuration,
|
||||
func cleanAUR(ctx context.Context, run *runtime.Runtime,
|
||||
keepInstalled, keepCurrent, removeAll bool, dbExecutor db.Executor,
|
||||
) error {
|
||||
fmt.Println(gotext.Get("removing AUR packages from cache..."))
|
||||
run.Logger.Println(gotext.Get("removing AUR packages from cache..."))
|
||||
|
||||
installedBases := make(stringset.StringSet)
|
||||
inAURBases := make(stringset.StringSet)
|
||||
installedBases := mapset.NewThreadUnsafeSet[string]()
|
||||
inAURBases := mapset.NewThreadUnsafeSet[string]()
|
||||
|
||||
remotePackages := dbExecutor.InstalledRemotePackages()
|
||||
|
||||
files, err := os.ReadDir(config.BuildDir)
|
||||
files, err := os.ReadDir(run.Cfg.BuildDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -130,21 +130,23 @@ func cleanAUR(ctx context.Context, config *settings.Configuration,
|
||||
// Querying the AUR is slow and needs internet so don't do it if we
|
||||
// don't need to.
|
||||
if keepCurrent {
|
||||
info, errInfo := query.AURInfo(ctx, config.Runtime.AURClient, cachedPackages, &query.AURWarnings{}, config.RequestSplitN)
|
||||
info, errInfo := run.AURClient.Get(ctx, &aur.Query{
|
||||
Needles: cachedPackages,
|
||||
})
|
||||
if errInfo != nil {
|
||||
return errInfo
|
||||
}
|
||||
|
||||
for i := range info {
|
||||
inAURBases.Set(info[i].PackageBase)
|
||||
inAURBases.Add(info[i].PackageBase)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range remotePackages {
|
||||
if pkg.Base() != "" {
|
||||
installedBases.Set(pkg.Base())
|
||||
installedBases.Add(pkg.Base())
|
||||
} else {
|
||||
installedBases.Set(pkg.Name())
|
||||
installedBases.Add(pkg.Name())
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,29 +156,29 @@ func cleanAUR(ctx context.Context, config *settings.Configuration,
|
||||
}
|
||||
|
||||
if !removeAll {
|
||||
if keepInstalled && installedBases.Get(file.Name()) {
|
||||
if keepInstalled && installedBases.Contains(file.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if keepCurrent && inAURBases.Get(file.Name()) {
|
||||
if keepCurrent && inAURBases.Contains(file.Name()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
dir := filepath.Join(config.BuildDir, file.Name())
|
||||
err = os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
text.Warnln(gotext.Get("Unable to remove %s: %s", dir, err))
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanUntracked(ctx context.Context, cfg *settings.Configuration) error {
|
||||
fmt.Println(gotext.Get("removing untracked AUR files from cache..."))
|
||||
func cleanUntracked(ctx context.Context, run *runtime.Runtime) error {
|
||||
run.Logger.Println(gotext.Get("removing untracked AUR files from cache..."))
|
||||
|
||||
files, err := os.ReadDir(cfg.BuildDir)
|
||||
files, err := os.ReadDir(run.Cfg.BuildDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -186,11 +188,11 @@ func cleanUntracked(ctx context.Context, cfg *settings.Configuration) error {
|
||||
continue
|
||||
}
|
||||
|
||||
dir := filepath.Join(cfg.BuildDir, file.Name())
|
||||
dir := filepath.Join(run.Cfg.BuildDir, file.Name())
|
||||
run.Logger.Debugln("cleaning", dir)
|
||||
if isGitRepository(dir) {
|
||||
if err := cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildGitCmd(ctx, dir, "clean", "-fx")); err != nil {
|
||||
text.Warnln(gotext.Get("Unable to clean:"), dir)
|
||||
|
||||
if err := run.CmdBuilder.Show(run.CmdBuilder.BuildGitCmd(ctx, dir, "clean", "-fx")); err != nil {
|
||||
run.Logger.Warnln(gotext.Get("Unable to clean:"), dir)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -203,29 +205,3 @@ func isGitRepository(dir string) bool {
|
||||
_, err := os.Stat(filepath.Join(dir, ".git"))
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
func cleanAfter(ctx context.Context, config *settings.Configuration,
|
||||
cmdBuilder exe.ICmdBuilder, pkgbuildDirs map[string]string,
|
||||
) {
|
||||
fmt.Println(gotext.Get("removing untracked AUR files from cache..."))
|
||||
|
||||
i := 0
|
||||
for _, dir := range pkgbuildDirs {
|
||||
text.OperationInfoln(gotext.Get("Cleaning (%d/%d): %s", i+1, len(pkgbuildDirs), text.Cyan(dir)))
|
||||
|
||||
_, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(
|
||||
ctx, dir, "reset", "--hard", "HEAD"))
|
||||
if err != nil {
|
||||
text.Errorln(gotext.Get("error resetting %s: %s", dir, stderr))
|
||||
}
|
||||
|
||||
if err := config.Runtime.CmdBuilder.Show(
|
||||
config.Runtime.CmdBuilder.BuildGitCmd(
|
||||
ctx, dir, "clean", "-fx", "--exclude", "*.pkg.*")); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -12,6 +15,7 @@ import (
|
||||
"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"
|
||||
@ -87,15 +91,13 @@ func TestCleanHanging(t *testing.T) {
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
cfg := &settings.Configuration{
|
||||
Runtime: &settings.Runtime{CmdBuilder: cmdBuilder},
|
||||
}
|
||||
|
||||
run := &runtime.Runtime{CmdBuilder: cmdBuilder, Cfg: &settings.Configuration{}}
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddArg(tc.args...)
|
||||
|
||||
err := handleCmd(context.Background(),
|
||||
cfg, cmdArgs, dbExc,
|
||||
run, cmdArgs, dbExc,
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
215
cmd.go
215
cmd.go
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
@ -18,6 +17,7 @@ import (
|
||||
"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"
|
||||
@ -26,8 +26,8 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Println(`Usage:
|
||||
func usage(logger *text.Logger) {
|
||||
logger.Println(`Usage:
|
||||
yay
|
||||
yay <operation> [...]
|
||||
yay <package(s)>
|
||||
@ -51,10 +51,10 @@ New operations:
|
||||
yay {-Y --yay} [options] [package(s)]
|
||||
|
||||
If no operation is specified 'yay -Syu' will be performed
|
||||
If no operation and no targets are provided -Y will be assumed
|
||||
If no operation is specified and targets are provided -Y will be assumed
|
||||
|
||||
New options:
|
||||
--repo Assume targets are from the repositories
|
||||
-N --repo Assume targets are from the repositories
|
||||
-a --aur Assume targets are from the AUR
|
||||
|
||||
Permanent configuration options:
|
||||
@ -92,24 +92,19 @@ 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
|
||||
--nocleanafter Do not remove package sources after successful build
|
||||
--keepsrc Keep pkg/ and src/ after building packages
|
||||
--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
|
||||
--rebuild Always build target packages
|
||||
--rebuildall Always build all AUR packages
|
||||
--norebuild Skip package build if in cache and up to date
|
||||
@ -118,19 +113,14 @@ Permanent configuration options:
|
||||
--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
|
||||
--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
|
||||
|
||||
--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
|
||||
@ -140,7 +130,7 @@ show specific options:
|
||||
-w --news Print arch news
|
||||
|
||||
yay specific options:
|
||||
-c --clean Remove unneeded dependencies
|
||||
-c --clean Remove unneeded dependencies (-cc to ignore optdepends)
|
||||
--gendb Generates development package DB used for updating
|
||||
|
||||
getpkgbuild specific options:
|
||||
@ -148,50 +138,49 @@ getpkgbuild specific options:
|
||||
-p --print Print pkgbuild of packages`)
|
||||
}
|
||||
|
||||
func handleCmd(ctx context.Context, cfg *settings.Configuration,
|
||||
func handleCmd(ctx context.Context, run *runtime.Runtime,
|
||||
cmdArgs *parser.Arguments, dbExecutor db.Executor,
|
||||
) error {
|
||||
if cmdArgs.ExistsArg("h", "help") {
|
||||
return handleHelp(ctx, cfg, cmdArgs)
|
||||
return handleHelp(ctx, run, cmdArgs)
|
||||
}
|
||||
|
||||
if cfg.SudoLoop && cmdArgs.NeedRoot(cfg.Mode) {
|
||||
cfg.Runtime.CmdBuilder.SudoLoop()
|
||||
if run.Cfg.SudoLoop && cmdArgs.NeedRoot(run.Cfg.Mode) {
|
||||
run.CmdBuilder.SudoLoop()
|
||||
}
|
||||
|
||||
switch cmdArgs.Op {
|
||||
case "V", "version":
|
||||
handleVersion()
|
||||
|
||||
handleVersion(run.Logger)
|
||||
return nil
|
||||
case "D", "database":
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case "F", "files":
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case "Q", "query":
|
||||
return handleQuery(ctx, cfg, cmdArgs, dbExecutor)
|
||||
return handleQuery(ctx, run, cmdArgs, dbExecutor)
|
||||
case "R", "remove":
|
||||
return handleRemove(ctx, cfg, cmdArgs, cfg.Runtime.VCSStore)
|
||||
return handleRemove(ctx, run, cmdArgs, run.VCSStore)
|
||||
case "S", "sync":
|
||||
return handleSync(ctx, cfg, cmdArgs, dbExecutor)
|
||||
return handleSync(ctx, run, cmdArgs, dbExecutor)
|
||||
case "T", "deptest":
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case "U", "upgrade":
|
||||
return handleUpgrade(ctx, cfg, cmdArgs)
|
||||
return handleUpgrade(ctx, run, cmdArgs)
|
||||
case "B", "build":
|
||||
return handleBuild(ctx, cfg, dbExecutor, cmdArgs)
|
||||
return handleBuild(ctx, run, dbExecutor, cmdArgs)
|
||||
case "G", "getpkgbuild":
|
||||
return handleGetpkgbuild(ctx, cfg, cmdArgs, dbExecutor)
|
||||
return handleGetpkgbuild(ctx, run, cmdArgs, dbExecutor)
|
||||
case "P", "show":
|
||||
return handlePrint(ctx, cfg, cmdArgs, dbExecutor)
|
||||
return handlePrint(ctx, run, cmdArgs, dbExecutor)
|
||||
case "Y", "yay":
|
||||
return handleYay(ctx, cfg, cmdArgs, cfg.Runtime.CmdBuilder,
|
||||
dbExecutor, cfg.Runtime.QueryBuilder)
|
||||
return handleYay(ctx, run, cmdArgs, run.CmdBuilder,
|
||||
dbExecutor, run.QueryBuilder)
|
||||
case "W", "web":
|
||||
return handleWeb(ctx, cfg, cmdArgs)
|
||||
return handleWeb(ctx, run, cmdArgs)
|
||||
}
|
||||
|
||||
return errors.New(gotext.Get("unhandled operation"))
|
||||
@ -221,19 +210,19 @@ func getFilter(cmdArgs *parser.Arguments) (upgrade.Filter, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func handleQuery(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
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, cfg, cmdArgs, dbExecutor,
|
||||
return printUpdateList(ctx, run, cmdArgs, dbExecutor,
|
||||
cmdArgs.ExistsDouble("u", "sysupgrade"), filter)
|
||||
}
|
||||
|
||||
if err := cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm)); err != nil {
|
||||
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("")
|
||||
@ -245,142 +234,139 @@ func handleQuery(ctx context.Context, cfg *settings.Configuration, cmdArgs *pars
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleHelp(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments) error {
|
||||
usage()
|
||||
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":
|
||||
return nil
|
||||
}
|
||||
|
||||
cfg.Runtime.Logger.Println("\npacman operation specific options:")
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
run.Logger.Println("\npacman operation specific options:")
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
func handleVersion() {
|
||||
fmt.Printf("yay v%s - libalpm v%s\n", yayVersion, alpm.Version())
|
||||
func handleVersion(logger *text.Logger) {
|
||||
logger.Printf("yay v%s - libalpm v%s\n", yayVersion, alpm.Version())
|
||||
}
|
||||
|
||||
func handlePrint(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
func handlePrint(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("d", "defaultconfig"):
|
||||
tmpConfig := settings.DefaultConfig(yayVersion)
|
||||
fmt.Printf("%v", tmpConfig)
|
||||
run.Logger.Printf("%v", tmpConfig)
|
||||
|
||||
return nil
|
||||
case cmdArgs.ExistsArg("g", "currentconfig"):
|
||||
fmt.Printf("%v", cfg)
|
||||
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, cfg.Runtime.HTTPClient, dbExecutor.LastBuildTime(), cfg.BottomUp, double, 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, cfg.Runtime.HTTPClient, dbExecutor,
|
||||
cfg.AURURL, cfg.CompletionPath, cfg.CompletionInterval, cmdArgs.ExistsDouble("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, cfg, dbExecutor)
|
||||
return localStatistics(ctx, run, dbExecutor)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleYay(ctx context.Context, cfg *settings.Configuration,
|
||||
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, cfg, dbExecutor)
|
||||
return createDevelDB(ctx, run, dbExecutor)
|
||||
case cmdArgs.ExistsDouble("c"):
|
||||
return cleanDependencies(ctx, cfg, cmdBuilder, cmdArgs, dbExecutor, true)
|
||||
return cleanDependencies(ctx, run.Cfg, cmdBuilder, cmdArgs, dbExecutor, true)
|
||||
case cmdArgs.ExistsArg("c", "clean"):
|
||||
return cleanDependencies(ctx, cfg, cmdBuilder, cmdArgs, dbExecutor, false)
|
||||
return cleanDependencies(ctx, run.Cfg, cmdBuilder, cmdArgs, dbExecutor, false)
|
||||
case len(cmdArgs.Targets) > 0:
|
||||
return displayNumberMenu(ctx, cfg, cmdArgs.Targets, dbExecutor, queryBuilder, cmdArgs)
|
||||
return displayNumberMenu(ctx, run, cmdArgs.Targets, dbExecutor, queryBuilder, cmdArgs)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleWeb(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments) error {
|
||||
func handleWeb(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments) error {
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("v", "vote"):
|
||||
return handlePackageVote(ctx, cmdArgs.Targets, cfg.Runtime.AURClient,
|
||||
cfg.Runtime.VoteClient, cfg.RequestSplitN, true)
|
||||
return handlePackageVote(ctx, cmdArgs.Targets, run.AURClient, run.Logger,
|
||||
run.VoteClient, true)
|
||||
case cmdArgs.ExistsArg("u", "unvote"):
|
||||
return handlePackageVote(ctx, cmdArgs.Targets, cfg.Runtime.AURClient,
|
||||
cfg.Runtime.VoteClient, cfg.RequestSplitN, false)
|
||||
return handlePackageVote(ctx, cmdArgs.Targets, run.AURClient, run.Logger,
|
||||
run.VoteClient, false)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleGetpkgbuild(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments, dbExecutor download.DBSearcher) error {
|
||||
func handleGetpkgbuild(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments, dbExecutor download.DBSearcher) error {
|
||||
if cmdArgs.ExistsArg("p", "print") {
|
||||
return printPkgbuilds(dbExecutor, cfg.Runtime.AURCache,
|
||||
cfg.Runtime.HTTPClient, cmdArgs.Targets, cfg.Mode, cfg.AURURL)
|
||||
return printPkgbuilds(dbExecutor, run.AURClient,
|
||||
run.HTTPClient, run.Logger, cmdArgs.Targets, run.Cfg.Mode, run.Cfg.AURURL)
|
||||
}
|
||||
|
||||
return getPkgbuilds(ctx, dbExecutor, cfg.Runtime.AURCache, cfg,
|
||||
return getPkgbuilds(ctx, dbExecutor, run.AURClient, run,
|
||||
cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
|
||||
}
|
||||
|
||||
func handleUpgrade(ctx context.Context,
|
||||
config *settings.Configuration, cmdArgs *parser.Arguments,
|
||||
run *runtime.Runtime, cmdArgs *parser.Arguments,
|
||||
) error {
|
||||
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, config.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
// -B* options
|
||||
func handleBuild(ctx context.Context,
|
||||
config *settings.Configuration, dbExecutor db.Executor, cmdArgs *parser.Arguments,
|
||||
run *runtime.Runtime, dbExecutor db.Executor, cmdArgs *parser.Arguments,
|
||||
) error {
|
||||
if cmdArgs.ExistsArg("i", "install") {
|
||||
return installLocalPKGBUILD(ctx, config, cmdArgs, dbExecutor)
|
||||
return installLocalPKGBUILD(ctx, run, cmdArgs, dbExecutor)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSync(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
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, cfg.Runtime.QueryBuilder, !cmdArgs.ExistsArg("q", "quiet"))
|
||||
return syncSearch(ctx, targets, dbExecutor, run.QueryBuilder, !cmdArgs.ExistsArg("q", "quiet"))
|
||||
case cmdArgs.ExistsArg("p", "print", "print-format"):
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case cmdArgs.ExistsArg("c", "clean"):
|
||||
return syncClean(ctx, cfg, cmdArgs, dbExecutor)
|
||||
return syncClean(ctx, run, cmdArgs, dbExecutor)
|
||||
case cmdArgs.ExistsArg("l", "list"):
|
||||
return syncList(ctx, cfg, cfg.Runtime.HTTPClient, cmdArgs, dbExecutor)
|
||||
return syncList(ctx, run, run.HTTPClient, cmdArgs, dbExecutor)
|
||||
case cmdArgs.ExistsArg("g", "groups"):
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
case cmdArgs.ExistsArg("i", "info"):
|
||||
return syncInfo(ctx, cfg, cmdArgs, targets, dbExecutor)
|
||||
return syncInfo(ctx, run, cmdArgs, targets, dbExecutor)
|
||||
case cmdArgs.ExistsArg("u", "sysupgrade") || len(cmdArgs.Targets) > 0:
|
||||
if cfg.NewInstallEngine {
|
||||
return syncInstall(ctx, cfg, cmdArgs, dbExecutor)
|
||||
}
|
||||
|
||||
return install(ctx, cfg, cmdArgs, dbExecutor, false)
|
||||
return syncInstall(ctx, run, cmdArgs, dbExecutor)
|
||||
case cmdArgs.ExistsArg("y", "refresh"):
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
return run.CmdBuilder.Show(run.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, run.Cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRemove(ctx context.Context, cfg *settings.Configuration, cmdArgs *parser.Arguments, localCache vcs.Store) error {
|
||||
err := cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
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)
|
||||
}
|
||||
@ -389,7 +375,7 @@ func handleRemove(ctx context.Context, cfg *settings.Configuration, cmdArgs *par
|
||||
}
|
||||
|
||||
// NumberMenu presents a CLI for selecting packages to install.
|
||||
func displayNumberMenu(ctx context.Context, cfg *settings.Configuration, pkgS []string, dbExecutor db.Executor,
|
||||
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)
|
||||
@ -403,9 +389,9 @@ func displayNumberMenu(ctx context.Context, cfg *settings.Configuration, pkgS []
|
||||
return nil
|
||||
}
|
||||
|
||||
text.Infoln(gotext.Get("Packages to install (eg: 1 2 3, 1-3 or ^4)"))
|
||||
run.Logger.Infoln(gotext.Get("Packages to install (eg: 1 2 3, 1-3 or ^4)"))
|
||||
|
||||
numberBuf, err := text.GetInput(os.Stdin, "", false)
|
||||
numberBuf, err := run.Logger.GetInput("", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -418,35 +404,30 @@ func displayNumberMenu(ctx context.Context, cfg *settings.Configuration, pkgS []
|
||||
}
|
||||
|
||||
// modify the arguments to pass for the install
|
||||
cmdArgs.Op = "S"
|
||||
cmdArgs.Targets = targets
|
||||
|
||||
if len(cmdArgs.Targets) == 0 {
|
||||
fmt.Println(gotext.Get(" there is nothing to do"))
|
||||
run.Logger.Println(gotext.Get(" there is nothing to do"))
|
||||
return nil
|
||||
}
|
||||
|
||||
if cfg.NewInstallEngine {
|
||||
return syncInstall(ctx, cfg, cmdArgs, dbExecutor)
|
||||
}
|
||||
|
||||
return install(ctx, cfg, cmdArgs, dbExecutor, true)
|
||||
return syncInstall(ctx, run, cmdArgs, dbExecutor)
|
||||
}
|
||||
|
||||
func syncList(ctx context.Context, cfg *settings.Configuration,
|
||||
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" && cfg.Mode.AtLeastAUR() {
|
||||
if cmdArgs.Targets[i] == "aur" && run.Cfg.Mode.AtLeastAUR() {
|
||||
cmdArgs.Targets = append(cmdArgs.Targets[:i], cmdArgs.Targets[i+1:]...)
|
||||
aur = true
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Mode.AtLeastAUR() && (len(cmdArgs.Targets) == 0 || aur) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.AURURL+"/packages.gz", http.NoBody)
|
||||
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
|
||||
}
|
||||
@ -464,22 +445,22 @@ func syncList(ctx context.Context, cfg *settings.Configuration,
|
||||
for scanner.Scan() {
|
||||
name := scanner.Text()
|
||||
if cmdArgs.ExistsArg("q", "quiet") {
|
||||
fmt.Println(name)
|
||||
run.Logger.Println(name)
|
||||
} else {
|
||||
fmt.Printf("%s %s %s", text.Magenta("aur"), text.Bold(name), text.Bold(text.Green(gotext.Get("unknown-version"))))
|
||||
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 {
|
||||
fmt.Print(text.Bold(text.Blue(gotext.Get(" [Installed]"))))
|
||||
run.Logger.Print(text.Bold(text.Blue(gotext.Get(" [Installed]"))))
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
run.Logger.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Mode.AtLeastRepo() && (len(cmdArgs.Targets) != 0 || !aur) {
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
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
|
||||
|
140
cmd_test.go
Normal file
140
cmd_test.go
Normal file
@ -0,0 +1,140 @@
|
||||
//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))
|
||||
}
|
||||
}
|
@ -61,22 +61,22 @@ _yay() {
|
||||
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'
|
||||
'c g i l p s u w y')
|
||||
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')
|
||||
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 nosudoloop
|
||||
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 upgrademenu cleanafter nocleanafter
|
||||
nocleanmenu nodiffmenu noupgrademenu provides noprovides pgpfetch nopgpfetch
|
||||
useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf
|
||||
nomakepkgconf askremovemake removemake noremovemake completioninterval aururl aurrpcurl
|
||||
searchby batchinstall nobatchinstall'
|
||||
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')
|
||||
|
@ -165,8 +165,8 @@ complete -c $progname -n "$webspecific" -s u -l unvote -d 'Unvote for AUR packag
|
||||
complete -c $progname -n "$webspecific" -xa "$listall"
|
||||
|
||||
# New options
|
||||
complete -c $progname -n "not $noopt" -l repo -d 'Assume targets are from the AUR' -f
|
||||
complete -c $progname -n "not $noopt" -s a -l aur -d 'Assume targets are from the repositories' -f
|
||||
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
|
||||
@ -216,12 +216,8 @@ complete -c $progname -n "not $noopt" -l noanswerupgrade -d 'Unset the answer fo
|
||||
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 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
|
||||
@ -229,24 +225,17 @@ complete -c $progname -n "not $noopt" -l bottomup -d 'Shows aur packages first a
|
||||
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 nodevel -d 'Disable development version checking' -f
|
||||
complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f
|
||||
complete -c $progname -n "not $noopt" -l nocleanafter -d 'Disable package sources cleaning' -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 notimeupdate -d 'Check only package version change' -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 noprovides -d 'Just look for packages by pkgname' -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 nopgpfetch -d 'Do not prompt to import PGP keys' -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 nouseask -d 'Confirm conflicts manually during the install' -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 nocombinedupgrade -d 'Perform the repo upgrade and AUR upgrade separately' -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 nobatchinstall -d 'Build and install each AUR package one by one' -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
|
||||
@ -254,4 +243,3 @@ complete -c $progname -n "not $noopt" -l norebuild -d 'Skip package build if in
|
||||
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 nosudoloop -d 'Do not loop sudo calls in the background' -f
|
||||
|
@ -23,7 +23,7 @@ _pacman_opts_commands=(
|
||||
|
||||
# options for passing to _arguments: options common to all commands
|
||||
_pacman_opts_common=(
|
||||
'--repo[Assume targets are from the repositories]'
|
||||
{-N,--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'
|
||||
@ -70,12 +70,8 @@ _pacman_opts_common=(
|
||||
'--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]"
|
||||
|
||||
@ -84,34 +80,26 @@ _pacman_opts_common=(
|
||||
'--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]'
|
||||
'--nodevel[Disable development version checking]'
|
||||
'--cleanafter[Clean package sources after successful build]'
|
||||
'--nocleanafter[Disable package sources cleaning after successful build]'
|
||||
'--keepsrc[Keep pkg/ and src/ after building packages]'
|
||||
'--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]'
|
||||
'--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]'
|
||||
'--nosudoloop[Do not loop sudo calls in the background]'
|
||||
'--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]'
|
||||
'--nobatchinstall[Build and install each AUR package one by one]'
|
||||
)
|
||||
|
||||
# options for passing to _arguments: options for --upgrade commands
|
||||
|
102
doc/yay.8
102
doc/yay.8
@ -23,7 +23,7 @@ This manpage only covers options unique to Yay. For other options see
|
||||
.TP
|
||||
.B \-Y, \-\-yay
|
||||
Perform yay specific operations. This is the default if no other operation is
|
||||
selected.
|
||||
selected and targets are defined.
|
||||
|
||||
.TP
|
||||
.B \-B, \-\-build
|
||||
@ -42,9 +42,9 @@ Downloads PKGBUILD from ABS or AUR. The ABS can only be used for Arch Linux repo
|
||||
Web related operations such as voting for AUR packages.
|
||||
|
||||
.RE
|
||||
If no arguments are provided 'yay \-Syu' will be performed.
|
||||
If no operation is specified 'yay \-Syu' will be performed
|
||||
|
||||
If no operation is selected \-Y will be assumed.
|
||||
If no operation is specified and targets are provided \-Y will be assumed
|
||||
|
||||
.SH EXTENDED PACMAN OPERATIONS
|
||||
.TP
|
||||
@ -63,7 +63,7 @@ Yay will also remove cached data about devel packages.
|
||||
|
||||
.SH NEW OPTIONS
|
||||
.TP
|
||||
.B \-\-repo
|
||||
.B \-N, \-\-repo
|
||||
Assume all targets are from the repositories. Additionally Actions such as
|
||||
sysupgrade will only act on repository packages.
|
||||
|
||||
@ -82,6 +82,10 @@ 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
|
||||
@ -93,6 +97,10 @@ 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)
|
||||
.TP
|
||||
.B \-c, \-\-complete
|
||||
@ -174,8 +182,8 @@ the AUR cache when deciding if Yay should skip builds.
|
||||
|
||||
.TP
|
||||
.B \-\-editor <command>
|
||||
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
|
||||
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
|
||||
these are set Yay will prompt the user for an editor.
|
||||
|
||||
.TP
|
||||
@ -289,6 +297,9 @@ 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
|
||||
@ -306,37 +317,14 @@ before building.
|
||||
\fBWarning\fR: Yay resolves dependencies ahead of time via the RPC. It is not
|
||||
recommended to edit pkgbuild variables unless you know what you are doing.
|
||||
|
||||
.TP
|
||||
.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 \-\-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 \-\-askyesremovemake
|
||||
Ask to remove makedepends after installing packages(with "Y" as default).
|
||||
|
||||
.TP
|
||||
.B \-\-removemake
|
||||
Remove makedepends after installing packages.
|
||||
@ -375,9 +363,8 @@ 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).
|
||||
|
||||
.TP
|
||||
.B \-\-nodevel
|
||||
Do not check for development packages updates during sysupgrade.
|
||||
If 'devel' is enabled in the configuration file, you can temporarily disable it by
|
||||
using '--devel=false' on the command line
|
||||
|
||||
.TP
|
||||
.B \-\-cleanafter
|
||||
@ -388,26 +375,18 @@ This allows VCS packages to easily pull an update
|
||||
instead of having to reclone the entire repo.
|
||||
|
||||
.TP
|
||||
.B \-\-nocleanafter
|
||||
Do not remove package sources after successful Install.
|
||||
.B \-\-keepsrc
|
||||
Keep pkg/ and src/ after building packages
|
||||
|
||||
.TP
|
||||
.B \-\-timeupdate
|
||||
During sysupgrade also compare the build time of installed packages against
|
||||
the last modification time of each package's AUR page.
|
||||
|
||||
.TP
|
||||
.B \-\-notimeupdate
|
||||
Do not consider build times during sysupgrade.
|
||||
|
||||
.TP
|
||||
.B \-\-separatesources
|
||||
Separate query results by source, AUR and sync
|
||||
|
||||
.TP
|
||||
.B \-\-noseparatesources
|
||||
Do not separate query results by source for searching
|
||||
|
||||
.TP
|
||||
.B \-\-redownload
|
||||
Always download pkgbuilds of targets even when a copy is available in cache.
|
||||
@ -428,23 +407,11 @@ 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.
|
||||
Yay will never show its provider menu but Pacman will still show its
|
||||
provider menu for repo packages.
|
||||
|
||||
.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
|
||||
@ -452,11 +419,6 @@ 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
|
||||
@ -468,12 +430,6 @@ If Yay exits for any reason After the refresh without upgrading. It is then
|
||||
the user's responsibility to either resolve the reason Yay exited or run
|
||||
a sysupgrade through pacman directly.
|
||||
|
||||
.TP
|
||||
.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 \-\-batchinstall
|
||||
When building and installing AUR packages instead of installing each package
|
||||
@ -481,10 +437,6 @@ 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.
|
||||
|
||||
.TP
|
||||
.B \-\-nobatchinstall
|
||||
Always install AUR packages immediately after building them.
|
||||
|
||||
.TP
|
||||
.B \-\-rebuild
|
||||
Always build target packages even when a copy is available in cache.
|
||||
@ -538,10 +490,6 @@ separated list that is quoted by the shell.
|
||||
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
|
||||
|
53
errors.go
53
errors.go
@ -7,56 +7,3 @@ import (
|
||||
)
|
||||
|
||||
var ErrPackagesNotFound = errors.New(gotext.Get("could not find all required packages"))
|
||||
|
||||
type NoPkgDestsFoundError struct {
|
||||
dir string
|
||||
}
|
||||
|
||||
func (e *NoPkgDestsFoundError) Error() string {
|
||||
return gotext.Get("could not find any package archives listed in %s", e.dir)
|
||||
}
|
||||
|
||||
type SetPkgReasonError struct {
|
||||
exp bool // explicit
|
||||
}
|
||||
|
||||
func (e *SetPkgReasonError) Error() string {
|
||||
reason := gotext.Get("explicit")
|
||||
if !e.exp {
|
||||
reason = gotext.Get("dependency")
|
||||
}
|
||||
|
||||
return gotext.Get("error updating package install reason to %s", reason)
|
||||
}
|
||||
|
||||
type FindPkgDestError struct {
|
||||
name, pkgDest string
|
||||
}
|
||||
|
||||
func (e *FindPkgDestError) Error() string {
|
||||
return gotext.Get(
|
||||
"the PKGDEST for %s is listed by makepkg but does not exist: %s",
|
||||
e.name, e.pkgDest)
|
||||
}
|
||||
|
||||
type PkgDestNotInListError struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (e *PkgDestNotInListError) Error() string {
|
||||
return gotext.Get("could not find PKGDEST for: %s", e.name)
|
||||
}
|
||||
|
||||
type FailedIgnoredPkgError struct {
|
||||
pkgErrors map[string]error
|
||||
}
|
||||
|
||||
func (e *FailedIgnoredPkgError) Error() string {
|
||||
msg := gotext.Get("Failed to install the following packages. Manual intervention is required:")
|
||||
|
||||
for pkg, err := range e.pkgErrors {
|
||||
msg += "\n" + pkg + " - " + err.Error()
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
26
get.go
26
get.go
@ -11,25 +11,23 @@ import (
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/download"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"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, targets []string,
|
||||
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, targets, aurURL, mode)
|
||||
pkgbuilds, err := download.PKGBUILDs(dbExecutor, aurClient, httpClient, logger, targets, aurURL, mode)
|
||||
if err != nil {
|
||||
text.Errorln(err)
|
||||
logger.Errorln(err)
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != 0 {
|
||||
for target, pkgbuild := range pkgbuilds {
|
||||
fmt.Printf("\n\n# %s\n\n", target)
|
||||
fmt.Print(string(pkgbuild))
|
||||
}
|
||||
for target, pkgbuild := range pkgbuilds {
|
||||
logger.Printf("\n\n# %s\n\n%s", target, string(pkgbuild))
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != len(targets) {
|
||||
@ -41,7 +39,7 @@ func printPkgbuilds(dbExecutor download.DBSearcher, aurClient aur.QueryClient, h
|
||||
}
|
||||
}
|
||||
|
||||
text.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
|
||||
logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
|
||||
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
@ -51,7 +49,7 @@ func printPkgbuilds(dbExecutor download.DBSearcher, aurClient aur.QueryClient, h
|
||||
|
||||
// yay -G.
|
||||
func getPkgbuilds(ctx context.Context, dbExecutor download.DBSearcher, aurClient aur.QueryClient,
|
||||
config *settings.Configuration, targets []string, force bool,
|
||||
run *runtime.Runtime, targets []string, force bool,
|
||||
) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@ -59,9 +57,9 @@ func getPkgbuilds(ctx context.Context, dbExecutor download.DBSearcher, aurClient
|
||||
}
|
||||
|
||||
cloned, errD := download.PKGBUILDRepos(ctx, dbExecutor, aurClient,
|
||||
config.Runtime.CmdBuilder, targets, config.Mode, config.AURURL, wd, force)
|
||||
run.CmdBuilder, run.Logger, targets, run.Cfg.Mode, run.Cfg.AURURL, wd, force)
|
||||
if errD != nil {
|
||||
text.Errorln(errD)
|
||||
run.Logger.Errorln(errD)
|
||||
}
|
||||
|
||||
if len(targets) != len(cloned) {
|
||||
@ -73,7 +71,7 @@ func getPkgbuilds(ctx context.Context, dbExecutor download.DBSearcher, aurClient
|
||||
}
|
||||
}
|
||||
|
||||
text.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
|
||||
run.Logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
|
||||
|
||||
err = fmt.Errorf("")
|
||||
}
|
||||
|
38
go.mod
38
go.mod
@ -2,40 +2,34 @@ module github.com/Jguer/yay/v12
|
||||
|
||||
require (
|
||||
github.com/Jguer/aur v1.2.3
|
||||
github.com/Jguer/go-alpm/v2 v2.2.0
|
||||
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/leonelquinteros/gotext v1.5.2
|
||||
github.com/stretchr/testify v1.8.2
|
||||
golang.org/x/sys v0.6.0
|
||||
golang.org/x/term v0.6.0
|
||||
golang.org/x/text v0.8.0 // indirect
|
||||
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/adrg/strutil v0.3.0
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
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
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/deckarep/golang-set/v2 v2.2.0
|
||||
github.com/itchyny/gojq v0.12.12 // indirect
|
||||
github.com/itchyny/timefmt-go v0.1.5 // indirect
|
||||
github.com/ohler55/ojg v1.17.5 // indirect
|
||||
)
|
||||
go 1.23.5
|
||||
|
||||
require github.com/hashicorp/go-multierror v1.1.1
|
||||
|
||||
require (
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
)
|
||||
|
||||
go 1.19
|
||||
toolchain go1.24.0
|
||||
|
74
go.sum
74
go.sum
@ -1,15 +1,15 @@
|
||||
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.0 h1:+sh4UEZwTpcAO+vHdySsnLZSnLZIBun8j85BbPExSlg=
|
||||
github.com/Jguer/go-alpm/v2 v2.2.0/go.mod h1:uLQcTMNM904dRiGU+/JDtDdd7Nd8mVbEVaHjhmziT7w=
|
||||
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.0 h1:bi/HB2zQbDihC8lxvATDTDzkT4bG7PATtVnDYp5rvq4=
|
||||
github.com/adrg/strutil v0.3.0/go.mod h1:Jz0wzBVE6Uiy9wxo62YEqEY1Nwto3QlLl1Il5gkLKWU=
|
||||
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=
|
||||
@ -17,8 +17,8 @@ github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEh
|
||||
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.2.0 h1:2pMQd3Soi6qfw7E5MMKaEh5W5ES18bW3AbFFnGl6LgQ=
|
||||
github.com/deckarep/golang-set/v2 v2.2.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
|
||||
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=
|
||||
@ -26,63 +26,39 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
|
||||
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.12 h1:x+xGI9BXqKoJQZkr95ibpe3cdrTbY8D9lonrK433rcA=
|
||||
github.com/itchyny/gojq v0.12.12/go.mod h1:j+3sVkjxwd7A7Z5jrbKibgOLn0ZfLWkV+Awxr/pyzJE=
|
||||
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
|
||||
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
|
||||
github.com/leonelquinteros/gotext v1.5.2 h1:T2y6ebHli+rMBCjcJlHTXyUrgXqsKBhl/ormgvt7lPo=
|
||||
github.com/leonelquinteros/gotext v1.5.2/go.mod h1:AT4NpQrOmyj1L/+hLja6aR0lk81yYYL4ePnj2kp7d6M=
|
||||
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.17.5 h1:SY6/cdhVzsLinNFIBRNSWhJgihvEWco5Y0TJe46XJ1Y=
|
||||
github.com/ohler55/ojg v1.17.5/go.mod h1:7Ghirupn8NC8hSSDpI0gcjorPxj+vSVIONDWfliHR1k=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||
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.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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=
|
||||
|
907
install.go
907
install.go
@ -1,907 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
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/completion"
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/dep"
|
||||
"github.com/Jguer/yay/v12/pkg/download"
|
||||
"github.com/Jguer/yay/v12/pkg/menus"
|
||||
"github.com/Jguer/yay/v12/pkg/pgp"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"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/srcinfo"
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
)
|
||||
|
||||
func setPkgReason(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode,
|
||||
cmdArgs *parser.Arguments, pkgs []string, exp bool,
|
||||
) error {
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
cmdArgs = cmdArgs.CopyGlobal()
|
||||
if exp {
|
||||
if err := cmdArgs.AddArg("q", "D", "asexplicit"); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := cmdArgs.AddArg("q", "D", "asdeps"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, compositePkgName := range pkgs {
|
||||
pkgSplit := strings.Split(compositePkgName, "/")
|
||||
|
||||
pkgName := pkgSplit[0]
|
||||
if len(pkgSplit) > 1 {
|
||||
pkgName = pkgSplit[1]
|
||||
}
|
||||
|
||||
cmdArgs.AddTarget(pkgName)
|
||||
}
|
||||
|
||||
if err := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, mode, settings.NoConfirm)); err != nil {
|
||||
return &SetPkgReasonError{exp: exp}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func asdeps(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode, cmdArgs *parser.Arguments, pkgs []string,
|
||||
) error {
|
||||
return setPkgReason(ctx, cmdBuilder, mode, cmdArgs, pkgs, false)
|
||||
}
|
||||
|
||||
func asexp(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode, cmdArgs *parser.Arguments, pkgs []string,
|
||||
) error {
|
||||
return setPkgReason(ctx, cmdBuilder, mode, cmdArgs, pkgs, true)
|
||||
}
|
||||
|
||||
// Install handles package installs.
|
||||
func install(ctx context.Context, cfg *settings.Configuration,
|
||||
cmdArgs *parser.Arguments, dbExecutor db.Executor, ignoreProviders bool,
|
||||
) error {
|
||||
var (
|
||||
do *dep.Order
|
||||
srcinfos map[string]*gosrc.Srcinfo
|
||||
noDeps = cmdArgs.ExistsDouble("d", "nodeps")
|
||||
noCheck = strings.Contains(cfg.MFlags, "--nocheck")
|
||||
assumeInstalled = cmdArgs.GetArgs("assume-installed")
|
||||
sysupgradeArg = cmdArgs.ExistsArg("u", "sysupgrade")
|
||||
refreshArg = cmdArgs.ExistsArg("y", "refresh")
|
||||
warnings = query.NewWarnings()
|
||||
)
|
||||
|
||||
if noDeps {
|
||||
cfg.Runtime.CmdBuilder.AddMakepkgFlag("-d")
|
||||
}
|
||||
|
||||
if cfg.Mode.AtLeastRepo() {
|
||||
if cfg.CombinedUpgrade {
|
||||
if refreshArg {
|
||||
if errR := earlyRefresh(ctx, cfg, cfg.Runtime.CmdBuilder, cmdArgs); errR != nil {
|
||||
return fmt.Errorf("%s - %w", gotext.Get("error refreshing databases"), errR)
|
||||
}
|
||||
cmdArgs.DelArg("y", "refresh")
|
||||
}
|
||||
} else if refreshArg || sysupgradeArg || len(cmdArgs.Targets) > 0 {
|
||||
if errP := earlyPacmanCall(ctx, cfg, cmdArgs, dbExecutor); errP != nil {
|
||||
return errP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we may have done -Sy, our handle now has an old
|
||||
// database.
|
||||
if errRefresh := dbExecutor.RefreshHandle(); errRefresh != nil {
|
||||
return errRefresh
|
||||
}
|
||||
|
||||
remoteNames := dbExecutor.InstalledRemotePackageNames()
|
||||
localNames := dbExecutor.InstalledSyncPackageNames()
|
||||
|
||||
remoteNamesCache := mapset.NewThreadUnsafeSet(remoteNames...)
|
||||
localNamesCache := stringset.FromSlice(localNames)
|
||||
|
||||
requestTargets := cmdArgs.Copy().Targets
|
||||
|
||||
// create the arguments to pass for the repo install
|
||||
arguments := cmdArgs.Copy()
|
||||
arguments.DelArg("asdeps", "asdep")
|
||||
arguments.DelArg("asexplicit", "asexp")
|
||||
arguments.Op = "S"
|
||||
arguments.ClearTargets()
|
||||
|
||||
if cfg.Mode == parser.ModeAUR {
|
||||
arguments.DelArg("u", "sysupgrade")
|
||||
}
|
||||
|
||||
// if we are doing -u also request all packages needing update
|
||||
if sysupgradeArg {
|
||||
var errSysUp error
|
||||
|
||||
requestTargets, errSysUp = addUpgradeTargetsToArgs(ctx, cfg, dbExecutor, cmdArgs, requestTargets, arguments)
|
||||
if errSysUp != nil {
|
||||
return errSysUp
|
||||
}
|
||||
}
|
||||
|
||||
targets := stringset.FromSlice(cmdArgs.Targets)
|
||||
|
||||
dp, err := dep.GetPool(ctx, requestTargets,
|
||||
warnings, dbExecutor, cfg.Runtime.AURClient, cfg.Mode,
|
||||
ignoreProviders, settings.NoConfirm, cfg.Provides, cfg.ReBuild, cfg.RequestSplitN, noDeps, noCheck, assumeInstalled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if errC := dp.CheckMissing(noDeps, noCheck); errC != nil {
|
||||
return errC
|
||||
}
|
||||
|
||||
if len(dp.Aur) == 0 {
|
||||
if !cfg.CombinedUpgrade {
|
||||
if sysupgradeArg {
|
||||
fmt.Println(gotext.Get(" there is nothing to do"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
cmdArgs.Op = "S"
|
||||
cmdArgs.DelArg("y", "refresh")
|
||||
|
||||
if arguments.ExistsArg("ignore") {
|
||||
cmdArgs.CreateOrAppendOption("ignore", arguments.GetArgs("ignore")...)
|
||||
}
|
||||
|
||||
return cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
conflicts, errCC := dp.CheckConflicts(cfg.UseAsk, settings.NoConfirm, noDeps)
|
||||
if errCC != nil {
|
||||
return errCC
|
||||
}
|
||||
|
||||
do = dep.GetOrder(dp, noDeps, noCheck)
|
||||
|
||||
for _, pkg := range do.Repo {
|
||||
arguments.AddTarget(pkg.DB().Name() + "/" + pkg.Name())
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Groups {
|
||||
arguments.AddTarget(pkg)
|
||||
}
|
||||
|
||||
if len(do.Aur) == 0 && len(arguments.Targets) == 0 &&
|
||||
(!cmdArgs.ExistsArg("u", "sysupgrade") || cfg.Mode == parser.ModeAUR) {
|
||||
fmt.Println(gotext.Get(" there is nothing to do"))
|
||||
return nil
|
||||
}
|
||||
|
||||
do.Print()
|
||||
fmt.Println()
|
||||
|
||||
pkgbuildDirs := make(map[string]string, len(do.Aur))
|
||||
|
||||
for _, base := range do.Aur {
|
||||
dir := filepath.Join(cfg.BuildDir, base.Pkgbase())
|
||||
pkgbuildDirs[base.Pkgbase()] = dir
|
||||
}
|
||||
|
||||
if cfg.CleanAfter {
|
||||
defer func() {
|
||||
cleanAfter(ctx, cfg, cfg.Runtime.CmdBuilder, pkgbuildDirs)
|
||||
}()
|
||||
}
|
||||
|
||||
if do.HasMake() {
|
||||
switch cfg.RemoveMake {
|
||||
case "yes":
|
||||
defer func() {
|
||||
err = removeMake(ctx, cfg, cfg.Runtime.CmdBuilder, do.GetMake(), cmdArgs)
|
||||
}()
|
||||
|
||||
case "no":
|
||||
break
|
||||
default:
|
||||
if text.ContinueTask(os.Stdin, gotext.Get("Remove make dependencies after install?"), false, settings.NoConfirm) {
|
||||
defer func() {
|
||||
err = removeMake(ctx, cfg, cfg.Runtime.CmdBuilder, do.GetMake(), cmdArgs)
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if errCleanMenu := menus.Clean(os.Stdout, cfg.CleanMenu,
|
||||
pkgbuildDirs,
|
||||
remoteNamesCache, settings.NoConfirm, cfg.AnswerClean); errCleanMenu != nil {
|
||||
if errors.As(errCleanMenu, &settings.ErrUserAbort{}) {
|
||||
return errCleanMenu
|
||||
}
|
||||
|
||||
text.Errorln(errCleanMenu)
|
||||
}
|
||||
|
||||
toSkip := pkgbuildsToSkip(cfg, do.Aur, targets)
|
||||
toClone := make([]string, 0, len(do.Aur))
|
||||
|
||||
for _, base := range do.Aur {
|
||||
if !toSkip.Get(base.Pkgbase()) {
|
||||
toClone = append(toClone, base.Pkgbase())
|
||||
}
|
||||
}
|
||||
|
||||
if toSkipSlice := toSkip.ToSlice(); len(toSkipSlice) != 0 {
|
||||
text.OperationInfoln(
|
||||
gotext.Get("PKGBUILD up to date, Skipping (%d/%d): %s",
|
||||
len(toSkipSlice), len(toClone), text.Cyan(strings.Join(toSkipSlice, ", "))))
|
||||
}
|
||||
|
||||
cloned, errA := download.AURPKGBUILDRepos(ctx,
|
||||
cfg.Runtime.CmdBuilder, toClone, cfg.AURURL, cfg.BuildDir, false)
|
||||
if errA != nil {
|
||||
return errA
|
||||
}
|
||||
|
||||
if errDiffMenu := menus.Diff(ctx, cfg.Runtime.CmdBuilder, os.Stdout, pkgbuildDirs,
|
||||
cfg.DiffMenu, remoteNamesCache,
|
||||
cloned, settings.NoConfirm, cfg.AnswerDiff); errDiffMenu != nil {
|
||||
if errors.As(errDiffMenu, &settings.ErrUserAbort{}) {
|
||||
return errDiffMenu
|
||||
}
|
||||
|
||||
text.Errorln(errDiffMenu)
|
||||
}
|
||||
|
||||
if errM := mergePkgbuilds(ctx, cfg.Runtime.CmdBuilder, pkgbuildDirs); errM != nil {
|
||||
return errM
|
||||
}
|
||||
|
||||
srcinfos, err = srcinfo.ParseSrcinfoFilesByBase(pkgbuildDirs, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if errEditMenu := menus.Edit(os.Stdout, cfg.EditMenu, pkgbuildDirs,
|
||||
cfg.Editor, cfg.EditorFlags, remoteNamesCache, srcinfos,
|
||||
settings.NoConfirm, cfg.AnswerEdit); errEditMenu != nil {
|
||||
if errors.As(errEditMenu, &settings.ErrUserAbort{}) {
|
||||
return errEditMenu
|
||||
}
|
||||
|
||||
text.Errorln(errEditMenu)
|
||||
}
|
||||
|
||||
if errI := confirmIncompatibleInstall(srcinfos, dbExecutor); errI != nil {
|
||||
return errI
|
||||
}
|
||||
|
||||
if cfg.PGPFetch {
|
||||
if _, errCPK := pgp.CheckPgpKeys(ctx, pkgbuildDirs, srcinfos, cfg.Runtime.CmdBuilder, settings.NoConfirm); errCPK != nil {
|
||||
return errCPK
|
||||
}
|
||||
}
|
||||
|
||||
if !cfg.CombinedUpgrade {
|
||||
arguments.DelArg("u", "sysupgrade")
|
||||
}
|
||||
|
||||
if len(arguments.Targets) > 0 || arguments.ExistsArg("u") {
|
||||
if errShow := cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, cfg.Mode, settings.NoConfirm)); errShow != nil {
|
||||
return errors.New(gotext.Get("error installing repo packages"))
|
||||
}
|
||||
|
||||
deps := make([]string, 0)
|
||||
exp := make([]string, 0)
|
||||
|
||||
for _, pkg := range do.Repo {
|
||||
if !dp.Explicit.Get(pkg.Name()) && !localNamesCache.Get(pkg.Name()) && !remoteNamesCache.Contains(pkg.Name()) {
|
||||
deps = append(deps, pkg.Name())
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if cmdArgs.ExistsArg("asdeps", "asdep") && dp.Explicit.Get(pkg.Name()) {
|
||||
deps = append(deps, pkg.Name())
|
||||
} else if cmdArgs.ExistsArg("asexp", "asexplicit") && dp.Explicit.Get(pkg.Name()) {
|
||||
exp = append(exp, pkg.Name())
|
||||
}
|
||||
}
|
||||
|
||||
if errDeps := asdeps(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cmdArgs, deps); errDeps != nil {
|
||||
return errDeps
|
||||
}
|
||||
|
||||
if errExp := asexp(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cmdArgs, exp); errExp != nil {
|
||||
return errExp
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
_ = completion.Update(ctx, cfg.Runtime.HTTPClient, dbExecutor,
|
||||
cfg.AURURL, cfg.CompletionPath, cfg.CompletionInterval, false)
|
||||
}()
|
||||
|
||||
if errP := downloadPKGBUILDSourceFanout(ctx,
|
||||
cfg.Runtime.CmdBuilder,
|
||||
pkgbuildDirs,
|
||||
true, cfg.MaxConcurrentDownloads); errP != nil {
|
||||
text.Errorln(errP)
|
||||
}
|
||||
|
||||
if errB := buildInstallPkgbuilds(ctx, cfg, cmdArgs, dbExecutor, dp, do,
|
||||
srcinfos, true, conflicts, noDeps, noCheck); errB != nil {
|
||||
return errB
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addUpgradeTargetsToArgs(ctx context.Context, cfg *settings.Configuration, dbExecutor db.Executor,
|
||||
cmdArgs *parser.Arguments, requestTargets []string, arguments *parser.Arguments,
|
||||
) ([]string, error) {
|
||||
ignore, targets, errUp := sysupgradeTargets(ctx, cfg, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
|
||||
if errUp != nil {
|
||||
return nil, errUp
|
||||
}
|
||||
|
||||
for _, up := range targets {
|
||||
cmdArgs.AddTarget(up)
|
||||
requestTargets = append(requestTargets, up)
|
||||
}
|
||||
|
||||
if len(ignore) > 0 {
|
||||
arguments.CreateOrAppendOption("ignore", ignore.ToSlice()...)
|
||||
}
|
||||
|
||||
return requestTargets, nil
|
||||
}
|
||||
|
||||
func removeMake(ctx context.Context, config *settings.Configuration,
|
||||
cmdBuilder exe.ICmdBuilder, makeDeps []string, cmdArgs *parser.Arguments,
|
||||
) error {
|
||||
removeArguments := cmdArgs.CopyGlobal()
|
||||
|
||||
err := removeArguments.AddArg("R", "s", "u")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pkg := range makeDeps {
|
||||
removeArguments.AddTarget(pkg)
|
||||
}
|
||||
|
||||
oldValue := settings.NoConfirm
|
||||
settings.NoConfirm = true
|
||||
err = cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
removeArguments, config.Mode, settings.NoConfirm))
|
||||
settings.NoConfirm = oldValue
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func inRepos(dbExecutor db.Executor, pkg string) bool {
|
||||
target := dep.ToTarget(pkg)
|
||||
|
||||
if target.DB == "aur" {
|
||||
return false
|
||||
} else if target.DB != "" {
|
||||
return true
|
||||
}
|
||||
|
||||
previousHideMenus := settings.HideMenus
|
||||
settings.HideMenus = true
|
||||
exists := dbExecutor.SyncSatisfierExists(target.DepString())
|
||||
settings.HideMenus = previousHideMenus
|
||||
|
||||
return exists || len(dbExecutor.PackagesFromGroup(target.Name)) > 0
|
||||
}
|
||||
|
||||
func earlyPacmanCall(ctx context.Context, cfg *settings.Configuration,
|
||||
cmdArgs *parser.Arguments, dbExecutor db.Executor,
|
||||
) error {
|
||||
arguments := cmdArgs.Copy()
|
||||
arguments.Op = "S"
|
||||
targets := cmdArgs.Targets
|
||||
cmdArgs.ClearTargets()
|
||||
arguments.ClearTargets()
|
||||
|
||||
if cfg.Mode == parser.ModeRepo {
|
||||
arguments.Targets = targets
|
||||
} else {
|
||||
// separate aur and repo targets
|
||||
for _, target := range targets {
|
||||
if inRepos(dbExecutor, target) {
|
||||
arguments.AddTarget(target)
|
||||
} else {
|
||||
cmdArgs.AddTarget(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cmdArgs.ExistsArg("y", "refresh") || cmdArgs.ExistsArg("u", "sysupgrade") || len(arguments.Targets) > 0 {
|
||||
if err := cfg.Runtime.CmdBuilder.Show(cfg.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, cfg.Mode, settings.NoConfirm)); err != nil {
|
||||
return errors.New(gotext.Get("error installing repo packages"))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func earlyRefresh(ctx context.Context, cfg *settings.Configuration, cmdBuilder exe.ICmdBuilder, cmdArgs *parser.Arguments) error {
|
||||
arguments := cmdArgs.Copy()
|
||||
arguments.DelArg("u", "sysupgrade")
|
||||
arguments.DelArg("s", "search")
|
||||
arguments.DelArg("i", "info")
|
||||
arguments.DelArg("l", "list")
|
||||
arguments.ClearTargets()
|
||||
|
||||
return cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, cfg.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
||||
func confirmIncompatibleInstall(srcinfos map[string]*gosrc.Srcinfo, dbExecutor db.Executor) error {
|
||||
incompatible := []string{}
|
||||
|
||||
alpmArch, err := dbExecutor.AlpmArchitectures()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nextpkg:
|
||||
for base, srcinfo := range srcinfos {
|
||||
for _, arch := range srcinfo.Arch {
|
||||
if db.ArchIsSupported(alpmArch, arch) {
|
||||
continue nextpkg
|
||||
}
|
||||
}
|
||||
incompatible = append(incompatible, base)
|
||||
}
|
||||
|
||||
if len(incompatible) > 0 {
|
||||
text.Warnln(gotext.Get("The following packages are not compatible with your architecture:"))
|
||||
|
||||
for _, pkg := range incompatible {
|
||||
fmt.Print(" " + text.Cyan(pkg))
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
|
||||
if !text.ContinueTask(os.Stdin, gotext.Get("Try to build them anyway?"), true, settings.NoConfirm) {
|
||||
return &settings.ErrUserAbort{}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parsePackageList(ctx context.Context, cmdBuilder exe.ICmdBuilder,
|
||||
dir string,
|
||||
) (pkgdests map[string]string, pkgVersion string, err error) {
|
||||
stdout, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildMakepkgCmd(ctx, dir, "--packagelist"))
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%s %w", stderr, err)
|
||||
}
|
||||
|
||||
lines := strings.Split(stdout, "\n")
|
||||
pkgdests = make(map[string]string)
|
||||
|
||||
for _, line := range lines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
fileName := filepath.Base(line)
|
||||
split := strings.Split(fileName, "-")
|
||||
|
||||
if len(split) < 4 {
|
||||
return nil, "", errors.New(gotext.Get("cannot find package name: %v", split))
|
||||
}
|
||||
|
||||
// pkgname-pkgver-pkgrel-arch.pkgext
|
||||
// This assumes 3 dashes after the pkgname, Will cause an error
|
||||
// if the PKGEXT contains a dash. Please no one do that.
|
||||
pkgName := strings.Join(split[:len(split)-3], "-")
|
||||
pkgVersion = strings.Join(split[len(split)-3:len(split)-1], "-")
|
||||
pkgdests[pkgName] = line
|
||||
}
|
||||
|
||||
if len(pkgdests) == 0 {
|
||||
return nil, "", &NoPkgDestsFoundError{dir}
|
||||
}
|
||||
|
||||
return pkgdests, pkgVersion, nil
|
||||
}
|
||||
|
||||
func pkgbuildsToSkip(cfg *settings.Configuration, bases []dep.Base, targets stringset.StringSet) stringset.StringSet {
|
||||
toSkip := make(stringset.StringSet)
|
||||
|
||||
for _, base := range bases {
|
||||
isTarget := false
|
||||
for _, pkg := range base {
|
||||
isTarget = isTarget || targets.Get(pkg.Name)
|
||||
}
|
||||
|
||||
if (cfg.ReDownload == "yes" && isTarget) || cfg.ReDownload == "all" {
|
||||
continue
|
||||
}
|
||||
|
||||
dir := filepath.Join(cfg.BuildDir, base.Pkgbase(), ".SRCINFO")
|
||||
pkgbuild, err := gosrc.ParseFile(dir)
|
||||
|
||||
if err == nil {
|
||||
if db.VerCmp(pkgbuild.Version(), base.Version()) >= 0 {
|
||||
toSkip.Set(base.Pkgbase())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toSkip
|
||||
}
|
||||
|
||||
func gitMerge(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) error {
|
||||
_, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(ctx,
|
||||
dir, "reset", "--hard", "HEAD"))
|
||||
if err != nil {
|
||||
return errors.New(gotext.Get("error resetting %s: %s", dir, stderr))
|
||||
}
|
||||
|
||||
_, stderr, err = cmdBuilder.Capture(
|
||||
cmdBuilder.BuildGitCmd(ctx,
|
||||
dir, "merge", "--no-edit", "--ff"))
|
||||
if err != nil {
|
||||
return errors.New(gotext.Get("error merging %s: %s", dir, stderr))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func mergePkgbuilds(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgbuildDirs map[string]string) error {
|
||||
for _, dir := range pkgbuildDirs {
|
||||
err := gitMerge(ctx, cmdBuilder, dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildInstallPkgbuilds(
|
||||
ctx context.Context,
|
||||
cfg *settings.Configuration,
|
||||
cmdArgs *parser.Arguments,
|
||||
dbExecutor db.Executor,
|
||||
dp *dep.Pool,
|
||||
do *dep.Order,
|
||||
srcinfos map[string]*gosrc.Srcinfo,
|
||||
incompatible bool,
|
||||
conflicts stringset.MapStringSet, noDeps, noCheck bool,
|
||||
) error {
|
||||
deps := make([]string, 0)
|
||||
exp := make([]string, 0)
|
||||
pkgArchives := make([]string, 0)
|
||||
oldConfirm := settings.NoConfirm
|
||||
settings.NoConfirm = true
|
||||
|
||||
// remotenames: names of all non repo packages on the system
|
||||
remoteNames := dbExecutor.InstalledRemotePackageNames()
|
||||
localNames := dbExecutor.InstalledSyncPackageNames()
|
||||
|
||||
// cache as a stringset. maybe make it return a string set in the first
|
||||
// place
|
||||
remoteNamesCache := stringset.FromSlice(remoteNames)
|
||||
localNamesCache := stringset.FromSlice(localNames)
|
||||
|
||||
for i, base := range do.Aur {
|
||||
pkg := base.Pkgbase()
|
||||
dir := filepath.Join(cfg.BuildDir, pkg)
|
||||
built := true
|
||||
|
||||
satisfied := true
|
||||
all:
|
||||
for _, pkg := range base {
|
||||
for _, dep := range dep.ComputeCombinedDepList(pkg, noDeps, noCheck) {
|
||||
if !dp.AlpmExecutor.LocalSatisfierExists(dep) {
|
||||
satisfied = false
|
||||
text.Warnln(gotext.Get("%s not satisfied, flushing install queue", dep))
|
||||
|
||||
break all
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !satisfied || !cfg.BatchInstall {
|
||||
text.Debugln("non batch installing archives:", pkgArchives)
|
||||
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder,
|
||||
cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives)
|
||||
errReason := setInstallReason(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cmdArgs, deps, exp)
|
||||
|
||||
deps = make([]string, 0)
|
||||
exp = make([]string, 0)
|
||||
pkgArchives = make([]string, 0) // reset the pkgarchives
|
||||
|
||||
if errArchive != nil || errReason != nil {
|
||||
if i != 0 {
|
||||
go cfg.Runtime.VCSStore.RemovePackages([]string{do.Aur[i-1].String()})
|
||||
}
|
||||
|
||||
if errArchive != nil {
|
||||
return errArchive
|
||||
}
|
||||
|
||||
return errReason
|
||||
}
|
||||
}
|
||||
|
||||
srcInfo := srcinfos[pkg]
|
||||
|
||||
args := []string{"--nobuild", "-fC"}
|
||||
|
||||
if incompatible {
|
||||
args = append(args, "--ignorearch")
|
||||
}
|
||||
|
||||
// pkgver bump
|
||||
if err := cfg.Runtime.CmdBuilder.Show(
|
||||
cfg.Runtime.CmdBuilder.BuildMakepkgCmd(ctx, dir, args...)); err != nil {
|
||||
return errors.New(gotext.Get("error making: %s", base.String()))
|
||||
}
|
||||
|
||||
pkgdests, pkgVersion, errList := parsePackageList(ctx, cfg.Runtime.CmdBuilder, dir)
|
||||
if errList != nil {
|
||||
return errList
|
||||
}
|
||||
|
||||
isExplicit := false
|
||||
for _, b := range base {
|
||||
isExplicit = isExplicit || dp.Explicit.Get(b.Name)
|
||||
}
|
||||
|
||||
if cfg.ReBuild == "no" || (cfg.ReBuild == "yes" && !isExplicit) {
|
||||
for _, split := range base {
|
||||
pkgdest, ok := pkgdests[split.Name]
|
||||
if !ok {
|
||||
return &PkgDestNotInListError{split.Name}
|
||||
}
|
||||
|
||||
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
|
||||
built = false
|
||||
} else if errStat != nil {
|
||||
return errStat
|
||||
}
|
||||
}
|
||||
} else {
|
||||
built = false
|
||||
}
|
||||
|
||||
if cmdArgs.ExistsArg("needed") {
|
||||
installed := true
|
||||
for _, split := range base {
|
||||
installed = dp.AlpmExecutor.IsCorrectVersionInstalled(split.Name, pkgVersion)
|
||||
}
|
||||
|
||||
if installed {
|
||||
err := cfg.Runtime.CmdBuilder.Show(
|
||||
cfg.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
|
||||
dir, "-c", "--nobuild", "--noextract", "--ignorearch"))
|
||||
if err != nil {
|
||||
return errors.New(gotext.Get("error making: %s", err))
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stdout, gotext.Get("%s is up to date -- skipping", text.Cyan(pkg+"-"+pkgVersion)))
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if built {
|
||||
err := cfg.Runtime.CmdBuilder.Show(
|
||||
cfg.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
|
||||
dir, "-c", "--nobuild", "--noextract", "--ignorearch"))
|
||||
if err != nil {
|
||||
return errors.New(gotext.Get("error making: %s", err))
|
||||
}
|
||||
|
||||
text.Warnln(gotext.Get("%s already made -- skipping build", text.Cyan(pkg+"-"+pkgVersion)))
|
||||
} else {
|
||||
args := []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
|
||||
|
||||
if incompatible {
|
||||
args = append(args, "--ignorearch")
|
||||
}
|
||||
|
||||
if errMake := cfg.Runtime.CmdBuilder.Show(
|
||||
cfg.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
|
||||
dir, args...)); errMake != nil {
|
||||
return errors.New(gotext.Get("error making: %s", base.String()))
|
||||
}
|
||||
}
|
||||
|
||||
// conflicts have been checked so answer y for them
|
||||
if cfg.UseAsk && cmdArgs.ExistsArg("ask") {
|
||||
ask, _ := strconv.Atoi(cmdArgs.Options["ask"].First())
|
||||
uask := alpm.QuestionType(ask) | alpm.QuestionTypeConflictPkg
|
||||
cmdArgs.Options["ask"].Set(fmt.Sprint(uask))
|
||||
} else {
|
||||
for _, split := range base {
|
||||
if _, ok := conflicts[split.Name]; ok {
|
||||
settings.NoConfirm = false
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var errAdd error
|
||||
|
||||
for _, split := range base {
|
||||
for suffix, optional := range map[string]bool{"": false, "-debug": true} {
|
||||
deps, exp, pkgArchives, errAdd = doAddTarget(dp, localNamesCache, remoteNamesCache,
|
||||
cmdArgs, pkgdests, deps, exp, split.Name+suffix, optional, pkgArchives)
|
||||
if errAdd != nil {
|
||||
return errAdd
|
||||
}
|
||||
}
|
||||
}
|
||||
text.Debugln("deps:", deps, "exp:", exp, "pkgArchives:", pkgArchives)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, pkg := range base {
|
||||
if srcInfo == nil {
|
||||
text.Errorln(gotext.Get("could not find srcinfo for: %s", pkg.Name))
|
||||
break
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
text.Debugln("checking vcs store for:", pkg.Name)
|
||||
go func(name string) {
|
||||
cfg.Runtime.VCSStore.Update(ctx, name, srcInfo.Source)
|
||||
wg.Done()
|
||||
}(pkg.Name)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
text.Debugln("installing archives:", pkgArchives)
|
||||
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives)
|
||||
if errArchive != nil {
|
||||
go cfg.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
|
||||
}
|
||||
|
||||
errReason := setInstallReason(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cmdArgs, deps, exp)
|
||||
if errReason != nil {
|
||||
go cfg.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
|
||||
}
|
||||
|
||||
settings.NoConfirm = oldConfirm
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func installPkgArchive(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode,
|
||||
vcsStore vcs.Store,
|
||||
cmdArgs *parser.Arguments,
|
||||
pkgArchives []string,
|
||||
) error {
|
||||
if len(pkgArchives) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arguments := cmdArgs.Copy()
|
||||
arguments.ClearTargets()
|
||||
arguments.Op = "U"
|
||||
arguments.DelArg("confirm")
|
||||
arguments.DelArg("noconfirm")
|
||||
arguments.DelArg("c", "clean")
|
||||
arguments.DelArg("i", "install")
|
||||
arguments.DelArg("q", "quiet")
|
||||
arguments.DelArg("y", "refresh")
|
||||
arguments.DelArg("u", "sysupgrade")
|
||||
arguments.DelArg("w", "downloadonly")
|
||||
arguments.DelArg("asdeps", "asdep")
|
||||
arguments.DelArg("asexplicit", "asexp")
|
||||
|
||||
arguments.AddTarget(pkgArchives...)
|
||||
|
||||
if errShow := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, mode, settings.NoConfirm)); errShow != nil {
|
||||
return errShow
|
||||
}
|
||||
|
||||
if errStore := vcsStore.Save(); errStore != nil {
|
||||
fmt.Fprintln(os.Stderr, errStore)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setInstallReason(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder, mode parser.TargetMode,
|
||||
cmdArgs *parser.Arguments, deps, exps []string,
|
||||
) error {
|
||||
if len(deps)+len(exps) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if errDeps := asdeps(ctx, cmdBuilder, mode, cmdArgs, deps); errDeps != nil {
|
||||
return errDeps
|
||||
}
|
||||
|
||||
return asexp(ctx, cmdBuilder, mode, cmdArgs, exps)
|
||||
}
|
||||
|
||||
func doAddTarget(dp *dep.Pool, localNamesCache, remoteNamesCache stringset.StringSet,
|
||||
cmdArgs *parser.Arguments, pkgdests map[string]string,
|
||||
deps, exp []string, name string, optional bool, pkgArchives []string,
|
||||
) (newDeps, newExp, newPkgArchives []string, err error) {
|
||||
pkgdest, ok := pkgdests[name]
|
||||
if !ok {
|
||||
if optional {
|
||||
return deps, exp, pkgArchives, nil
|
||||
}
|
||||
|
||||
return deps, exp, pkgArchives, &PkgDestNotInListError{name}
|
||||
}
|
||||
|
||||
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
|
||||
if optional {
|
||||
return deps, exp, pkgArchives, nil
|
||||
}
|
||||
|
||||
return deps, exp, pkgArchives, &FindPkgDestError{pkgDest: pkgdest, name: name}
|
||||
}
|
||||
|
||||
pkgArchives = append(pkgArchives, pkgdest)
|
||||
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("asdeps", "asdep"):
|
||||
deps = append(deps, name)
|
||||
case cmdArgs.ExistsArg("asexplicit", "asexp"):
|
||||
exp = append(exp, name)
|
||||
case !dp.Explicit.Get(name) && !localNamesCache.Get(name) && !remoteNamesCache.Get(name):
|
||||
deps = append(deps, name)
|
||||
default:
|
||||
exp = append(exp, name)
|
||||
}
|
||||
|
||||
return deps, exp, pkgArchives, nil
|
||||
}
|
@ -4,6 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -12,20 +13,17 @@ import (
|
||||
"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/topo"
|
||||
"github.com/Jguer/yay/v12/pkg/sync"
|
||||
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
|
||||
ErrNoBuildFiles = errors.New(gotext.Get("cannot find PKGBUILD and .SRCINFO in directory"))
|
||||
)
|
||||
var ErrNoBuildFiles = errors.New(gotext.Get("cannot find PKGBUILD and .SRCINFO in directory"))
|
||||
|
||||
func srcinfoExists(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder, targetDir string,
|
||||
@ -45,6 +43,10 @@ func srcinfoExists(ctx context.Context,
|
||||
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)
|
||||
}
|
||||
@ -57,39 +59,40 @@ func srcinfoExists(ctx context.Context,
|
||||
|
||||
func installLocalPKGBUILD(
|
||||
ctx context.Context,
|
||||
config *settings.Configuration,
|
||||
run *runtime.Runtime,
|
||||
cmdArgs *parser.Arguments,
|
||||
dbExecutor db.Executor,
|
||||
) error {
|
||||
aurCache := config.Runtime.AURCache
|
||||
noCheck := strings.Contains(config.MFlags, "--nocheck")
|
||||
aurCache := run.AURClient
|
||||
noCheck := strings.Contains(run.Cfg.MFlags, "--nocheck")
|
||||
|
||||
if len(cmdArgs.Targets) < 1 {
|
||||
return errors.New(gotext.Get("no target directories specified"))
|
||||
}
|
||||
|
||||
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
|
||||
cmdArgs.ExistsDouble("d", "nodeps"), noCheck, cmdArgs.ExistsArg("needed"),
|
||||
config.Runtime.Logger.Child("grapher"))
|
||||
graph := topo.New[string, *dep.InstallInfo]()
|
||||
srcInfos := map[string]*gosrc.Srcinfo{}
|
||||
for _, targetDir := range cmdArgs.Targets {
|
||||
if err := srcinfoExists(ctx, config.Runtime.CmdBuilder, targetDir); err != nil {
|
||||
if err := srcinfoExists(ctx, run.CmdBuilder, targetDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkgbuild, err := gosrc.ParseFile(filepath.Join(targetDir, ".SRCINFO"))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
|
||||
return fmt.Errorf("%s: %w", gotext.Get("failed to parse .SRCINFO"), err)
|
||||
}
|
||||
|
||||
var errG error
|
||||
graph, errG = grapher.GraphFromSrcInfo(ctx, graph, targetDir, pkgbuild)
|
||||
if errG != nil {
|
||||
return errG
|
||||
}
|
||||
srcInfos[targetDir] = pkgbuild
|
||||
}
|
||||
|
||||
opService := NewOperationService(ctx, config, dbExecutor)
|
||||
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 {
|
||||
@ -101,5 +104,5 @@ func installLocalPKGBUILD(
|
||||
if err := multiErr.Return(); err != nil {
|
||||
return err
|
||||
}
|
||||
return opService.Run(ctx, cmdArgs, targets, []string{})
|
||||
return opService.Run(ctx, run, cmdArgs, targets, []string{})
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -17,6 +20,7 @@ import (
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/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"
|
||||
@ -24,6 +28,10 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
)
|
||||
|
||||
func newTestLogger() *text.Logger {
|
||||
return text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), true, "test")
|
||||
}
|
||||
|
||||
func TestIntegrationLocalInstall(t *testing.T) {
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
@ -48,17 +56,17 @@ func TestIntegrationLocalInstall(t *testing.T) {
|
||||
}
|
||||
|
||||
wantShow := []string{
|
||||
"makepkg --verifysource -Ccf",
|
||||
"makepkg --verifysource --skippgpcheck -f -Cc",
|
||||
"pacman -S --config /etc/pacman.conf -- community/dotnet-sdk-6.0 community/dotnet-runtime-6.0",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 dotnet-sdk-6.0",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin-server jellyfin-web",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin-server jellyfin jellyfin-web",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin",
|
||||
}
|
||||
|
||||
wantCapture := []string{
|
||||
@ -66,7 +74,6 @@ func TestIntegrationLocalInstall(t *testing.T) {
|
||||
"git -C testdata/jfin git reset --hard HEAD",
|
||||
"git -C testdata/jfin git merge --no-edit --ff",
|
||||
"makepkg --packagelist",
|
||||
"makepkg --packagelist",
|
||||
}
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
@ -135,23 +142,25 @@ func TestIntegrationLocalInstall(t *testing.T) {
|
||||
|
||||
return nil
|
||||
},
|
||||
LocalPackageFn: func(s string) mock.IPackage { return nil },
|
||||
InstalledRemotePackageNamesFn: func() []string { return []string{} },
|
||||
}
|
||||
|
||||
config := &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
Runtime: &settings.Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), true, "test"),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURCache: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
run := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = handleCmd(context.Background(), config, cmdArgs, db)
|
||||
err = handleCmd(context.Background(), run, cmdArgs, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mockRunner.ShowCalls, len(wantShow))
|
||||
@ -255,22 +264,22 @@ func TestIntegrationLocalInstallMissingDep(t *testing.T) {
|
||||
|
||||
return nil
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
}
|
||||
|
||||
config := &settings.Configuration{
|
||||
Runtime: &settings.Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), true, "test"),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURCache: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
run := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = handleCmd(context.Background(), config, cmdArgs, db)
|
||||
err = handleCmd(context.Background(), run, cmdArgs, db)
|
||||
require.ErrorContains(t, err, wantErr.Error())
|
||||
|
||||
require.Len(t, mockRunner.ShowCalls, len(wantShow))
|
||||
@ -312,14 +321,12 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) {
|
||||
}
|
||||
|
||||
wantShow := []string{
|
||||
"makepkg --verifysource -Ccf",
|
||||
"makepkg --verifysource --skippgpcheck -f -Cc",
|
||||
"pacman -S --config /etc/pacman.conf -- community/dotnet-sdk-6.0 community/dotnet-runtime-6.0",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 dotnet-sdk-6.0",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
}
|
||||
|
||||
@ -328,7 +335,6 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) {
|
||||
"git -C testdata/jfin git reset --hard HEAD",
|
||||
"git -C testdata/jfin git merge --no-edit --ff",
|
||||
"makepkg --packagelist",
|
||||
"makepkg --packagelist",
|
||||
}
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
@ -412,23 +418,24 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) {
|
||||
|
||||
return nil
|
||||
},
|
||||
InstalledRemotePackageNamesFn: func() []string { return []string{} },
|
||||
}
|
||||
|
||||
config := &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
Runtime: &settings.Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), true, "test"),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURCache: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
run := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = handleCmd(context.Background(), config, cmdArgs, db)
|
||||
err = handleCmd(context.Background(), run, cmdArgs, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mockRunner.ShowCalls, len(wantShow), "show calls: %v", mockRunner.ShowCalls)
|
||||
@ -479,17 +486,17 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) {
|
||||
}
|
||||
|
||||
wantShow := []string{
|
||||
"makepkg --verifysource -Ccf",
|
||||
"makepkg --verifysource --skippgpcheck -f -Cc",
|
||||
"pacman -S --config /etc/pacman.conf -- community/dotnet-sdk-6.0 community/dotnet-runtime-6.0",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 dotnet-sdk-6.0",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin-server jellyfin-web",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin-server jellyfin jellyfin-web",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin",
|
||||
}
|
||||
|
||||
wantCapture := []string{
|
||||
@ -498,7 +505,6 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) {
|
||||
"git -C testdata/jfin git reset --hard HEAD",
|
||||
"git -C testdata/jfin git merge --no-edit --ff",
|
||||
"makepkg --packagelist",
|
||||
"makepkg --packagelist",
|
||||
}
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
@ -552,6 +558,7 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) {
|
||||
|
||||
return true
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
switch s {
|
||||
case "dotnet-runtime>=6", "dotnet-runtime<7":
|
||||
@ -572,24 +579,25 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) {
|
||||
|
||||
return nil
|
||||
},
|
||||
InstalledRemotePackageNamesFn: func() []string { return []string{} },
|
||||
}
|
||||
|
||||
config := &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
Debug: false,
|
||||
Runtime: &settings.Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), true, "test"),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURCache: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
run := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
Debug: false,
|
||||
},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = handleCmd(context.Background(), config, cmdArgs, db)
|
||||
err = handleCmd(context.Background(), run, cmdArgs, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mockRunner.ShowCalls, len(wantShow))
|
||||
@ -640,7 +648,6 @@ func TestIntegrationLocalInstallMissingFiles(t *testing.T) {
|
||||
wantCapture := []string{}
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
fmt.Println(cmd.Args)
|
||||
if cmd.Args[1] == "--printsrcinfo" {
|
||||
return string(srcinfo), "", nil
|
||||
}
|
||||
@ -711,16 +718,17 @@ func TestIntegrationLocalInstallMissingFiles(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
config := &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
Runtime: &settings.Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), true, "test"),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURCache: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
config := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
Debug: false,
|
||||
},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -742,3 +750,270 @@ func TestIntegrationLocalInstallMissingFiles(t *testing.T) {
|
||||
assert.Subset(t, strings.Split(show, " "), strings.Split(wantShow[i], " "), fmt.Sprintf("%d - %s", i, show))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationLocalInstallWithDepsProvides(t *testing.T) {
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
gitBin := t.TempDir() + "/git"
|
||||
tmpDir := t.TempDir()
|
||||
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())
|
||||
|
||||
tars := []string{
|
||||
tmpDir + "/ceph-bin-17.2.6-2-x86_64.pkg.tar.zst",
|
||||
tmpDir + "/ceph-libs-bin-17.2.6-2-x86_64.pkg.tar.zst",
|
||||
}
|
||||
|
||||
wantShow := []string{
|
||||
"makepkg --verifysource --skippgpcheck -f -Cc",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/ceph-libs-bin-17.2.6-2-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- ceph-libs-bin",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/ceph-bin-17.2.6-2-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- ceph-bin",
|
||||
}
|
||||
|
||||
wantCapture := []string{
|
||||
"git -C testdata/cephbin git reset --hard HEAD",
|
||||
"git -C testdata/cephbin git merge --no-edit --ff",
|
||||
"makepkg --packagelist",
|
||||
"makepkg --packagelist",
|
||||
}
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return strings.Join(tars, "\n"), "", nil
|
||||
}
|
||||
|
||||
once := sync.Once{}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
once.Do(func() {
|
||||
for _, tar := range tars {
|
||||
f, err := os.OpenFile(tar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
}
|
||||
})
|
||||
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("B")
|
||||
cmdArgs.AddArg("i")
|
||||
cmdArgs.AddTarget("testdata/cephbin")
|
||||
settings.NoConfirm = true
|
||||
defer func() { settings.NoConfirm = false }()
|
||||
db := &mock.DBExecutor{
|
||||
AlpmArchitecturesFn: func() ([]string, error) {
|
||||
return []string{"x86_64"}, nil
|
||||
},
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "ceph=17.2.6-2", "ceph-libs=17.2.6-2":
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
return nil
|
||||
},
|
||||
LocalPackageFn: func(s string) mock.IPackage { return nil },
|
||||
InstalledRemotePackageNamesFn: func() []string { return []string{} },
|
||||
}
|
||||
|
||||
config := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = handleCmd(context.Background(), config, cmdArgs, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
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, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationLocalInstallTwoSrcInfosWithDeps(t *testing.T) {
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
gitBin := t.TempDir() + "/git"
|
||||
tmpDir1 := t.TempDir()
|
||||
tmpDir2 := t.TempDir()
|
||||
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())
|
||||
|
||||
pkgsTars := []string{
|
||||
tmpDir1 + "/libzip-git-1.9.2.r166.gd2c47d0f-1-x86_64.pkg.tar.zst",
|
||||
tmpDir2 + "/gourou-0.8.1-4-x86_64.pkg.tar.zst",
|
||||
}
|
||||
|
||||
wantShow := []string{
|
||||
"makepkg --verifysource --skippgpcheck -f -Cc",
|
||||
"makepkg --verifysource --skippgpcheck -f -Cc",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir1/libzip-git-1.9.2.r166.gd2c47d0f-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- libzip-git",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir2/gourou-0.8.1-4-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- gourou",
|
||||
}
|
||||
|
||||
wantCapture := []string{
|
||||
"git -C testdata/gourou git reset --hard HEAD",
|
||||
"git -C testdata/gourou git merge --no-edit --ff",
|
||||
"git -C testdata/libzip-git git reset --hard HEAD",
|
||||
"git -C testdata/libzip-git git merge --no-edit --ff",
|
||||
"makepkg --packagelist",
|
||||
"makepkg --packagelist",
|
||||
}
|
||||
|
||||
captureCounter := 0
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
captureCounter++
|
||||
switch captureCounter {
|
||||
case 5:
|
||||
return pkgsTars[0] + "\n", "", nil
|
||||
case 6:
|
||||
return pkgsTars[1] + "\n", "", nil
|
||||
default:
|
||||
return "", "", nil
|
||||
}
|
||||
}
|
||||
|
||||
once := sync.Once{}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
once.Do(func() {
|
||||
for _, tar := range pkgsTars {
|
||||
f, err := os.OpenFile(tar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
}
|
||||
})
|
||||
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("B")
|
||||
cmdArgs.AddArg("i")
|
||||
cmdArgs.AddTarget("testdata/gourou")
|
||||
cmdArgs.AddTarget("testdata/libzip-git")
|
||||
settings.NoConfirm = true
|
||||
defer func() { settings.NoConfirm = false }()
|
||||
db := &mock.DBExecutor{
|
||||
AlpmArchitecturesFn: func() ([]string, error) {
|
||||
return []string{"x86_64"}, nil
|
||||
},
|
||||
LocalSatisfierExistsFn: func(s string) bool {
|
||||
switch s {
|
||||
case "gourou", "libzip", "libzip-git":
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
SyncSatisfierFn: func(s string) mock.IPackage {
|
||||
return nil
|
||||
},
|
||||
LocalPackageFn: func(s string) mock.IPackage { return nil },
|
||||
InstalledRemotePackageNamesFn: func() []string { return []string{} },
|
||||
}
|
||||
|
||||
run := &runtime.Runtime{
|
||||
Cfg: &settings.Configuration{
|
||||
RemoveMake: "no",
|
||||
},
|
||||
Logger: newTestLogger(),
|
||||
CmdBuilder: cmdBuilder,
|
||||
VCSStore: &vcs.Mock{},
|
||||
AURClient: &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = handleCmd(context.Background(), run, cmdArgs, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
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, tmpDir1, "/testdir1") // replace the temp dir with a static path
|
||||
show = strings.ReplaceAll(show, tmpDir2, "/testdir2") // replace the temp dir with a static path
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
80
main.go
80
main.go
@ -6,19 +6,19 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/db/ialpm"
|
||||
"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/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
var (
|
||||
yayVersion = "12.0.0" // To be set by compiler.
|
||||
yayVersion = "12.0.4" // To be set by compiler.
|
||||
localePath = "/usr/share/locale" // To be set by compiler.
|
||||
)
|
||||
|
||||
@ -28,7 +28,12 @@ func initGotext() {
|
||||
}
|
||||
|
||||
if lc := os.Getenv("LANGUAGE"); lc != "" {
|
||||
gotext.Configure(localePath, lc, "yay")
|
||||
// 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 != "" {
|
||||
@ -39,6 +44,7 @@ func initGotext() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
fallbackLog := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, false, "fallback")
|
||||
var (
|
||||
err error
|
||||
ctx = context.Background()
|
||||
@ -47,8 +53,9 @@ func main() {
|
||||
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
text.Errorln(rec)
|
||||
debug.PrintStack()
|
||||
fallbackLog.Errorln("Panic occurred:", rec)
|
||||
fallbackLog.Errorln("Stack trace:", string(debug.Stack()))
|
||||
ret = 1
|
||||
}
|
||||
|
||||
os.Exit(ret)
|
||||
@ -57,15 +64,15 @@ func main() {
|
||||
initGotext()
|
||||
|
||||
if os.Geteuid() == 0 {
|
||||
text.Warnln(gotext.Get("Avoid running yay as root/sudo."))
|
||||
fallbackLog.Warnln(gotext.Get("Avoid running yay as root/sudo."))
|
||||
}
|
||||
|
||||
configPath := settings.GetConfigPath()
|
||||
// Parse config
|
||||
cfg, err := settings.NewConfig(configPath, yayVersion)
|
||||
cfg, err := settings.NewConfig(fallbackLog, configPath, yayVersion)
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
text.Errorln(str)
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
@ -73,13 +80,9 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.Debug {
|
||||
text.GlobalLogger.Debug = true
|
||||
}
|
||||
|
||||
if errS := cfg.RunMigrations(
|
||||
if errS := cfg.RunMigrations(fallbackLog,
|
||||
settings.DefaultMigrations(), configPath, yayVersion); errS != nil {
|
||||
text.Errorln(errS)
|
||||
fallbackLog.Errorln(errS)
|
||||
}
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
@ -87,7 +90,7 @@ func main() {
|
||||
// Parse command line
|
||||
if err = cfg.ParseCommandLine(cmdArgs); err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
text.Errorln(str)
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
@ -97,15 +100,15 @@ func main() {
|
||||
|
||||
if cfg.SaveConfig {
|
||||
if errS := cfg.Save(configPath, yayVersion); errS != nil {
|
||||
text.Errorln(errS)
|
||||
fallbackLog.Errorln(errS)
|
||||
}
|
||||
}
|
||||
|
||||
// Build runtime
|
||||
runtime, err := settings.BuildRuntime(cfg, cmdArgs, yayVersion)
|
||||
// Build run
|
||||
run, err := runtime.NewRuntime(cfg, cmdArgs, yayVersion)
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
text.Errorln(str)
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
@ -113,35 +116,10 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
cfg.Runtime = runtime
|
||||
|
||||
cfg.Runtime.QueryBuilder = query.NewSourceQueryBuilder(
|
||||
cfg.Runtime.AURCache,
|
||||
cfg.Runtime.Logger.Child("mixed.querybuilder"), cfg.SortBy,
|
||||
cfg.Mode, cfg.SearchBy,
|
||||
cfg.BottomUp, cfg.SingleLineResults, cfg.SeparateSources)
|
||||
|
||||
var useColor bool
|
||||
|
||||
cfg.Runtime.PacmanConf, useColor, err = settings.RetrievePacmanConfig(cmdArgs, cfg.PacmanConf)
|
||||
dbExecutor, err := ialpm.NewExecutor(run.PacmanConf, run.Logger.Child("db"))
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
text.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
cfg.Runtime.CmdBuilder.SetPacmanDBPath(cfg.Runtime.PacmanConf.DBPath)
|
||||
|
||||
text.UseColor = useColor
|
||||
|
||||
dbExecutor, err := ialpm.NewExecutor(cfg.Runtime.PacmanConf, runtime.Logger.Child("db"))
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
text.Errorln(str)
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
ret = 1
|
||||
@ -151,16 +129,16 @@ func main() {
|
||||
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
text.Errorln(rec)
|
||||
debug.PrintStack()
|
||||
fallbackLog.Errorln("Panic occurred in DB operation:", rec)
|
||||
fallbackLog.Errorln("Stack trace:", string(debug.Stack()))
|
||||
}
|
||||
|
||||
dbExecutor.Cleanup()
|
||||
}()
|
||||
|
||||
if err = handleCmd(ctx, cfg, cmdArgs, db.Executor(dbExecutor)); err != nil {
|
||||
if err = handleCmd(ctx, run, cmdArgs, dbExecutor); err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
text.Errorln(str)
|
||||
fallbackLog.Errorln(str)
|
||||
}
|
||||
|
||||
exitError := &exec.ExitError{}
|
||||
|
@ -2,59 +2,61 @@ 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"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func handleCmd() error {
|
||||
config, err := settings.NewConfig(settings.GetConfigPath(), "")
|
||||
func handleCmd(logger *text.Logger) error {
|
||||
cfg, err := settings.NewConfig(logger, settings.GetConfigPath(), "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
if errP := config.ParseCommandLine(cmdArgs); errP != nil {
|
||||
if errP := cfg.ParseCommandLine(cmdArgs); errP != nil {
|
||||
return errP
|
||||
}
|
||||
|
||||
pacmanConf, _, err := settings.RetrievePacmanConfig(cmdArgs, config.PacmanConf)
|
||||
run, err := runtime.NewRuntime(cfg, cmdArgs, "1.0.0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbExecutor, err := ialpm.NewExecutor(pacmanConf, text.GlobalLogger)
|
||||
dbExecutor, err := ialpm.NewExecutor(run.PacmanConf, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aurCache, err := metadata.New(
|
||||
metadata.WithCacheFilePath(
|
||||
filepath.Join(config.BuildDir, "aur.json")))
|
||||
filepath.Join(cfg.BuildDir, "aur.json")))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
|
||||
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,
|
||||
config.Runtime.Logger.Child("grapher"))
|
||||
run.Logger.Child("grapher"))
|
||||
|
||||
return graphPackage(context.Background(), grapher, cmdArgs.Targets)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := handleCmd(); err != nil {
|
||||
text.Errorln(err)
|
||||
fallbackLog := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, false, "fallback")
|
||||
if err := handleCmd(fallbackLog); err != nil {
|
||||
fallbackLog.Errorln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func createAURList(ctx context.Context, client httpRequestDoer, aurURL string, o
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreatePackageList appends Repo packages to completion cache.
|
||||
// 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")
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package completion
|
||||
|
||||
import (
|
||||
|
@ -26,6 +26,7 @@ type Upgrade struct {
|
||||
LocalVersion string
|
||||
RemoteVersion string
|
||||
Reason alpm.PkgReason
|
||||
Extra string // Extra information to be displayed
|
||||
}
|
||||
|
||||
type SyncUpgrade struct {
|
||||
@ -46,18 +47,19 @@ type Executor interface {
|
||||
LocalPackage(string) IPackage
|
||||
LocalPackages() []IPackage
|
||||
LocalSatisfierExists(string) bool
|
||||
PackageConflicts(IPackage) []Depend
|
||||
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
|
||||
SatisfierFromDB(string, string) (IPackage, error)
|
||||
SyncPackage(string) IPackage
|
||||
SyncPackageFromDB(string, string) IPackage
|
||||
SyncPackages(...string) []IPackage
|
||||
SyncSatisfier(string) IPackage
|
||||
SyncSatisfierExists(string) bool
|
||||
|
@ -38,7 +38,7 @@ func NewExecutor(pacmanConf *pacmanconf.Config, logger *text.Logger) (*AlpmExecu
|
||||
conf: pacmanConf,
|
||||
log: logger,
|
||||
installedRemotePkgNames: nil,
|
||||
installedRemotePkgMap: map[string]alpm.IPackage{},
|
||||
installedRemotePkgMap: nil,
|
||||
installedSyncPkgNames: nil,
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ func (ae *AlpmExecutor) questionCallback() func(question alpm.QuestionAny) {
|
||||
return nil
|
||||
})
|
||||
|
||||
str := text.Bold(gotext.Get("There are %d providers available for %s:", size, qp.Dep()))
|
||||
str := text.Bold(gotext.Get("There are %[1]d providers available for %[2]s:", size, qp.Dep()))
|
||||
|
||||
size = 1
|
||||
|
||||
@ -311,6 +311,22 @@ func (ae *AlpmExecutor) PackagesFromGroup(groupName string) []alpm.IPackage {
|
||||
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 {
|
||||
@ -369,18 +385,27 @@ func (ae *AlpmExecutor) SyncPackage(pkgName string) alpm.IPackage {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SatisfierFromDB(pkgName, dbName string) alpm.IPackage {
|
||||
func (ae *AlpmExecutor) SyncPackageFromDB(pkgName, dbName string) alpm.IPackage {
|
||||
singleDB, err := ae.handle.SyncDBByName(dbName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
foundPkg, err := singleDB.PkgCache().FindSatisfier(pkgName)
|
||||
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
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return foundPkg
|
||||
foundPkg, err := singleDBList.FindSatisfier(pkgName)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return foundPkg, nil
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageDepends(pkg alpm.IPackage) []alpm.Depend {
|
||||
@ -398,11 +423,6 @@ func (ae *AlpmExecutor) PackageProvides(pkg alpm.IPackage) []alpm.Depend {
|
||||
return alpmPackage.Provides().Slice()
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageConflicts(pkg alpm.IPackage) []alpm.Depend {
|
||||
alpmPackage := pkg.(*alpm.Package)
|
||||
return alpmPackage.Conflicts().Slice()
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) PackageGroups(pkg alpm.IPackage) []string {
|
||||
alpmPackage := pkg.(*alpm.Package)
|
||||
return alpmPackage.Groups().Slice()
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package ialpm
|
||||
|
||||
import (
|
||||
@ -45,7 +48,7 @@ func TestAlpmExecutor(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
aExec, err := NewExecutor(pacmanConf, text.NewLogger(io.Discard, strings.NewReader(""), false, "test"))
|
||||
aExec, err := NewExecutor(pacmanConf, text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), false, "test"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, aExec.conf)
|
||||
|
@ -8,6 +8,9 @@ import (
|
||||
|
||||
// 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 {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
@ -27,11 +28,15 @@ type DBExecutor struct {
|
||||
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 {
|
||||
@ -137,6 +142,13 @@ func (t *DBExecutor) PackagesFromGroup(s string) []IPackage {
|
||||
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()
|
||||
@ -158,7 +170,10 @@ func (t *DBExecutor) Repos() []string {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SatisfierFromDB(s, s2 string) IPackage {
|
||||
func (t *DBExecutor) SatisfierFromDB(s, s2 string) (IPackage, error) {
|
||||
if t.SatisfierFromDBFn != nil {
|
||||
return t.SatisfierFromDBFn(s, s2)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@ -170,6 +185,9 @@ func (t *DBExecutor) SyncPackage(s string) IPackage {
|
||||
}
|
||||
|
||||
func (t *DBExecutor) SyncPackages(s ...string) []IPackage {
|
||||
if t.SyncPackagesFn != nil {
|
||||
return t.SyncPackagesFn(s...)
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@ -181,5 +199,16 @@ func (t *DBExecutor) SyncSatisfier(s string) IPackage {
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ type Package struct {
|
||||
PVersion string
|
||||
PReason alpm.PkgReason
|
||||
PDepends alpm.IDependList
|
||||
PProvides alpm.IDependList
|
||||
}
|
||||
|
||||
func (p *Package) Base() string {
|
||||
@ -172,7 +173,10 @@ func (p *Package) Packager() string {
|
||||
|
||||
// Provides returns DependList of packages provides by package.
|
||||
func (p *Package) Provides() alpm.IDependList {
|
||||
return alpm.DependList{}
|
||||
if p.PProvides == nil {
|
||||
return alpm.DependList{}
|
||||
}
|
||||
return p.PProvides
|
||||
}
|
||||
|
||||
// Origin returns package origin.
|
||||
|
@ -1,69 +0,0 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
aur "github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
)
|
||||
|
||||
// Base is an AUR base package.
|
||||
type Base []*aur.Pkg
|
||||
|
||||
// Pkgbase returns the first base package.
|
||||
func (b Base) Pkgbase() string {
|
||||
return b[0].PackageBase
|
||||
}
|
||||
|
||||
// Version returns the first base package version.
|
||||
func (b Base) Version() string {
|
||||
return b[0].Version
|
||||
}
|
||||
|
||||
// URLPath returns the first base package URL.
|
||||
func (b Base) URLPath() string {
|
||||
return b[0].URLPath
|
||||
}
|
||||
|
||||
func (b Base) AnyIsInSet(set stringset.StringSet) bool {
|
||||
for _, pkg := range b {
|
||||
if set.Get(pkg.Name) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Packages foo and bar from a pkgbase named base would print like so:
|
||||
// base (foo bar).
|
||||
func (b Base) String() string {
|
||||
pkg := b[0]
|
||||
str := pkg.PackageBase
|
||||
|
||||
if len(b) > 1 || pkg.PackageBase != pkg.Name {
|
||||
str2 := " ("
|
||||
for _, split := range b {
|
||||
str2 += split.Name + " "
|
||||
}
|
||||
|
||||
str2 = str2[:len(str2)-1] + ")"
|
||||
|
||||
str += str2
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func GetBases(pkgs []aur.Pkg) []Base {
|
||||
basesMap := make(map[string]Base)
|
||||
for i := range pkgs {
|
||||
pkg := &pkgs[i]
|
||||
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
|
||||
}
|
||||
|
||||
bases := make([]Base, 0, len(basesMap))
|
||||
for _, base := range basesMap {
|
||||
bases = append(bases, base)
|
||||
}
|
||||
|
||||
return bases
|
||||
}
|
@ -5,41 +5,8 @@ import (
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
aur "github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type providers struct {
|
||||
lookfor string
|
||||
Pkgs []*aur.Pkg
|
||||
}
|
||||
|
||||
func makeProviders(name string) providers {
|
||||
return providers{
|
||||
name,
|
||||
make([]*aur.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 text.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) (pkg, mod, ver string) {
|
||||
split := strings.FieldsFunc(dep, func(c rune) bool {
|
||||
match := c == '>' || c == '<' || c == '='
|
||||
@ -118,17 +85,3 @@ func satisfiesAur(dep string, pkg *aur.Pkg) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func satisfiesRepo(dep string, pkg db.IPackage, dbExecutor db.Executor) bool {
|
||||
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, provided := range dbExecutor.PackageProvides(pkg) {
|
||||
if provideSatisfies(provided.String(), dep, pkg.Version()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -1,324 +0,0 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func (dp *Pool) checkInnerConflict(name, conflict string, conflicts stringset.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, dp.AlpmExecutor) {
|
||||
conflicts.Add(name, pkg.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *Pool) checkForwardConflict(name, conflict string, conflicts stringset.MapStringSet) {
|
||||
for _, pkg := range dp.AlpmExecutor.LocalPackages() {
|
||||
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if satisfiesRepo(conflict, pkg, dp.AlpmExecutor) {
|
||||
n := pkg.Name()
|
||||
if n != conflict {
|
||||
n += " (" + conflict + ")"
|
||||
}
|
||||
|
||||
conflicts.Add(name, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *Pool) checkReverseConflict(name, conflict string, conflicts stringset.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, dp.AlpmExecutor) {
|
||||
if name != conflict {
|
||||
name += " (" + conflict + ")"
|
||||
}
|
||||
|
||||
conflicts.Add(pkg.Name(), name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *Pool) checkInnerConflicts(conflicts stringset.MapStringSet) {
|
||||
for _, pkg := range dp.Aur {
|
||||
for _, conflict := range pkg.Conflicts {
|
||||
dp.checkInnerConflict(pkg.Name, conflict, conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Repo {
|
||||
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
||||
dp.checkInnerConflict(pkg.Name(), conflict.String(), conflicts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *Pool) checkForwardConflicts(conflicts stringset.MapStringSet) {
|
||||
for _, pkg := range dp.Aur {
|
||||
for _, conflict := range pkg.Conflicts {
|
||||
dp.checkForwardConflict(pkg.Name, conflict, conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range dp.Repo {
|
||||
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
||||
dp.checkForwardConflict(pkg.Name(), conflict.String(), conflicts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *Pool) checkReverseConflicts(conflicts stringset.MapStringSet) {
|
||||
for _, pkg := range dp.AlpmExecutor.LocalPackages() {
|
||||
if dp.hasPackage(pkg.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, conflict := range dp.AlpmExecutor.PackageConflicts(pkg) {
|
||||
dp.checkReverseConflict(pkg.Name(), conflict.String(), conflicts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *Pool) CheckConflicts(useAsk, noConfirm, noDeps bool) (stringset.MapStringSet, error) {
|
||||
conflicts := make(stringset.MapStringSet)
|
||||
if noDeps {
|
||||
return conflicts, nil
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
innerConflicts := make(stringset.MapStringSet)
|
||||
|
||||
wg.Add(2)
|
||||
|
||||
text.OperationInfoln(gotext.Get("Checking for conflicts..."))
|
||||
|
||||
go func() {
|
||||
dp.checkForwardConflicts(conflicts)
|
||||
dp.checkReverseConflicts(conflicts)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
text.OperationInfoln(gotext.Get("Checking for inner conflicts..."))
|
||||
|
||||
go func() {
|
||||
dp.checkInnerConflicts(innerConflicts)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if len(innerConflicts) != 0 {
|
||||
text.Errorln(gotext.Get("Inner conflicts found:"))
|
||||
|
||||
for name, pkgs := range innerConflicts {
|
||||
str := text.SprintError(name + ":")
|
||||
for pkg := range pkgs {
|
||||
str += " " + text.Cyan(pkg) + ","
|
||||
}
|
||||
|
||||
str = strings.TrimSuffix(str, ",")
|
||||
|
||||
fmt.Println(str)
|
||||
}
|
||||
}
|
||||
|
||||
if len(conflicts) != 0 {
|
||||
text.Errorln(gotext.Get("Package conflicts found:"))
|
||||
|
||||
for name, pkgs := range conflicts {
|
||||
str := text.SprintError(gotext.Get("Installing %s will remove:", text.Cyan(name)))
|
||||
for pkg := range pkgs {
|
||||
str += " " + text.Cyan(pkg) + ","
|
||||
}
|
||||
|
||||
str = strings.TrimSuffix(str, ",")
|
||||
|
||||
fmt.Println(str)
|
||||
}
|
||||
}
|
||||
|
||||
// Add the inner conflicts to the conflicts
|
||||
// These are used to decide what to pass --ask to (if set) or don't pass --noconfirm to
|
||||
// As we have no idea what the order is yet we add every inner conflict to the slice
|
||||
for name, pkgs := range innerConflicts {
|
||||
conflicts[name] = make(stringset.StringSet)
|
||||
for pkg := range pkgs {
|
||||
conflicts[pkg] = make(stringset.StringSet)
|
||||
}
|
||||
}
|
||||
|
||||
if len(conflicts) > 0 {
|
||||
if !useAsk {
|
||||
if noConfirm {
|
||||
return nil, errors.New(gotext.Get("package conflicts can not be resolved with noconfirm, aborting"))
|
||||
}
|
||||
|
||||
text.Errorln(gotext.Get("Conflicting packages will have to be confirmed manually"))
|
||||
}
|
||||
}
|
||||
|
||||
return conflicts, nil
|
||||
}
|
||||
|
||||
type missing struct {
|
||||
Good stringset.StringSet
|
||||
Missing map[string][][]string
|
||||
}
|
||||
|
||||
func (dp *Pool) _checkMissing(dep string, stack []string, missing *missing, noDeps, noCheckDeps bool) {
|
||||
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
|
||||
}
|
||||
|
||||
if aurPkg := dp.findSatisfierAur(dep); aurPkg != nil {
|
||||
missing.Good.Set(dep)
|
||||
|
||||
combinedDepList := ComputeCombinedDepList(aurPkg, noDeps, noCheckDeps)
|
||||
for _, aurDep := range combinedDepList {
|
||||
if dp.AlpmExecutor.LocalSatisfierExists(aurDep) {
|
||||
missing.Good.Set(aurDep)
|
||||
continue
|
||||
}
|
||||
|
||||
dp._checkMissing(aurDep, append(stack, aurPkg.Name), missing, noDeps, noCheckDeps)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if repoPkg := dp.findSatisfierRepo(dep); repoPkg != nil {
|
||||
missing.Good.Set(dep)
|
||||
|
||||
if noDeps {
|
||||
return
|
||||
}
|
||||
|
||||
for _, dep := range dp.AlpmExecutor.PackageDepends(repoPkg) {
|
||||
if dp.AlpmExecutor.LocalSatisfierExists(dep.String()) {
|
||||
missing.Good.Set(dep.String())
|
||||
continue
|
||||
}
|
||||
|
||||
dp._checkMissing(dep.String(), append(stack, repoPkg.Name()), missing, noDeps, noCheckDeps)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
missing.Missing[dep] = [][]string{stack}
|
||||
}
|
||||
|
||||
func stringSliceEqual(a, b []string) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (dp *Pool) CheckMissing(noDeps, noCheckDeps bool) error {
|
||||
missing := &missing{
|
||||
make(stringset.StringSet),
|
||||
make(map[string][][]string),
|
||||
}
|
||||
|
||||
for _, target := range dp.Targets {
|
||||
dp._checkMissing(target.DepString(), make([]string, 0), missing, noDeps, noCheckDeps)
|
||||
}
|
||||
|
||||
if len(missing.Missing) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
text.Errorln(gotext.Get("could not find all required packages:"))
|
||||
|
||||
for dep, trees := range missing.Missing {
|
||||
for _, tree := range trees {
|
||||
fmt.Fprintf(os.Stderr, "\t%s", text.Cyan(dep))
|
||||
|
||||
if len(tree) == 0 {
|
||||
fmt.Fprint(os.Stderr, gotext.Get(" (Target"))
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, gotext.Get(" (Wanted by: "))
|
||||
for n := 0; n < len(tree)-1; n++ {
|
||||
fmt.Fprint(os.Stderr, text.Cyan(tree[n]), " -> ")
|
||||
}
|
||||
fmt.Fprint(os.Stderr, text.Cyan(tree[len(tree)-1]))
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, ")")
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("")
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
aur "github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
Aur []Base
|
||||
Repo []db.IPackage
|
||||
Runtime stringset.StringSet
|
||||
}
|
||||
|
||||
func newOrder() *Order {
|
||||
return &Order{
|
||||
make([]Base, 0),
|
||||
make([]db.IPackage, 0),
|
||||
make(stringset.StringSet),
|
||||
}
|
||||
}
|
||||
|
||||
func GetOrder(dp *Pool, noDeps, noCheckDeps bool) *Order {
|
||||
do := newOrder()
|
||||
|
||||
for _, target := range dp.Targets {
|
||||
dep := target.DepString()
|
||||
|
||||
if aurPkg := dp.Aur[dep]; aurPkg != nil && pkgSatisfies(aurPkg.Name, aurPkg.Version, dep) {
|
||||
do.orderPkgAur(aurPkg, dp, true, noDeps, noCheckDeps)
|
||||
} else if aurPkg := dp.findSatisfierAur(dep); aurPkg != nil {
|
||||
do.orderPkgAur(aurPkg, dp, true, noDeps, noCheckDeps)
|
||||
} else if repoPkg := dp.findSatisfierRepo(dep); repoPkg != nil {
|
||||
do.orderPkgRepo(repoPkg, dp, true)
|
||||
}
|
||||
}
|
||||
|
||||
return do
|
||||
}
|
||||
|
||||
func (do *Order) orderPkgAur(pkg *aur.Pkg, dp *Pool, runtime, noDeps, noCheckDeps bool) {
|
||||
if runtime {
|
||||
do.Runtime.Set(pkg.Name)
|
||||
}
|
||||
|
||||
delete(dp.Aur, pkg.Name)
|
||||
|
||||
for i, dep := range ComputeCombinedDepList(pkg, noDeps, noCheckDeps) {
|
||||
if aurPkg := dp.findSatisfierAur(dep); aurPkg != nil {
|
||||
do.orderPkgAur(aurPkg, dp, runtime && i == 0, noDeps, noCheckDeps)
|
||||
}
|
||||
|
||||
if repoPkg := dp.findSatisfierRepo(dep); 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 *Order) orderPkgRepo(pkg db.IPackage, dp *Pool, runtime bool) {
|
||||
if runtime {
|
||||
do.Runtime.Set(pkg.Name())
|
||||
}
|
||||
|
||||
delete(dp.Repo, pkg.Name())
|
||||
|
||||
for _, dep := range dp.AlpmExecutor.PackageDepends(pkg) {
|
||||
if repoPkg := dp.findSatisfierRepo(dep.String()); repoPkg != nil {
|
||||
do.orderPkgRepo(repoPkg, dp, runtime)
|
||||
}
|
||||
}
|
||||
|
||||
do.Repo = append(do.Repo, pkg)
|
||||
}
|
||||
|
||||
func (do *Order) HasMake() bool {
|
||||
lenAur := 0
|
||||
for _, base := range do.Aur {
|
||||
lenAur += len(base)
|
||||
}
|
||||
|
||||
return len(do.Runtime) != lenAur+len(do.Repo)
|
||||
}
|
||||
|
||||
func (do *Order) GetMake() []string {
|
||||
makeOnly := []string{}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Print prints repository packages to be downloaded.
|
||||
func (do *Order) Print() {
|
||||
repo := ""
|
||||
repoMake := ""
|
||||
aurString := ""
|
||||
aurMake := ""
|
||||
|
||||
repoLen := 0
|
||||
repoMakeLen := 0
|
||||
aurLen := 0
|
||||
aurMakeLen := 0
|
||||
|
||||
for _, pkg := range do.Repo {
|
||||
pkgStr := fmt.Sprintf(" %s-%s", pkg.Name(), pkg.Version())
|
||||
if do.Runtime.Get(pkg.Name()) {
|
||||
repo += pkgStr
|
||||
repoLen++
|
||||
} else {
|
||||
repoMake += pkgStr
|
||||
repoMakeLen++
|
||||
}
|
||||
}
|
||||
|
||||
for _, base := range do.Aur {
|
||||
pkg := base.Pkgbase()
|
||||
pkgStr := " " + pkg + "-" + base[0].Version
|
||||
pkgStrMake := pkgStr
|
||||
|
||||
push := false
|
||||
pushMake := false
|
||||
|
||||
switch {
|
||||
case len(base) > 1, pkg != base[0].Name:
|
||||
pkgStr += " ("
|
||||
pkgStrMake += " ("
|
||||
|
||||
for _, split := range base {
|
||||
if do.Runtime.Get(split.Name) {
|
||||
pkgStr += split.Name + " "
|
||||
aurLen++
|
||||
|
||||
push = true
|
||||
} else {
|
||||
pkgStrMake += split.Name + " "
|
||||
aurMakeLen++
|
||||
pushMake = true
|
||||
}
|
||||
}
|
||||
|
||||
pkgStr = pkgStr[:len(pkgStr)-1] + ")"
|
||||
pkgStrMake = pkgStrMake[:len(pkgStrMake)-1] + ")"
|
||||
case do.Runtime.Get(base[0].Name):
|
||||
aurLen++
|
||||
|
||||
push = true
|
||||
default:
|
||||
aurMakeLen++
|
||||
|
||||
pushMake = true
|
||||
}
|
||||
|
||||
if push {
|
||||
aurString += pkgStr
|
||||
}
|
||||
|
||||
if pushMake {
|
||||
aurMake += pkgStrMake
|
||||
}
|
||||
}
|
||||
|
||||
printDownloads("Repo", repoLen, repo)
|
||||
printDownloads("Repo Make", repoMakeLen, repoMake)
|
||||
printDownloads("Aur", aurLen, aurString)
|
||||
printDownloads("Aur Make", aurMakeLen, aurMake)
|
||||
}
|
||||
|
||||
func printDownloads(repoName string, length int, packages string) {
|
||||
if length < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
repoInfo := fmt.Sprintf(text.Bold(text.Blue("[%s:%d]")), repoName, length)
|
||||
fmt.Println(repoInfo + text.Cyan(packages))
|
||||
}
|
@ -1,546 +0,0 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/aur/rpc"
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type Pool struct {
|
||||
Targets []Target
|
||||
Explicit stringset.StringSet
|
||||
Repo map[string]db.IPackage
|
||||
Aur map[string]*query.Pkg
|
||||
AurCache map[string]*query.Pkg
|
||||
Groups []string
|
||||
AlpmExecutor db.Executor
|
||||
Warnings *query.AURWarnings
|
||||
aurClient rpc.ClientInterface
|
||||
}
|
||||
|
||||
func newPool(dbExecutor db.Executor, aurClient rpc.ClientInterface) *Pool {
|
||||
dp := &Pool{
|
||||
Targets: []Target{},
|
||||
Explicit: map[string]struct{}{},
|
||||
Repo: map[string]alpm.IPackage{},
|
||||
Aur: map[string]*aur.Pkg{},
|
||||
AurCache: map[string]*aur.Pkg{},
|
||||
Groups: []string{},
|
||||
AlpmExecutor: dbExecutor,
|
||||
Warnings: nil,
|
||||
aurClient: aurClient,
|
||||
}
|
||||
|
||||
return dp
|
||||
}
|
||||
|
||||
// Includes db/ prefixes and group installs.
|
||||
func (dp *Pool) ResolveTargets(ctx context.Context, pkgs []string,
|
||||
mode parser.TargetMode,
|
||||
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int, noDeps, noCheckDeps bool, assumeInstalled []string,
|
||||
) error {
|
||||
// RPC requests are slow
|
||||
// Combine as many AUR package requests as possible into a single RPC call
|
||||
aurTargets := make(stringset.StringSet)
|
||||
|
||||
pkgs = query.RemoveInvalidTargets(pkgs, mode)
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
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()) || isInAssumeInstalled(target.DepString(), assumeInstalled) {
|
||||
continue
|
||||
}
|
||||
|
||||
var foundPkg db.IPackage
|
||||
|
||||
// aur/ prefix means we only check the aur
|
||||
if target.DB == "aur" || mode == parser.ModeAUR {
|
||||
dp.Targets = append(dp.Targets, target)
|
||||
aurTargets.Set(target.DepString())
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
// If there's a different prefix only look in that repo
|
||||
if target.DB != "" {
|
||||
foundPkg = dp.AlpmExecutor.SatisfierFromDB(target.DepString(), target.DB)
|
||||
} else {
|
||||
// otherwise find it in any repo
|
||||
foundPkg = dp.AlpmExecutor.SyncSatisfier(target.DepString())
|
||||
}
|
||||
|
||||
if foundPkg != nil {
|
||||
dp.Targets = append(dp.Targets, target)
|
||||
dp.Explicit.Set(foundPkg.Name())
|
||||
dp.ResolveRepoDependency(foundPkg, noDeps)
|
||||
|
||||
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
|
||||
groupPackages := dp.AlpmExecutor.PackagesFromGroup(target.Name)
|
||||
if len(groupPackages) > 0 {
|
||||
dp.Groups = append(dp.Groups, target.String())
|
||||
for _, pkg := range groupPackages {
|
||||
dp.Explicit.Set(pkg.Name())
|
||||
}
|
||||
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.AtLeastAUR() {
|
||||
return dp.resolveAURPackages(ctx, aurTargets, true, ignoreProviders,
|
||||
noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
|
||||
}
|
||||
|
||||
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 *Pool) findProvides(ctx context.Context, pkgs stringset.StringSet) error {
|
||||
var (
|
||||
mux sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
doSearch := func(pkg string) {
|
||||
defer wg.Done()
|
||||
|
||||
var (
|
||||
err error
|
||||
results []query.Pkg
|
||||
)
|
||||
|
||||
results, err = dp.aurClient.Search(ctx, pkg, aur.Provides)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for iR := range results {
|
||||
mux.Lock()
|
||||
if _, ok := dp.AurCache[results[iR].Name]; !ok {
|
||||
pkgs.Set(results[iR].Name)
|
||||
}
|
||||
mux.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
for pkg := range pkgs {
|
||||
if dp.AlpmExecutor.LocalPackage(pkg) != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
text.Debugln("AUR RPC Search:", pkg)
|
||||
|
||||
go doSearch(pkg)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *Pool) cacheAURPackages(ctx context.Context, _pkgs stringset.StringSet, provides bool, splitN int) error {
|
||||
pkgs := _pkgs.Copy()
|
||||
toQuery := make([]string, 0)
|
||||
|
||||
for pkg := range pkgs {
|
||||
if _, ok := dp.AurCache[pkg]; ok {
|
||||
pkgs.Remove(pkg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if provides {
|
||||
err := dp.findProvides(ctx, pkgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for pkg := range pkgs {
|
||||
if _, ok := dp.AurCache[pkg]; !ok {
|
||||
name, _, ver := splitDep(pkg)
|
||||
if ver != "" {
|
||||
toQuery = append(toQuery, name, name+"-"+ver)
|
||||
} else {
|
||||
toQuery = append(toQuery, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info, err := query.AURInfo(ctx, dp.aurClient, toQuery, dp.Warnings, splitN)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range info {
|
||||
// Dump everything in cache just in case we need it later
|
||||
pkg := &info[i]
|
||||
dp.AurCache[pkg.Name] = pkg
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compute dependency lists used in Package dep searching and ordering.
|
||||
// Order sensitive TOFIX.
|
||||
func ComputeCombinedDepList(pkg *aur.Pkg, noDeps, noCheckDeps bool) []string {
|
||||
combinedDepList := make([]string, 0, len(pkg.Depends)+len(pkg.MakeDepends)+len(pkg.CheckDepends))
|
||||
|
||||
if !noDeps {
|
||||
combinedDepList = append(combinedDepList, pkg.Depends...)
|
||||
}
|
||||
|
||||
combinedDepList = append(combinedDepList, pkg.MakeDepends...)
|
||||
|
||||
if !noCheckDeps {
|
||||
combinedDepList = append(combinedDepList, pkg.CheckDepends...)
|
||||
}
|
||||
|
||||
return combinedDepList
|
||||
}
|
||||
|
||||
func (dp *Pool) resolveAURPackages(ctx context.Context,
|
||||
pkgs stringset.StringSet,
|
||||
explicit, ignoreProviders, noConfirm, provides bool,
|
||||
rebuild string, splitN int, noDeps, noCheckDeps bool,
|
||||
) error {
|
||||
newPackages := make(stringset.StringSet)
|
||||
newAURPackages := make(stringset.StringSet)
|
||||
|
||||
err := dp.cacheAURPackages(ctx, pkgs, provides, splitN)
|
||||
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, ignoreProviders, noConfirm, provides)
|
||||
if pkg == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if explicit {
|
||||
dp.Explicit.Set(pkg.Name)
|
||||
}
|
||||
|
||||
dp.Aur[pkg.Name] = pkg
|
||||
|
||||
combinedDepList := ComputeCombinedDepList(pkg, noDeps, noCheckDeps)
|
||||
for _, dep := range combinedDepList {
|
||||
newPackages.Set(dep)
|
||||
}
|
||||
}
|
||||
|
||||
for dep := range newPackages {
|
||||
if dp.hasSatisfier(dep) {
|
||||
continue
|
||||
}
|
||||
|
||||
isInstalled := dp.AlpmExecutor.LocalSatisfierExists(dep)
|
||||
hm := settings.HideMenus
|
||||
settings.HideMenus = isInstalled
|
||||
repoPkg := dp.AlpmExecutor.SyncSatisfier(dep) // has satisfier in repo: fetch it
|
||||
settings.HideMenus = hm
|
||||
|
||||
if isInstalled && (rebuild != "tree" || repoPkg != nil) {
|
||||
continue
|
||||
}
|
||||
|
||||
if repoPkg != nil {
|
||||
dp.ResolveRepoDependency(repoPkg, false)
|
||||
continue
|
||||
}
|
||||
|
||||
// assume it's in the aur
|
||||
// ditch the versioning because the RPC can't handle it
|
||||
newAURPackages.Set(dep)
|
||||
}
|
||||
|
||||
err = dp.resolveAURPackages(ctx, newAURPackages, false, ignoreProviders,
|
||||
noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (dp *Pool) ResolveRepoDependency(pkg db.IPackage, noDeps bool) {
|
||||
dp.Repo[pkg.Name()] = pkg
|
||||
|
||||
if noDeps {
|
||||
return
|
||||
}
|
||||
|
||||
for _, dep := range dp.AlpmExecutor.PackageDepends(pkg) {
|
||||
if dp.hasSatisfier(dep.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
// has satisfier installed: skip
|
||||
if dp.AlpmExecutor.LocalSatisfierExists(dep.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
// has satisfier in repo: fetch it
|
||||
if repoPkg := dp.AlpmExecutor.SyncSatisfier(dep.String()); repoPkg != nil {
|
||||
dp.ResolveRepoDependency(repoPkg, noDeps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetPool(ctx context.Context, pkgs []string,
|
||||
warnings *query.AURWarnings,
|
||||
dbExecutor db.Executor,
|
||||
aurClient rpc.ClientInterface,
|
||||
mode parser.TargetMode,
|
||||
ignoreProviders, noConfirm, provides bool,
|
||||
rebuild string, splitN int, noDeps bool, noCheckDeps bool, assumeInstalled []string,
|
||||
) (*Pool, error) {
|
||||
dp := newPool(dbExecutor, aurClient)
|
||||
|
||||
dp.Warnings = warnings
|
||||
err := dp.ResolveTargets(ctx, pkgs, mode, ignoreProviders, noConfirm, provides,
|
||||
rebuild, splitN, noDeps, noCheckDeps, assumeInstalled)
|
||||
|
||||
return dp, err
|
||||
}
|
||||
|
||||
func (dp *Pool) findSatisfierAur(dep string) *query.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 *Pool) findSatisfierAurCache(dep string, ignoreProviders, noConfirm, provides bool) *query.Pkg {
|
||||
depName, _, _ := splitDep(dep)
|
||||
seen := make(stringset.StringSet)
|
||||
providerSlice := makeProviders(depName)
|
||||
|
||||
if dp.AlpmExecutor.LocalPackage(depName) != nil {
|
||||
if pkg, ok := dp.AurCache[dep]; ok && pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
|
||||
if ignoreProviders {
|
||||
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) {
|
||||
providerSlice.Pkgs = append(providerSlice.Pkgs, pkg)
|
||||
seen.Set(pkg.Name)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
for _, provide := range pkg.Provides {
|
||||
if provideSatisfies(provide, dep, pkg.Version) {
|
||||
providerSlice.Pkgs = append(providerSlice.Pkgs, pkg)
|
||||
seen.Set(pkg.Name)
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !provides && providerSlice.Len() >= 1 {
|
||||
return providerSlice.Pkgs[0]
|
||||
}
|
||||
|
||||
if providerSlice.Len() == 1 {
|
||||
return providerSlice.Pkgs[0]
|
||||
}
|
||||
|
||||
if providerSlice.Len() > 1 {
|
||||
sort.Sort(providerSlice)
|
||||
return providerMenu(dep, providerSlice, noConfirm)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *Pool) findSatisfierRepo(dep string) db.IPackage {
|
||||
for _, pkg := range dp.Repo {
|
||||
if satisfiesRepo(dep, pkg, dp.AlpmExecutor) {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dp *Pool) hasSatisfier(dep string) bool {
|
||||
return dp.findSatisfierRepo(dep) != nil || dp.findSatisfierAur(dep) != nil
|
||||
}
|
||||
|
||||
func (dp *Pool) 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
|
||||
}
|
||||
|
||||
func isInAssumeInstalled(name string, assumeInstalled []string) bool {
|
||||
for _, pkgAndVersion := range assumeInstalled {
|
||||
assumeName, _, _ := splitDep(pkgAndVersion)
|
||||
|
||||
depName, _, _ := splitDep(name)
|
||||
if assumeName == depName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func providerMenu(dep string, providers providers, noConfirm bool) *query.Pkg {
|
||||
size := providers.Len()
|
||||
|
||||
str := text.Bold(gotext.Get("There are %d providers available for %s:", size, dep))
|
||||
str += "\n"
|
||||
|
||||
size = 1
|
||||
str += text.SprintOperationInfo(gotext.Get("Repository AUR"), "\n ")
|
||||
|
||||
for _, pkg := range providers.Pkgs {
|
||||
str += fmt.Sprintf("%d) %s ", size, pkg.Name)
|
||||
size++
|
||||
}
|
||||
|
||||
text.OperationInfoln(str)
|
||||
|
||||
for {
|
||||
fmt.Println(gotext.Get("\nEnter a number (default=1): "))
|
||||
|
||||
if noConfirm {
|
||||
fmt.Println("1")
|
||||
return providers.Pkgs[0]
|
||||
}
|
||||
|
||||
numberBuf, err := text.GetInput(os.Stdin, "", false)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if numberBuf == "" {
|
||||
return providers.Pkgs[0]
|
||||
}
|
||||
|
||||
num, err := strconv.Atoi(numberBuf)
|
||||
if err != nil {
|
||||
text.Errorln(gotext.Get("invalid number: %s", numberBuf))
|
||||
continue
|
||||
}
|
||||
|
||||
if num < 1 || num >= size {
|
||||
text.Errorln(gotext.Get("invalid value: %d is not between %d and %d", num, 1, size-1))
|
||||
continue
|
||||
}
|
||||
|
||||
return providers.Pkgs[num-1]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -12,10 +12,10 @@ import (
|
||||
"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"
|
||||
"github.com/Jguer/yay/v12/pkg/topo"
|
||||
)
|
||||
|
||||
type InstallInfo struct {
|
||||
@ -27,6 +27,7 @@ type InstallInfo struct {
|
||||
AURBase *string
|
||||
SyncDBName *string
|
||||
|
||||
IsGroup bool
|
||||
Upgrade bool
|
||||
Devel bool
|
||||
}
|
||||
@ -36,7 +37,7 @@ func (i *InstallInfo) String() string {
|
||||
}
|
||||
|
||||
type (
|
||||
Reason int
|
||||
Reason uint
|
||||
Source int
|
||||
)
|
||||
|
||||
@ -122,11 +123,15 @@ func NewGrapher(dbExecutor db.Executor, aurCache aurc.QueryClient,
|
||||
}
|
||||
}
|
||||
|
||||
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 = topo.New[string, *InstallInfo]()
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
aurTargets := make([]string, 0, len(targets))
|
||||
@ -137,25 +142,7 @@ func (g *Grapher) GraphFromTargets(ctx context.Context,
|
||||
switch target.DB {
|
||||
case "": // unspecified db
|
||||
if pkg := g.dbExecutor.SyncSatisfier(target.Name); pkg != nil {
|
||||
dbName := pkg.DB().Name()
|
||||
graph.AddNode(pkg.Name())
|
||||
g.ValidateAndSetNodeInfo(graph, pkg.Name(), &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[Explicit],
|
||||
Background: bgColorMap[Sync],
|
||||
Value: &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: pkg.Version(),
|
||||
SyncDBName: &dbName,
|
||||
},
|
||||
})
|
||||
|
||||
g.GraphSyncPkg(ctx, graph, pkg, &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: pkg.Version(),
|
||||
SyncDBName: &dbName,
|
||||
})
|
||||
g.GraphSyncPkg(ctx, graph, pkg, nil)
|
||||
|
||||
continue
|
||||
}
|
||||
@ -163,17 +150,7 @@ func (g *Grapher) GraphFromTargets(ctx context.Context,
|
||||
groupPackages := g.dbExecutor.PackagesFromGroup(target.Name)
|
||||
if len(groupPackages) > 0 {
|
||||
dbName := groupPackages[0].DB().Name()
|
||||
graph.AddNode(target.Name)
|
||||
g.ValidateAndSetNodeInfo(graph, target.Name, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[Explicit],
|
||||
Background: bgColorMap[Sync],
|
||||
Value: &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: "",
|
||||
SyncDBName: &dbName,
|
||||
},
|
||||
})
|
||||
g.GraphSyncGroup(ctx, graph, target.Name, dbName)
|
||||
|
||||
continue
|
||||
}
|
||||
@ -182,17 +159,26 @@ func (g *Grapher) GraphFromTargets(ctx context.Context,
|
||||
case "aur":
|
||||
aurTargets = append(aurTargets, target.Name)
|
||||
default:
|
||||
graph.AddNode(target.Name)
|
||||
g.ValidateAndSetNodeInfo(graph, target.Name, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[Explicit],
|
||||
Background: bgColorMap[Sync],
|
||||
Value: &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: target.Version,
|
||||
SyncDBName: &target.DB,
|
||||
},
|
||||
})
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,8 +191,8 @@ func (g *Grapher) GraphFromTargets(ctx context.Context,
|
||||
return graph, nil
|
||||
}
|
||||
|
||||
func (g *Grapher) pickSrcInfoPkgs(pkgs []aurc.Pkg) ([]aurc.Pkg, error) {
|
||||
final := make([]aurc.Pkg, 0, len(pkgs))
|
||||
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))
|
||||
@ -220,7 +206,7 @@ func (g *Grapher) pickSrcInfoPkgs(pkgs []aurc.Pkg) ([]aurc.Pkg, error) {
|
||||
}
|
||||
|
||||
include, exclude, _, otherExclude := intrange.ParseNumberMenu(numberBuf)
|
||||
isInclude := len(exclude) == 0 && len(otherExclude) == 0
|
||||
isInclude := len(exclude) == 0 && otherExclude.Cardinality() == 0
|
||||
|
||||
for i := 1; i <= len(pkgs); i++ {
|
||||
target := i - 1
|
||||
@ -237,48 +223,81 @@ func (g *Grapher) pickSrcInfoPkgs(pkgs []aurc.Pkg) ([]aurc.Pkg, error) {
|
||||
return final, nil
|
||||
}
|
||||
|
||||
func (g *Grapher) GraphFromSrcInfo(ctx context.Context, graph *topo.Graph[string, *InstallInfo], pkgBuildDir string,
|
||||
pkgbuild *gosrc.Srcinfo,
|
||||
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 = topo.New[string, *InstallInfo]()
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
aurPkgs, err := makeAURPKGFromSrcinfo(g.dbExecutor, pkgbuild)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aurPkgsAdded := []*aurc.Pkg{}
|
||||
for pkgBuildDir, pkgbuild := range srcInfos {
|
||||
pkgBuildDir := pkgBuildDir
|
||||
|
||||
if len(aurPkgs) > 1 {
|
||||
var errPick error
|
||||
aurPkgs, errPick = g.pickSrcInfoPkgs(aurPkgs)
|
||||
if errPick != nil {
|
||||
return nil, errPick
|
||||
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...)
|
||||
}
|
||||
|
||||
for i := range aurPkgs {
|
||||
pkg := &aurPkgs[i]
|
||||
|
||||
graph.AddNode(pkg.Name)
|
||||
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[Explicit],
|
||||
Background: bgColorMap[AUR],
|
||||
Value: &InstallInfo{
|
||||
Source: SrcInfo,
|
||||
Reason: Explicit,
|
||||
SrcinfoPath: &pkgBuildDir,
|
||||
AURBase: &pkg.PackageBase,
|
||||
Version: pkg.Version,
|
||||
},
|
||||
})
|
||||
|
||||
g.addDepNodes(ctx, pkg, graph)
|
||||
}
|
||||
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)
|
||||
@ -295,17 +314,66 @@ func (g *Grapher) addDepNodes(ctx context.Context, pkg *aur.Pkg, graph *topo.Gra
|
||||
|
||||
func (g *Grapher) GraphSyncPkg(ctx context.Context,
|
||||
graph *topo.Graph[string, *InstallInfo],
|
||||
pkg alpm.IPackage, instalInfo *InstallInfo,
|
||||
pkg alpm.IPackage, upgradeInfo *db.SyncUpgrade,
|
||||
) *topo.Graph[string, *InstallInfo] {
|
||||
if graph == nil {
|
||||
graph = topo.New[string, *InstallInfo]()
|
||||
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: instalInfo,
|
||||
Value: &InstallInfo{
|
||||
Source: Sync,
|
||||
Reason: Explicit,
|
||||
Version: "",
|
||||
SyncDBName: &dbName,
|
||||
IsGroup: true,
|
||||
},
|
||||
})
|
||||
|
||||
return graph
|
||||
@ -316,18 +384,19 @@ func (g *Grapher) GraphAURTarget(ctx context.Context,
|
||||
pkg *aurc.Pkg, instalInfo *InstallInfo,
|
||||
) *topo.Graph[string, *InstallInfo] {
|
||||
if graph == nil {
|
||||
graph = topo.New[string, *InstallInfo]()
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
graph.AddNode(pkg.Name)
|
||||
|
||||
g.addAurPkgProvides(pkg, graph)
|
||||
|
||||
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
|
||||
Color: colorMap[Explicit],
|
||||
Color: colorMap[instalInfo.Reason],
|
||||
Background: bgColorMap[AUR],
|
||||
Value: instalInfo,
|
||||
})
|
||||
|
||||
g.addDepNodes(ctx, pkg, graph)
|
||||
|
||||
return graph
|
||||
}
|
||||
|
||||
@ -336,7 +405,7 @@ func (g *Grapher) GraphFromAUR(ctx context.Context,
|
||||
targets []string,
|
||||
) (*topo.Graph[string, *InstallInfo], error) {
|
||||
if graph == nil {
|
||||
graph = topo.New[string, *InstallInfo]()
|
||||
graph = NewGraph()
|
||||
}
|
||||
|
||||
if len(targets) == 0 {
|
||||
@ -355,6 +424,8 @@ func (g *Grapher) GraphFromAUR(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
aurPkgsAdded := []*aurc.Pkg{}
|
||||
|
||||
for _, target := range targets {
|
||||
if cachedProvidePkg, ok := g.providerCache[target]; ok {
|
||||
aurPkgs = cachedProvidePkg
|
||||
@ -362,7 +433,7 @@ func (g *Grapher) GraphFromAUR(ctx context.Context,
|
||||
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)
|
||||
g.logger.Errorln(gotext.Get("Failed to find AUR package for"), " ", target, ":", errA)
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,8 +450,11 @@ func (g *Grapher) GraphFromAUR(ctx context.Context,
|
||||
g.providerCache[target] = []aurc.Pkg{*aurPkg}
|
||||
}
|
||||
|
||||
if g.needed {
|
||||
if pkg := g.dbExecutor.LocalPackage(aurPkg.Name); pkg != nil {
|
||||
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
|
||||
@ -390,12 +464,15 @@ func (g *Grapher) GraphFromAUR(ctx context.Context,
|
||||
|
||||
graph = g.GraphAURTarget(ctx, graph, aurPkg, &InstallInfo{
|
||||
AURBase: &aurPkg.PackageBase,
|
||||
Reason: Explicit,
|
||||
Reason: reason,
|
||||
Source: AUR,
|
||||
Version: aurPkg.Version,
|
||||
})
|
||||
aurPkgsAdded = append(aurPkgsAdded, aurPkg)
|
||||
}
|
||||
|
||||
g.AddDepsForPkgs(ctx, aurPkgsAdded, graph)
|
||||
|
||||
return graph, nil
|
||||
}
|
||||
|
||||
@ -429,15 +506,18 @@ func (g *Grapher) findDepsFromAUR(ctx context.Context,
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
if deps.Contains(pkg.Name) {
|
||||
g.providerCache[pkg.Name] = append(g.providerCache[pkg.Name], *pkg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,12 +536,13 @@ func (g *Grapher) findDepsFromAUR(ctx context.Context,
|
||||
}
|
||||
|
||||
// remove packages that don't satisfy the dependency
|
||||
for i := 0; i < len(aurPkgs); i++ {
|
||||
if !satisfiesAur(depString, &aurPkgs[i]) {
|
||||
aurPkgs = append(aurPkgs[:i], aurPkgs[i+1:]...)
|
||||
i--
|
||||
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)
|
||||
@ -488,9 +569,13 @@ func (g *Grapher) ValidateAndSetNodeInfo(graph *topo.Graph[string, *InstallInfo]
|
||||
) {
|
||||
info := graph.GetNodeInfo(node)
|
||||
if info != nil && info.Value != nil {
|
||||
if info.Value.Reason <= nodeInfo.Value.Reason {
|
||||
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)
|
||||
@ -507,15 +592,27 @@ func (g *Grapher) addNodes(
|
||||
// Check if in graph already
|
||||
for _, depString := range targetsToFind.ToSlice() {
|
||||
depName, _, _ := splitDep(depString)
|
||||
if !graph.Exists(depName) {
|
||||
if !graph.Exists(depName) && !graph.ProvidesExists(depName) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
||||
g.logger.Warnln(depString, parentPkgName, err)
|
||||
if graph.Exists(depName) {
|
||||
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
||||
g.logger.Warnln(depString, parentPkgName, err)
|
||||
}
|
||||
|
||||
targetsToFind.Remove(depString)
|
||||
}
|
||||
|
||||
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
|
||||
@ -605,7 +702,9 @@ func (g *Grapher) addNodes(
|
||||
for _, depString := range targetsToFind.ToSlice() {
|
||||
depName, mod, ver := splitDep(depString)
|
||||
// no dep found. add as missing
|
||||
graph.AddNode(depName)
|
||||
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],
|
||||
@ -624,7 +723,7 @@ func (g *Grapher) provideMenu(dep string, options []aur.Pkg) *aur.Pkg {
|
||||
return &options[0]
|
||||
}
|
||||
|
||||
str := text.Bold(gotext.Get("There are %d providers available for %s:", size, dep))
|
||||
str := text.Bold(gotext.Get("There are %[1]d providers available for %[2]s:", size, dep))
|
||||
str += "\n"
|
||||
|
||||
size = 1
|
||||
@ -650,7 +749,7 @@ func (g *Grapher) provideMenu(dep string, options []aur.Pkg) *aur.Pkg {
|
||||
if err != nil {
|
||||
g.logger.Errorln(err)
|
||||
|
||||
break
|
||||
return &options[0]
|
||||
}
|
||||
|
||||
if numberBuf == "" {
|
||||
@ -673,12 +772,10 @@ func (g *Grapher) provideMenu(dep string, options []aur.Pkg) *aur.Pkg {
|
||||
|
||||
return &options[num-1]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]aur.Pkg, error) {
|
||||
pkgs := make([]aur.Pkg, 0, 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 {
|
||||
@ -698,7 +795,7 @@ func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]au
|
||||
for i := range srcInfo.Packages {
|
||||
pkg := &srcInfo.Packages[i]
|
||||
|
||||
pkgs = append(pkgs, aur.Pkg{
|
||||
pkgs = append(pkgs, &aur.Pkg{
|
||||
ID: 0,
|
||||
Name: pkg.Pkgname,
|
||||
PackageBaseID: 0,
|
||||
@ -707,19 +804,20 @@ func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]au
|
||||
Description: getDesc(pkg),
|
||||
URL: pkg.URL,
|
||||
Depends: append(archStringToString(alpmArch, pkg.Depends),
|
||||
archStringToString(alpmArch, srcInfo.Package.Depends)...),
|
||||
MakeDepends: archStringToString(alpmArch, srcInfo.PackageBase.MakeDepends),
|
||||
CheckDepends: archStringToString(alpmArch, srcInfo.PackageBase.CheckDepends),
|
||||
archStringToString(alpmArch, srcInfo.Depends)...),
|
||||
MakeDepends: archStringToString(alpmArch, srcInfo.MakeDepends),
|
||||
CheckDepends: archStringToString(alpmArch, srcInfo.CheckDepends),
|
||||
Conflicts: append(archStringToString(alpmArch, pkg.Conflicts),
|
||||
archStringToString(alpmArch, srcInfo.Package.Conflicts)...),
|
||||
archStringToString(alpmArch, srcInfo.Conflicts)...),
|
||||
Provides: append(archStringToString(alpmArch, pkg.Provides),
|
||||
archStringToString(alpmArch, srcInfo.Package.Provides)...),
|
||||
archStringToString(alpmArch, srcInfo.Provides)...),
|
||||
Replaces: append(archStringToString(alpmArch, pkg.Replaces),
|
||||
archStringToString(alpmArch, srcInfo.Package.Replaces)...),
|
||||
OptDepends: []string{},
|
||||
Groups: pkg.Groups,
|
||||
License: pkg.License,
|
||||
Keywords: []string{},
|
||||
archStringToString(alpmArch, srcInfo.Replaces)...),
|
||||
OptDepends: append(archStringToString(alpmArch, pkg.OptDepends),
|
||||
archStringToString(alpmArch, srcInfo.OptDepends)...),
|
||||
Groups: pkg.Groups,
|
||||
License: pkg.License,
|
||||
Keywords: []string{},
|
||||
})
|
||||
}
|
||||
|
||||
@ -737,3 +835,19 @@ func archStringToString(alpmArches []string, archString []gosrc.ArchString) []st
|
||||
|
||||
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,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package dep
|
||||
|
||||
import (
|
||||
@ -9,6 +12,7 @@ import (
|
||||
"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"
|
||||
@ -72,6 +76,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) {
|
||||
|
||||
return true
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage { return nil },
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
|
||||
@ -197,7 +202,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) {
|
||||
g := NewGrapher(tt.fields.dbExecutor,
|
||||
tt.fields.aurCache, false, true,
|
||||
tt.fields.noDeps, tt.fields.noCheckDeps, false,
|
||||
text.NewLogger(io.Discard, &os.File{}, true, "test"))
|
||||
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)
|
||||
@ -205,3 +210,602 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
3
pkg/dep/testdata/android-sdk.json
vendored
Normal file
3
pkg/dep/testdata/android-sdk.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[
|
||||
{"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"]}
|
||||
]
|
@ -4,20 +4,36 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
NodeSet[T comparable] map[T]bool
|
||||
DepMap[T comparable] map[T]NodeSet[T]
|
||||
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 {
|
||||
@ -26,6 +42,9 @@ type Graph[T comparable, V any] struct {
|
||||
// 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.
|
||||
@ -38,6 +57,7 @@ func New[T comparable, V any]() *Graph[T, V] {
|
||||
dependencies: make(DepMap[T]),
|
||||
dependents: make(DepMap[T]),
|
||||
nodeInfo: make(map[T]*NodeInfo[V]),
|
||||
provides: make(ProvidesMap[T]),
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +75,23 @@ 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 {
|
||||
@ -85,10 +122,6 @@ func (g *Graph[T, V]) DependOn(child, parent T) error {
|
||||
g.AddNode(parent)
|
||||
g.AddNode(child)
|
||||
|
||||
// Add nodes.
|
||||
g.nodes[parent] = true
|
||||
g.nodes[child] = true
|
||||
|
||||
// Add edges.
|
||||
g.dependents.addNodeToNodeset(parent, child)
|
||||
g.dependencies.addNodeToNodeset(child, parent)
|
||||
@ -209,7 +242,6 @@ func (g *Graph[T, V]) Prune(node T) []T {
|
||||
// Remove edges from things that depend on `node`.
|
||||
for dependent := range g.dependents[node] {
|
||||
last := g.dependencies.removeFromDepmap(dependent, node)
|
||||
text.Debugln("pruning dependent", dependent, last)
|
||||
if last {
|
||||
pruned = append(pruned, g.Prune(dependent)...)
|
||||
}
|
||||
@ -220,7 +252,6 @@ func (g *Graph[T, V]) Prune(node T) []T {
|
||||
// Remove all edges from node to the things it depends on.
|
||||
for dependency := range g.dependencies[node] {
|
||||
last := g.dependents.removeFromDepmap(dependency, node)
|
||||
text.Debugln("pruning dependency", dependency, last)
|
||||
if last {
|
||||
pruned = append(pruned, g.Prune(dependency)...)
|
||||
}
|
||||
@ -253,10 +284,10 @@ func (g *Graph[T, V]) remove(node T) {
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) Dependencies(child T) NodeSet[T] {
|
||||
return g.buildTransitive(child, g.immediateDependencies)
|
||||
return g.buildTransitive(child, g.ImmediateDependencies)
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) immediateDependencies(node T) NodeSet[T] {
|
||||
func (g *Graph[T, V]) ImmediateDependencies(node T) NodeSet[T] {
|
||||
return g.dependencies[node]
|
||||
}
|
||||
|
9
pkg/dep/topo/errors.go
Normal file
9
pkg/dep/topo/errors.go
Normal file
@ -0,0 +1,9 @@
|
||||
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")
|
||||
)
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
@ -14,55 +15,52 @@ import (
|
||||
|
||||
const (
|
||||
MaxConcurrentFetch = 20
|
||||
_urlPackagePath = "%s/raw/packages/%s/trunk/PKGBUILD"
|
||||
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"))
|
||||
ABSPackageURL = "https://github.com/archlinux/svntogit-packages"
|
||||
ABSCommunityURL = "https://github.com/archlinux/svntogit-community"
|
||||
)
|
||||
|
||||
func getRepoURL(db string) (string, error) {
|
||||
switch db {
|
||||
case "core", "extra", "testing":
|
||||
return ABSPackageURL, nil
|
||||
case "community", "multilib", "community-testing", "multilib-testing":
|
||||
return ABSCommunityURL, nil
|
||||
}
|
||||
type regexReplace struct {
|
||||
repl string
|
||||
match *regexp.Regexp
|
||||
}
|
||||
|
||||
return "", ErrInvalidRepository
|
||||
// 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://github.com/archlinux/svntogit-community/raw/packages/neovim/trunk/PKGBUILD
|
||||
func getPackageURL(db, pkgName string) (string, error) {
|
||||
repoURL, err := getRepoURL(db)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf(_urlPackagePath, repoURL, pkgName), err
|
||||
// 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://github.com/archlinux/svntogit-community.git
|
||||
func getPackageRepoURL(db string) (string, error) {
|
||||
repoURL, err := getRepoURL(db)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// https://gitlab.archlinux.org/archlinux/packaging/packages/0ad.git
|
||||
func getPackageRepoURL(pkgName string) string {
|
||||
return fmt.Sprintf("%s/%s.git", absPackageURL, convertPkgNameForURL(pkgName))
|
||||
}
|
||||
|
||||
return repoURL + ".git", err
|
||||
// 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, err := getPackageURL(dbName, pkgName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
packageURL := getPackagePKGBUILDURL(pkgName)
|
||||
|
||||
resp, err := httpClient.Get(packageURL)
|
||||
if err != nil {
|
||||
@ -87,11 +85,8 @@ func ABSPKGBUILD(httpClient httpRequestDoer, dbName, pkgName string) ([]byte, er
|
||||
func ABSPKGBUILDRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder,
|
||||
dbName, pkgName, dest string, force bool,
|
||||
) (bool, error) {
|
||||
pkgURL, err := getPackageRepoURL(dbName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
pkgURL := getPackageRepoURL(pkgName)
|
||||
|
||||
return downloadGitRepo(ctx, cmdBuilder, pkgURL,
|
||||
pkgName, dest, force, "--single-branch", "-b", "packages/"+pkgName)
|
||||
pkgName, dest, force, "--single-branch")
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
@ -47,12 +50,12 @@ func Test_getPackageURL(t *testing.T) {
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "community package",
|
||||
name: "extra package",
|
||||
args: args{
|
||||
db: "community",
|
||||
db: "extra",
|
||||
pkgName: "kitty",
|
||||
},
|
||||
want: "https://github.com/archlinux/svntogit-community/raw/packages/kitty/trunk/PKGBUILD",
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/kitty/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
@ -61,27 +64,69 @@ func Test_getPackageURL(t *testing.T) {
|
||||
db: "core",
|
||||
pkgName: "linux",
|
||||
},
|
||||
want: "https://github.com/archlinux/svntogit-packages/raw/packages/linux/trunk/PKGBUILD",
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/raw/main/PKGBUILD",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "personal repo package",
|
||||
args: args{
|
||||
db: "sweswe",
|
||||
pkgName: "linux",
|
||||
pkgName: "zabix",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
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, err := getPackageURL(tt.args.db, tt.args.pkgName)
|
||||
if tt.wantErr {
|
||||
assert.ErrorIs(t, err, ErrInvalidRepository)
|
||||
}
|
||||
got := getPackagePKGBUILDURL(tt.args.pkgName)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
@ -110,7 +155,7 @@ func TestGetABSPkgbuild(t *testing.T) {
|
||||
body: gitExtrasPKGBUILD,
|
||||
status: 200,
|
||||
pkgName: "git-extras",
|
||||
wantURL: "https://github.com/archlinux/svntogit-packages/raw/packages/git-extras/trunk/PKGBUILD",
|
||||
wantURL: "https://gitlab.archlinux.org/archlinux/packaging/packages/git-extras/-/raw/main/PKGBUILD",
|
||||
},
|
||||
want: gitExtrasPKGBUILD,
|
||||
wantErr: false,
|
||||
@ -122,7 +167,7 @@ func TestGetABSPkgbuild(t *testing.T) {
|
||||
body: "",
|
||||
status: 404,
|
||||
pkgName: "git-git",
|
||||
wantURL: "https://github.com/archlinux/svntogit-packages/raw/packages/git-git/trunk/PKGBUILD",
|
||||
wantURL: "https://gitlab.archlinux.org/archlinux/packaging/packages/git-git/-/raw/main/PKGBUILD",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
@ -154,7 +199,7 @@ func Test_getPackageRepoURL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type args struct {
|
||||
db string
|
||||
pkgName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -163,32 +208,59 @@ func Test_getPackageRepoURL(t *testing.T) {
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "community package",
|
||||
args: args{db: "community"},
|
||||
want: "https://github.com/archlinux/svntogit-community.git",
|
||||
name: "extra package",
|
||||
args: args{pkgName: "zoxide"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/zoxide.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "core package",
|
||||
args: args{db: "core"},
|
||||
want: "https://github.com/archlinux/svntogit-packages.git",
|
||||
args: args{pkgName: "linux"},
|
||||
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "personal repo package",
|
||||
args: args{db: "sweswe"},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
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, err := getPackageRepoURL(tt.args.db)
|
||||
if tt.wantErr {
|
||||
assert.ErrorIs(t, err, ErrInvalidRepository)
|
||||
}
|
||||
got := getPackageRepoURL(tt.args.pkgName)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
@ -200,13 +272,13 @@ func Test_getPackageRepoURL(t *testing.T) {
|
||||
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 -b packages/linux https://github.com/archlinux/svntogit-packages.git linux"
|
||||
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 -b packages/linux https://github.com/archlinux/svntogit-packages.git linux", ld)
|
||||
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{
|
||||
|
@ -48,7 +48,7 @@ func AURPKGBUILDRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder, aurURL,
|
||||
|
||||
func AURPKGBUILDRepos(
|
||||
ctx context.Context,
|
||||
cmdBuilder exe.GitCmdBuilder,
|
||||
cmdBuilder exe.GitCmdBuilder, logger *text.Logger,
|
||||
targets []string, aurURL, dest string, force bool,
|
||||
) (map[string]bool, error) {
|
||||
cloned := make(map[string]bool, len(targets))
|
||||
@ -63,30 +63,34 @@ func AURPKGBUILDRepos(
|
||||
|
||||
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)
|
||||
|
||||
progress := 0
|
||||
|
||||
mux.Lock()
|
||||
progress := len(cloned)
|
||||
if err != nil {
|
||||
errs.Add(err)
|
||||
} else {
|
||||
mux.Lock()
|
||||
cloned[target] = newClone
|
||||
progress = len(cloned)
|
||||
mux.Unlock()
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Failed to download PKGBUILD: %s",
|
||||
progress, len(targets), text.Cyan(target)))
|
||||
return
|
||||
}
|
||||
|
||||
text.OperationInfoln(
|
||||
cloned[target] = newClone
|
||||
progress = len(cloned)
|
||||
mux.Unlock()
|
||||
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Downloaded PKGBUILD: %s",
|
||||
progress, len(targets), text.Cyan(target)))
|
||||
|
||||
<-sem
|
||||
|
||||
wg.Done()
|
||||
}(target)
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
@ -155,7 +158,7 @@ func TestAURPKGBUILDRepos(t *testing.T) {
|
||||
GitFlags: []string{},
|
||||
},
|
||||
}
|
||||
cloned, err := AURPKGBUILDRepos(context.Background(), cmdBuilder, targets, "https://aur.archlinux.org", dir, false)
|
||||
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)
|
||||
|
@ -24,7 +24,7 @@ type httpRequestDoer interface {
|
||||
|
||||
type DBSearcher interface {
|
||||
SyncPackage(string) db.IPackage
|
||||
SatisfierFromDB(string, string) db.IPackage
|
||||
SyncPackageFromDB(string, string) db.IPackage
|
||||
}
|
||||
|
||||
func downloadGitRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder,
|
||||
@ -81,8 +81,8 @@ func getURLName(pkg db.IPackage) string {
|
||||
return name
|
||||
}
|
||||
|
||||
func PKGBUILDs(dbExecutor DBSearcher, aurClient aur.QueryClient, httpClient *http.Client, targets []string,
|
||||
aurURL string, mode parser.TargetMode,
|
||||
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))
|
||||
|
||||
@ -96,7 +96,7 @@ func PKGBUILDs(dbExecutor DBSearcher, aurClient aur.QueryClient, httpClient *htt
|
||||
|
||||
for _, target := range targets {
|
||||
// Probably replaceable by something in query.
|
||||
dbName, name, isAUR, toSkip := getPackageUsableName(dbExecutor, aurClient, target, mode)
|
||||
dbName, name, isAUR, toSkip := getPackageUsableName(dbExecutor, aurClient, logger, target, mode)
|
||||
if toSkip {
|
||||
continue
|
||||
}
|
||||
@ -136,7 +136,7 @@ func PKGBUILDs(dbExecutor DBSearcher, aurClient aur.QueryClient, httpClient *htt
|
||||
}
|
||||
|
||||
func PKGBUILDRepos(ctx context.Context, dbExecutor DBSearcher, aurClient aur.QueryClient,
|
||||
cmdBuilder exe.GitCmdBuilder,
|
||||
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))
|
||||
@ -151,7 +151,7 @@ func PKGBUILDRepos(ctx context.Context, dbExecutor DBSearcher, aurClient aur.Que
|
||||
|
||||
for _, target := range targets {
|
||||
// Probably replaceable by something in query.
|
||||
dbName, name, isAUR, toSkip := getPackageUsableName(dbExecutor, aurClient, target, mode)
|
||||
dbName, name, isAUR, toSkip := getPackageUsableName(dbExecutor, aurClient, logger, target, mode)
|
||||
if toSkip {
|
||||
continue
|
||||
}
|
||||
@ -184,11 +184,11 @@ func PKGBUILDRepos(ctx context.Context, dbExecutor DBSearcher, aurClient aur.Que
|
||||
}
|
||||
|
||||
if aur {
|
||||
text.OperationInfoln(
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Downloaded PKGBUILD: %s",
|
||||
progress, len(targets), text.Cyan(pkgName)))
|
||||
} else {
|
||||
text.OperationInfoln(
|
||||
logger.OperationInfoln(
|
||||
gotext.Get("(%d/%d) Downloaded PKGBUILD from ABS: %s",
|
||||
progress, len(targets), text.Cyan(pkgName)))
|
||||
}
|
||||
@ -206,13 +206,13 @@ func PKGBUILDRepos(ctx context.Context, dbExecutor DBSearcher, aurClient aur.Que
|
||||
|
||||
// TODO: replace with dep.ResolveTargets.
|
||||
func getPackageUsableName(dbExecutor DBSearcher, aurClient aur.QueryClient,
|
||||
target string, mode parser.TargetMode,
|
||||
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.SatisfierFromDB(name, dbName)
|
||||
pkg = dbExecutor.SyncPackageFromDB(name, dbName)
|
||||
} else {
|
||||
pkg = dbExecutor.SyncPackage(name)
|
||||
}
|
||||
@ -239,7 +239,7 @@ func getPackageUsableName(dbExecutor DBSearcher, aurClient aur.QueryClient,
|
||||
Needles: []string{name},
|
||||
})
|
||||
if err != nil {
|
||||
text.Warnln(err)
|
||||
logger.Warnln(err)
|
||||
return dbName, name, true, true
|
||||
}
|
||||
|
||||
|
106
pkg/download/unified_integration_test.go
Normal file
106
pkg/download/unified_integration_test.go
Normal file
@ -0,0 +1,106 @@
|
||||
//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,10 +1,15 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -15,8 +20,13 @@ import (
|
||||
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
|
||||
@ -31,6 +41,8 @@ func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
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"}
|
||||
@ -42,13 +54,14 @@ func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
||||
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,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
@ -82,7 +95,7 @@ func TestPKGBUILDReposDefinedDBClone(t *testing.T) {
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
@ -116,7 +129,7 @@ func TestPKGBUILDReposClone(t *testing.T) {
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
@ -150,7 +163,7 @@ func TestPKGBUILDReposNotFound(t *testing.T) {
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
@ -184,7 +197,7 @@ func TestPKGBUILDReposRepoMode(t *testing.T) {
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeRepo, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
@ -211,8 +224,8 @@ func TestPKGBUILDFull(t *testing.T) {
|
||||
Reply(200).
|
||||
BodyString("example_yay-bin")
|
||||
|
||||
gock.New("https://github.com/").
|
||||
Get("/archlinux/svntogit-packages/raw/packages/yay/trunk/PKGBUILD").
|
||||
gock.New("https://gitlab.archlinux.org/").
|
||||
Get("archlinux/packaging/packages/yay/-/raw/main/PKGBUILD").
|
||||
Reply(200).
|
||||
BodyString("example_yay")
|
||||
|
||||
@ -222,7 +235,7 @@ func TestPKGBUILDFull(t *testing.T) {
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
|
||||
fetched, err := PKGBUILDs(searcher, mockClient, &http.Client{},
|
||||
fetched, err := PKGBUILDs(searcher, mockClient, &http.Client{}, newTestLogger(),
|
||||
targets, "https://aur.archlinux.org", parser.ModeAny)
|
||||
|
||||
assert.NoError(t, err)
|
||||
@ -260,7 +273,7 @@ func TestPKGBUILDReposMissingAUR(t *testing.T) {
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
cmdBuilder, newTestLogger(),
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
@ -102,7 +102,7 @@ func (d *testDBSearcher) SyncPackage(name string) db.IPackage {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *testDBSearcher) SatisfierFromDB(name string, db string) db.IPackage {
|
||||
func (d *testDBSearcher) SyncPackageFromDB(name string, db string) db.IPackage {
|
||||
if v, ok := d.absPackagesDB[name]; ok && v == db {
|
||||
return &testPackage{
|
||||
name: name,
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
)
|
||||
|
||||
// IntRange stores a max and min amount for range.
|
||||
@ -17,10 +17,10 @@ type IntRange struct {
|
||||
// IntRanges is a slice of IntRange.
|
||||
type IntRanges []IntRange
|
||||
|
||||
func makeIntRange(min, max int) IntRange {
|
||||
func makeIntRange(minVal, maxVal int) IntRange {
|
||||
return IntRange{
|
||||
min,
|
||||
max,
|
||||
min: minVal,
|
||||
max: maxVal,
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,24 +42,6 @@ func (rs IntRanges) Get(n int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Min returns min value between a and b.
|
||||
func Min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// Max returns max value between a and b.
|
||||
func Max(a, b int) int {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -71,12 +53,12 @@ func Max(a, b int) int {
|
||||
// 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 stringset.StringSet,
|
||||
otherInclude, otherExclude mapset.Set[string],
|
||||
) {
|
||||
include = make(IntRanges, 0)
|
||||
exclude = make(IntRanges, 0)
|
||||
otherInclude = make(stringset.StringSet)
|
||||
otherExclude = make(stringset.StringSet)
|
||||
otherInclude = mapset.NewThreadUnsafeSet[string]()
|
||||
otherExclude = mapset.NewThreadUnsafeSet[string]()
|
||||
|
||||
words := strings.FieldsFunc(input, func(c rune) bool {
|
||||
return unicode.IsSpace(c) || c == ','
|
||||
@ -102,22 +84,22 @@ func ParseNumberMenu(input string) (include, exclude IntRanges,
|
||||
|
||||
num1, err = strconv.Atoi(ranges[0])
|
||||
if err != nil {
|
||||
other.Set(strings.ToLower(word))
|
||||
other.Add(strings.ToLower(word))
|
||||
continue
|
||||
}
|
||||
|
||||
if len(ranges) == 2 {
|
||||
num2, err = strconv.Atoi(ranges[1])
|
||||
if err != nil {
|
||||
other.Set(strings.ToLower(word))
|
||||
other.Add(strings.ToLower(word))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
num2 = num1
|
||||
}
|
||||
|
||||
mi := Min(num1, num2)
|
||||
ma := Max(num1, num2)
|
||||
mi := min(num1, num2)
|
||||
ma := max(num1, num2)
|
||||
|
||||
if !invert {
|
||||
include = append(include, makeIntRange(mi, ma))
|
||||
|
@ -1,9 +1,13 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package intrange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseNumberMenu(t *testing.T) {
|
||||
@ -11,8 +15,8 @@ func TestParseNumberMenu(t *testing.T) {
|
||||
type result struct {
|
||||
Include IntRanges
|
||||
Exclude IntRanges
|
||||
OtherInclude stringset.StringSet
|
||||
OtherExclude stringset.StringSet
|
||||
OtherInclude mapset.Set[string]
|
||||
OtherExclude mapset.Set[string]
|
||||
}
|
||||
|
||||
inputs := []string{
|
||||
@ -37,15 +41,15 @@ func TestParseNumberMenu(t *testing.T) {
|
||||
makeIntRange(3, 3),
|
||||
makeIntRange(4, 4),
|
||||
makeIntRange(5, 5),
|
||||
}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(1, 10),
|
||||
makeIntRange(5, 15),
|
||||
}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(5, 10),
|
||||
makeIntRange(85, 90),
|
||||
}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{
|
||||
IntRanges{
|
||||
makeIntRange(1, 1),
|
||||
@ -58,18 +62,18 @@ func TestParseNumberMenu(t *testing.T) {
|
||||
makeIntRange(38, 40),
|
||||
makeIntRange(123, 123),
|
||||
},
|
||||
make(stringset.StringSet), make(stringset.StringSet),
|
||||
mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string](),
|
||||
},
|
||||
{IntRanges{}, IntRanges{}, stringset.Make("abort", "all", "none"), make(stringset.StringSet)},
|
||||
{IntRanges{}, IntRanges{}, stringset.Make("a-b"), stringset.Make("abort", "a-b")},
|
||||
{IntRanges{}, IntRanges{}, stringset.Make("-9223372036854775809-9223372036854775809"), make(stringset.StringSet)},
|
||||
{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{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
|
||||
{IntRanges{
|
||||
makeIntRange(1, 1),
|
||||
makeIntRange(2, 2),
|
||||
@ -79,23 +83,20 @@ func TestParseNumberMenu(t *testing.T) {
|
||||
makeIntRange(6, 6),
|
||||
makeIntRange(7, 7),
|
||||
makeIntRange(8, 8),
|
||||
}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
{IntRanges{}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
{IntRanges{}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
|
||||
{IntRanges{}, IntRanges{}, stringset.Make("a", "b", "c", "d", "e"), make(stringset.StringSet)},
|
||||
}, 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)
|
||||
|
||||
if !intRangesEqual(include, res.Include) ||
|
||||
!intRangesEqual(exclude, res.Exclude) ||
|
||||
!stringset.Equal(otherInclude, res.OtherInclude) ||
|
||||
!stringset.Equal(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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,13 @@ package menus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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"
|
||||
)
|
||||
@ -24,7 +24,9 @@ func anyExistInCache(pkgbuildDirs map[string]string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error {
|
||||
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
|
||||
}
|
||||
@ -48,26 +50,25 @@ func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, p
|
||||
bases = append(bases, pkg)
|
||||
}
|
||||
|
||||
// TOFIX: empty installed slice means installed filter is disabled
|
||||
toClean, errClean := selectionMenu(w, pkgbuildDirsByBase, bases, mapset.NewSet[string](),
|
||||
toClean, errClean := selectionMenu(run.Logger, pkgbuildDirsByBase, bases, installed,
|
||||
gotext.Get("Packages to cleanBuild?"),
|
||||
settings.NoConfirm, config.AnswerClean, skipFunc)
|
||||
settings.NoConfirm, run.Cfg.AnswerClean, skipFunc)
|
||||
if errClean != nil {
|
||||
return errClean
|
||||
}
|
||||
|
||||
for i, base := range toClean {
|
||||
dir := pkgbuildDirsByBase[base]
|
||||
text.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(toClean), text.Cyan(dir)))
|
||||
run.Logger.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(toClean), text.Cyan(dir)))
|
||||
|
||||
if err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildGitCmd(ctx, dir, "reset", "--hard", "origin/HEAD")); err != nil {
|
||||
text.Warnln(gotext.Get("Unable to clean:"), 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 := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildGitCmd(ctx, dir, "clean", "-fdx")); err != nil {
|
||||
text.Warnln(gotext.Get("Unable to clean:"), dir)
|
||||
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
|
||||
}
|
||||
@ -75,42 +76,3 @@ func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, p
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Clean(w io.Writer, cleanMenuOption bool, pkgbuildDirs map[string]string,
|
||||
installed mapset.Set[string], noConfirm bool, answerClean string,
|
||||
) error {
|
||||
if !(cleanMenuOption && anyExistInCache(pkgbuildDirs)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
skipFunc := func(pkg string) bool {
|
||||
dir := pkgbuildDirs[pkg]
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
bases := make([]string, 0, len(pkgbuildDirs))
|
||||
for pkg := range pkgbuildDirs {
|
||||
bases = append(bases, pkg)
|
||||
}
|
||||
|
||||
toClean, errClean := selectionMenu(w, pkgbuildDirs, bases, installed, gotext.Get("Packages to cleanBuild?"),
|
||||
noConfirm, answerClean, skipFunc)
|
||||
if errClean != nil {
|
||||
return errClean
|
||||
}
|
||||
|
||||
for i, base := range toClean {
|
||||
dir := pkgbuildDirs[base]
|
||||
text.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(toClean), text.Cyan(dir)))
|
||||
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"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"
|
||||
@ -22,7 +22,7 @@ const (
|
||||
gitDiffRefName = "AUR_SEEN"
|
||||
)
|
||||
|
||||
func showPkgbuildDiffs(ctx context.Context, cmdBuilder exe.ICmdBuilder,
|
||||
func showPkgbuildDiffs(ctx context.Context, cmdBuilder exe.ICmdBuilder, logger *text.Logger,
|
||||
pkgbuildDirs map[string]string, bases []string,
|
||||
) error {
|
||||
var errMulti multierror.MultiError
|
||||
@ -46,7 +46,7 @@ func showPkgbuildDiffs(ctx context.Context, cmdBuilder exe.ICmdBuilder,
|
||||
}
|
||||
|
||||
if !hasDiff {
|
||||
text.Warnln(gotext.Get("%s: No changes -- skipping", text.Cyan(pkg)))
|
||||
logger.Warnln(gotext.Get("%s: No changes -- skipping", text.Cyan(pkg)))
|
||||
|
||||
continue
|
||||
}
|
||||
@ -85,13 +85,13 @@ func gitHasDiff(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) (bo
|
||||
|
||||
return lastseen != upstream, nil
|
||||
}
|
||||
// If YAY_DIFF_REVIEW does not exists, we have never reviewed a diff for this package
|
||||
// If AUR_SEEN does not exists, we have never reviewed a diff for this package
|
||||
// and should display it.
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Return wether or not we have reviewed a diff yet. It checks for the existence of
|
||||
// YAY_DIFF_REVIEW in the git ref-list.
|
||||
// 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,
|
||||
@ -100,7 +100,7 @@ func gitHasLastSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir stri
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Returns the last reviewed hash. If YAY_DIFF_REVIEW exists it will return this hash.
|
||||
// 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) {
|
||||
@ -119,7 +119,7 @@ func getLastSeenHash(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string
|
||||
return gitEmptyTree, nil
|
||||
}
|
||||
|
||||
// Update the YAY_DIFF_REVIEW ref to HEAD. We use this ref to determine which diff were
|
||||
// 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(
|
||||
@ -145,43 +145,9 @@ func updatePkgbuildSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgb
|
||||
return errMulti.Return()
|
||||
}
|
||||
|
||||
func Diff(ctx context.Context, cmdBuilder exe.ICmdBuilder, w io.Writer,
|
||||
pkgbuildDirs map[string]string, diffMenuOption bool,
|
||||
installed mapset.Set[string], cloned map[string]bool, noConfirm bool, diffDefaultAnswer string,
|
||||
func DiffFn(ctx context.Context, run *runtime.Runtime, w io.Writer,
|
||||
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
|
||||
) error {
|
||||
if !diffMenuOption {
|
||||
return nil
|
||||
}
|
||||
|
||||
bases := make([]string, 0, len(pkgbuildDirs))
|
||||
for base := range pkgbuildDirs {
|
||||
bases = append(bases, base)
|
||||
}
|
||||
|
||||
toDiff, errMenu := selectionMenu(w, pkgbuildDirs, bases, installed, gotext.Get("Diffs to show?"),
|
||||
noConfirm, diffDefaultAnswer, nil)
|
||||
if errMenu != nil || len(toDiff) == 0 {
|
||||
return errMenu
|
||||
}
|
||||
|
||||
if errD := showPkgbuildDiffs(ctx, cmdBuilder, pkgbuildDirs, toDiff); errD != nil {
|
||||
return errD
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
|
||||
if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
|
||||
return settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
if errUpd := updatePkgbuildSeenRef(ctx, cmdBuilder, pkgbuildDirs, toDiff); errUpd != nil {
|
||||
return errUpd
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error {
|
||||
if len(pkgbuildDirsByBase) == 0 {
|
||||
return nil // no work to do
|
||||
}
|
||||
@ -191,23 +157,23 @@ func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, pk
|
||||
bases = append(bases, base)
|
||||
}
|
||||
|
||||
toDiff, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, mapset.NewThreadUnsafeSet[string](), gotext.Get("Diffs to show?"),
|
||||
settings.NoConfirm, config.AnswerDiff, nil)
|
||||
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, config.Runtime.CmdBuilder, pkgbuildDirsByBase, toDiff); errD != nil {
|
||||
if errD := showPkgbuildDiffs(ctx, run.CmdBuilder, run.Logger, pkgbuildDirsByBase, toDiff); errD != nil {
|
||||
return errD
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
run.Logger.Println()
|
||||
|
||||
if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
|
||||
if !run.Logger.ContinueTask(gotext.Get("Proceed with install?"), true, false) {
|
||||
return settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
if errUpd := updatePkgbuildSeenRef(ctx, config.Runtime.CmdBuilder, pkgbuildDirsByBase, toDiff); errUpd != nil {
|
||||
if errUpd := updatePkgbuildSeenRef(ctx, run.CmdBuilder, pkgbuildDirsByBase, toDiff); errUpd != nil {
|
||||
return errUpd
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ package menus
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -15,17 +14,18 @@ import (
|
||||
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(editorConfig, editorFlags string, noConfirm bool) (editor string, args []string) {
|
||||
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 {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
log.Errorln(err)
|
||||
} else {
|
||||
return editor, strings.Fields(editorFlags)
|
||||
}
|
||||
@ -35,7 +35,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
|
||||
if editorArgs := strings.Fields(os.Getenv("VISUAL")); len(editorArgs) != 0 {
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
log.Errorln(err)
|
||||
} else {
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
@ -46,7 +46,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
|
||||
if editorArgs := strings.Fields(os.Getenv("EDITOR")); len(editorArgs) != 0 {
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
log.Errorln(err)
|
||||
} else {
|
||||
return editor, editorArgs[1:]
|
||||
}
|
||||
@ -54,16 +54,15 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
|
||||
|
||||
fallthrough
|
||||
default:
|
||||
fmt.Fprintln(os.Stderr)
|
||||
text.Errorln(gotext.Get("%s is not set", text.Bold(text.Cyan("$EDITOR"))))
|
||||
text.Warnln(gotext.Get("Add %s or %s to your environment variables", text.Bold(text.Cyan("$EDITOR")), text.Bold(text.Cyan("$VISUAL"))))
|
||||
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 {
|
||||
text.Infoln(gotext.Get("Edit PKGBUILD with?"))
|
||||
log.Infoln(gotext.Get("Edit PKGBUILD with?"))
|
||||
|
||||
editorInput, err := text.GetInput(os.Stdin, "", noConfirm)
|
||||
editorInput, err := log.GetInput("", noConfirm)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
log.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -74,7 +73,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
|
||||
|
||||
editor, err := exec.LookPath(editorArgs[0])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
log.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -83,7 +82,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
|
||||
}
|
||||
}
|
||||
|
||||
func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
|
||||
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))
|
||||
@ -102,7 +101,7 @@ func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
|
||||
}
|
||||
|
||||
if len(pkgbuilds) > 0 {
|
||||
editor, editorArgs := editor(editorConfig, editorFlags, noConfirm)
|
||||
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
|
||||
@ -115,40 +114,8 @@ func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
|
||||
return nil
|
||||
}
|
||||
|
||||
func Edit(w io.Writer, editMenuOption bool, pkgbuildDirs map[string]string, editorConfig,
|
||||
editorFlags string, installed mapset.Set[string], srcinfos map[string]*gosrc.Srcinfo,
|
||||
noConfirm bool, editDefaultAnswer string,
|
||||
) error {
|
||||
if !editMenuOption {
|
||||
return nil
|
||||
}
|
||||
|
||||
bases := make([]string, 0, len(pkgbuildDirs))
|
||||
for pkg := range pkgbuildDirs {
|
||||
bases = append(bases, pkg)
|
||||
}
|
||||
|
||||
toEdit, errMenu := selectionMenu(w, pkgbuildDirs, bases,
|
||||
installed, gotext.Get("PKGBUILDs to edit?"), noConfirm, editDefaultAnswer, nil)
|
||||
if errMenu != nil || len(toEdit) == 0 {
|
||||
return errMenu
|
||||
}
|
||||
|
||||
if errEdit := editPkgbuilds(pkgbuildDirs, toEdit, editorConfig, editorFlags, srcinfos, noConfirm); errEdit != nil {
|
||||
return errEdit
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
|
||||
if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
|
||||
return settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func EditFn(ctx context.Context, config *settings.Configuration, w io.Writer,
|
||||
pkgbuildDirsByBase map[string]string,
|
||||
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
|
||||
@ -159,22 +126,21 @@ func EditFn(ctx context.Context, config *settings.Configuration, w io.Writer,
|
||||
bases = append(bases, pkg)
|
||||
}
|
||||
|
||||
toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases,
|
||||
mapset.NewThreadUnsafeSet[string](),
|
||||
gotext.Get("PKGBUILDs to edit?"), settings.NoConfirm, config.AnswerEdit, nil)
|
||||
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(pkgbuildDirsByBase,
|
||||
toEdit, config.Editor, config.EditorFlags, nil, settings.NoConfirm); errEdit != nil {
|
||||
if errEdit := editPkgbuilds(run.Logger, pkgbuildDirsByBase,
|
||||
toEdit, run.Cfg.Editor, run.Cfg.EditorFlags, nil, settings.NoConfirm); errEdit != nil {
|
||||
return errEdit
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
run.Logger.Println()
|
||||
|
||||
if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
|
||||
if !run.Logger.ContinueTask(gotext.Get("Proceed with install?"), true, false) {
|
||||
return settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package menus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
@ -14,7 +13,9 @@ import (
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
)
|
||||
|
||||
func pkgbuildNumberMenu(w io.Writer, pkgbuildDirs map[string]string, bases []string, installed mapset.Set[string]) {
|
||||
func pkgbuildNumberMenu(logger *text.Logger, pkgbuildDirs map[string]string,
|
||||
bases []string, installed mapset.Set[string],
|
||||
) {
|
||||
toPrint := ""
|
||||
|
||||
for n, pkgBase := range bases {
|
||||
@ -34,32 +35,32 @@ func pkgbuildNumberMenu(w io.Writer, pkgbuildDirs map[string]string, bases []str
|
||||
toPrint += "\n"
|
||||
}
|
||||
|
||||
fmt.Fprint(w, toPrint)
|
||||
logger.Print(toPrint)
|
||||
}
|
||||
|
||||
func selectionMenu(w io.Writer, pkgbuildDirs map[string]string, bases []string, installed mapset.Set[string],
|
||||
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(w, pkgbuildDirs, bases, installed)
|
||||
pkgbuildNumberMenu(logger, pkgbuildDirs, bases, installed)
|
||||
|
||||
text.Infoln(message)
|
||||
text.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"))))
|
||||
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 := text.GetInput(os.Stdin, defaultAnswer, noConfirm)
|
||||
selectInput, err := logger.GetInput(defaultAnswer, noConfirm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
eInclude, eExclude, eOtherInclude, eOtherExclude := intrange.ParseNumberMenu(selectInput)
|
||||
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
|
||||
eIsInclude := len(eExclude) == 0 && eOtherExclude.Cardinality() == 0
|
||||
|
||||
if eOtherInclude.Get("abort") || eOtherInclude.Get("ab") {
|
||||
if eOtherInclude.Contains("abort") || eOtherInclude.Contains("ab") {
|
||||
return nil, settings.ErrUserAbort{}
|
||||
}
|
||||
|
||||
if eOtherInclude.Get("n") || eOtherInclude.Get("none") {
|
||||
if eOtherInclude.Contains("n") || eOtherInclude.Contains("none") {
|
||||
return selected, nil
|
||||
}
|
||||
|
||||
@ -74,26 +75,26 @@ func selectionMenu(w io.Writer, pkgbuildDirs map[string]string, bases []string,
|
||||
continue
|
||||
}
|
||||
|
||||
if anyInstalled && (eOtherInclude.Get("i") || eOtherInclude.Get("installed")) {
|
||||
if anyInstalled && (eOtherInclude.Contains("i") || eOtherInclude.Contains("installed")) {
|
||||
selected = append(selected, pkgBase)
|
||||
continue
|
||||
}
|
||||
|
||||
if !anyInstalled && (eOtherInclude.Get("no") || eOtherInclude.Get("notinstalled")) {
|
||||
if !anyInstalled && (eOtherInclude.Contains("no") || eOtherInclude.Contains("notinstalled")) {
|
||||
selected = append(selected, pkgBase)
|
||||
continue
|
||||
}
|
||||
|
||||
if eOtherInclude.Get("a") || eOtherInclude.Get("all") {
|
||||
if eOtherInclude.Contains("a") || eOtherInclude.Contains("all") {
|
||||
selected = append(selected, pkgBase)
|
||||
continue
|
||||
}
|
||||
|
||||
if eIsInclude && (eInclude.Get(len(bases)-i) || eOtherInclude.Get(pkgBase)) {
|
||||
if eIsInclude && (eInclude.Get(len(bases)-i) || eOtherInclude.Contains(pkgBase)) {
|
||||
selected = append(selected, pkgBase)
|
||||
}
|
||||
|
||||
if !eIsInclude && (!eExclude.Get(len(bases)-i) && !eOtherExclude.Get(pkgBase)) {
|
||||
if !eIsInclude && (!eExclude.Get(len(bases)-i) && !eOtherExclude.Contains(pkgBase)) {
|
||||
selected = append(selected, pkgBase)
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,9 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"html"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -23,13 +21,13 @@ type item struct {
|
||||
Creator string `xml:"dc:creator"`
|
||||
}
|
||||
|
||||
func (item *item) print(buildTime time.Time, all, quiet bool) {
|
||||
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 {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
logger.Errorln(err)
|
||||
} else {
|
||||
fd = text.FormatTime(int(date.Unix()))
|
||||
if !all && !buildTime.IsZero() {
|
||||
@ -39,11 +37,11 @@ func (item *item) print(buildTime time.Time, all, quiet bool) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(text.Bold(text.Magenta(fd)), text.Bold(strings.TrimSpace(item.Title)))
|
||||
logger.Println(text.Bold(text.Magenta(fd)), text.Bold(strings.TrimSpace(item.Title)))
|
||||
|
||||
if !quiet {
|
||||
desc := strings.TrimSpace(parseNews(item.Description))
|
||||
fmt.Println(desc)
|
||||
logger.Println(desc)
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +58,9 @@ type rss struct {
|
||||
Channel channel `xml:"channel"`
|
||||
}
|
||||
|
||||
func PrintNewsFeed(ctx context.Context, client *http.Client, cutOffDate time.Time, bottomUp, all, quiet bool) error {
|
||||
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
|
||||
@ -87,11 +87,11 @@ func PrintNewsFeed(ctx context.Context, client *http.Client, cutOffDate time.Tim
|
||||
|
||||
if bottomUp {
|
||||
for i := len(rssGot.Channel.Items) - 1; i >= 0; i-- {
|
||||
rssGot.Channel.Items[i].print(cutOffDate, all, quiet)
|
||||
rssGot.Channel.Items[i].printNews(logger, cutOffDate, all, quiet)
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < len(rssGot.Channel.Items); i++ {
|
||||
rssGot.Channel.Items[i].print(cutOffDate, all, quiet)
|
||||
rssGot.Channel.Items[i].printNews(logger, cutOffDate, all, quiet)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package news
|
||||
|
||||
import (
|
||||
@ -5,12 +8,15 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/bradleyjkemp/cupaloy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
const lastNews = `
|
||||
@ -121,6 +127,7 @@ func TestPrintNewsFeed(t *testing.T) {
|
||||
{name: "latest-quiet", args: args{bottomUp: true, cutOffDate: lastNewsTime, all: false, quiet: true}, wantErr: false},
|
||||
{name: "latest-quiet-topdown", args: args{bottomUp: false, cutOffDate: lastNewsTime, all: false, quiet: true}, wantErr: false},
|
||||
}
|
||||
t.Setenv("TZ", "UTC")
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@ -131,17 +138,16 @@ func TestPrintNewsFeed(t *testing.T) {
|
||||
|
||||
defer gock.Off()
|
||||
|
||||
rescueStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
logger := text.NewLogger(w, w, strings.NewReader(""), false, "logger")
|
||||
|
||||
err := PrintNewsFeed(context.Background(), &http.Client{}, tt.args.cutOffDate, tt.args.bottomUp, tt.args.all, tt.args.quiet)
|
||||
err := PrintNewsFeed(context.Background(), &http.Client{}, logger,
|
||||
tt.args.cutOffDate, tt.args.bottomUp, tt.args.all, tt.args.quiet)
|
||||
assert.NoError(t, err)
|
||||
|
||||
w.Close()
|
||||
out, _ := io.ReadAll(r)
|
||||
cupaloy.SnapshotT(t, out)
|
||||
os.Stdout = rescueStdout
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -160,15 +166,14 @@ func TestPrintNewsFeedSameDay(t *testing.T) {
|
||||
|
||||
defer gock.Off()
|
||||
|
||||
rescueStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
logger := text.NewLogger(w, w, strings.NewReader(""), false, "logger")
|
||||
|
||||
err := PrintNewsFeed(context.Background(), &http.Client{}, lastNewsTime, true, false, false)
|
||||
err := PrintNewsFeed(context.Background(), &http.Client{}, logger,
|
||||
lastNewsTime, true, false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
w.Close()
|
||||
out, _ := io.ReadAll(r)
|
||||
cupaloy.SnapshotT(t, out)
|
||||
os.Stdout = rescueStdout
|
||||
}
|
||||
|
@ -1,101 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/aur/rpc"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
"github.com/Jguer/yay/v12/pkg/multierror"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type Pkg = aur.Pkg
|
||||
|
||||
// Queries the aur for information about specified packages.
|
||||
// All packages should be queried in a single aur request except when the number
|
||||
// of packages exceeds the number set in config.RequestSplitN.
|
||||
// If the number does exceed config.RequestSplitN multiple aur requests will be
|
||||
// performed concurrently.
|
||||
func AURInfo(ctx context.Context, aurClient rpc.ClientInterface, names []string, warnings *AURWarnings, splitN int) ([]Pkg, error) {
|
||||
info := make([]Pkg, 0, len(names))
|
||||
seen := make(map[string]int)
|
||||
|
||||
var (
|
||||
mux sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
errs multierror.MultiError
|
||||
)
|
||||
|
||||
makeRequest := func(n, max int) {
|
||||
defer wg.Done()
|
||||
|
||||
text.Debugln("AUR RPC:", names[n:max])
|
||||
|
||||
tempInfo, requestErr := aurClient.Info(ctx, names[n:max])
|
||||
if requestErr != nil {
|
||||
errs.Add(requestErr)
|
||||
return
|
||||
}
|
||||
|
||||
mux.Lock()
|
||||
info = append(info, tempInfo...)
|
||||
mux.Unlock()
|
||||
}
|
||||
|
||||
for n := 0; n < len(names); n += splitN {
|
||||
max := intrange.Min(len(names), n+splitN)
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go makeRequest(n, max)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if err := errs.Return(); err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
for k := range info {
|
||||
seen[info[k].Name] = k
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
i, ok := seen[name]
|
||||
if !ok && !warnings.Ignore.Get(name) {
|
||||
warnings.Missing = append(warnings.Missing, name)
|
||||
continue
|
||||
}
|
||||
|
||||
pkg := info[i]
|
||||
|
||||
if pkg.Maintainer == "" && !warnings.Ignore.Get(name) {
|
||||
warnings.Orphans = append(warnings.Orphans, name)
|
||||
}
|
||||
|
||||
if pkg.OutOfDate != 0 && !warnings.Ignore.Get(name) {
|
||||
warnings.OutOfDate = append(warnings.OutOfDate, name)
|
||||
}
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func AURInfoPrint(ctx context.Context, aurClient rpc.ClientInterface, names []string, splitN int) ([]Pkg, error) {
|
||||
text.OperationInfoln(gotext.Get("Querying AUR..."))
|
||||
|
||||
warnings := &AURWarnings{}
|
||||
|
||||
info, err := AURInfo(ctx, aurClient, names, warnings, splitN)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
warnings.Print()
|
||||
|
||||
return info, nil
|
||||
}
|
@ -1,47 +1,92 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type AURWarnings struct {
|
||||
Orphans []string
|
||||
OutOfDate []string
|
||||
Missing []string
|
||||
Ignore stringset.StringSet
|
||||
Orphans []string
|
||||
OutOfDate []string
|
||||
Missing []string
|
||||
LocalNewer []string
|
||||
|
||||
log *text.Logger
|
||||
}
|
||||
|
||||
func NewWarnings() *AURWarnings {
|
||||
return &AURWarnings{Ignore: make(stringset.StringSet)}
|
||||
func NewWarnings(logger *text.Logger) *AURWarnings {
|
||||
return &AURWarnings{log: logger}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) AddToWarnings(remote map[string]alpm.IPackage, aurPkg *aur.Pkg) {
|
||||
name := aurPkg.Name
|
||||
pkg, ok := remote[name]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if aurPkg.Maintainer == "" && !pkg.ShouldIgnore() {
|
||||
warnings.Orphans = append(warnings.Orphans, name)
|
||||
}
|
||||
|
||||
if aurPkg.OutOfDate != 0 && !pkg.ShouldIgnore() {
|
||||
warnings.OutOfDate = append(warnings.OutOfDate, name)
|
||||
}
|
||||
|
||||
if !pkg.ShouldIgnore() && !isDevelPackage(pkg) && db.VerCmp(pkg.Version(), aurPkg.Version) > 0 {
|
||||
left, right := GetVersionDiff(pkg.Version(), aurPkg.Version)
|
||||
|
||||
newerMsg := gotext.Get("%s: local (%s) is newer than AUR (%s)",
|
||||
text.Cyan(name),
|
||||
left, right,
|
||||
)
|
||||
|
||||
warnings.LocalNewer = append(warnings.LocalNewer, newerMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) CalculateMissing(remoteNames []string,
|
||||
remote map[string]alpm.IPackage, aurData map[string]*aur.Pkg,
|
||||
) {
|
||||
for _, name := range remoteNames {
|
||||
if _, ok := aurData[name]; !ok && !remote[name].ShouldIgnore() {
|
||||
if _, ok := aurData[strings.TrimSuffix(name, "-debug")]; !ok {
|
||||
warnings.Missing = append(warnings.Missing, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) Print() {
|
||||
normalMissing, debugMissing := filterDebugPkgs(warnings.Missing)
|
||||
|
||||
if len(normalMissing) > 0 {
|
||||
text.Warn(gotext.Get("Packages not in AUR:"))
|
||||
printRange(normalMissing)
|
||||
warnings.log.Warnln(gotext.Get("Packages not in AUR:"), formatNames(normalMissing))
|
||||
}
|
||||
|
||||
if len(debugMissing) > 0 {
|
||||
text.Warn(gotext.Get("Missing AUR Debug Packages:"))
|
||||
printRange(debugMissing)
|
||||
warnings.log.Warnln(gotext.Get("Missing AUR Debug Packages:"), formatNames(debugMissing))
|
||||
}
|
||||
|
||||
if len(warnings.Orphans) > 0 {
|
||||
text.Warn(gotext.Get("Orphan (unmaintained) AUR Packages:"))
|
||||
printRange(warnings.Orphans)
|
||||
warnings.log.Warnln(gotext.Get("Orphan (unmaintained) AUR Packages:"), formatNames(warnings.Orphans))
|
||||
}
|
||||
|
||||
if len(warnings.OutOfDate) > 0 {
|
||||
text.Warn(gotext.Get("Flagged Out Of Date AUR Packages:"))
|
||||
printRange(warnings.OutOfDate)
|
||||
warnings.log.Warnln(gotext.Get("Flagged Out Of Date AUR Packages:"), formatNames(warnings.OutOfDate))
|
||||
}
|
||||
|
||||
if len(warnings.LocalNewer) > 0 {
|
||||
for _, newer := range warnings.LocalNewer {
|
||||
warnings.log.Warnln(newer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,10 +105,6 @@ func filterDebugPkgs(names []string) (normal, debug []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func printRange(names []string) {
|
||||
for _, name := range names {
|
||||
fmt.Print(" " + text.Cyan(name))
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
func formatNames(names []string) string {
|
||||
return " " + text.Cyan(strings.Join(names, " "))
|
||||
}
|
||||
|
@ -7,19 +7,19 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func RemoveInvalidTargets(targets []string, mode parser.TargetMode) []string {
|
||||
func RemoveInvalidTargets(logger *text.Logger, targets []string, mode parser.TargetMode) []string {
|
||||
filteredTargets := make([]string, 0)
|
||||
|
||||
for _, target := range targets {
|
||||
dbName, _ := text.SplitDBFromName(target)
|
||||
|
||||
if dbName == "aur" && !mode.AtLeastAUR() {
|
||||
text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
|
||||
logger.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
|
||||
continue
|
||||
}
|
||||
|
||||
if dbName != "aur" && dbName != "" && !mode.AtLeastRepo() {
|
||||
text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
|
||||
logger.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -11,22 +11,31 @@ import (
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
"github.com/adrg/strutil"
|
||||
"github.com/adrg/strutil/metrics"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
const sourceAUR = "aur"
|
||||
|
||||
type SearchVerbosity int
|
||||
|
||||
// Verbosity settings for search.
|
||||
const (
|
||||
NumberMenu SearchVerbosity = iota
|
||||
Detailed
|
||||
Minimal
|
||||
)
|
||||
|
||||
type Builder interface {
|
||||
Len() int
|
||||
Execute(ctx context.Context, dbExecutor db.Executor, pkgS []string)
|
||||
Results(dbExecutor db.Executor, verboseSearch SearchVerbosity) error
|
||||
GetTargets(include, exclude intrange.IntRanges, otherExclude stringset.StringSet) ([]string, error)
|
||||
GetTargets(include, exclude intrange.IntRanges, otherExclude mapset.Set[string]) ([]string, error)
|
||||
}
|
||||
|
||||
type SourceQueryBuilder struct {
|
||||
@ -94,20 +103,34 @@ func (a *abstractResults) Less(i, j int) bool {
|
||||
pkgA := a.results[i]
|
||||
pkgB := a.results[j]
|
||||
|
||||
simA := a.calculateMetric(&pkgA)
|
||||
simB := a.calculateMetric(&pkgB)
|
||||
var cmpResult bool
|
||||
|
||||
if a.bottomUp {
|
||||
return simA < simB
|
||||
switch a.sortBy {
|
||||
case "name":
|
||||
cmpResult = !text.LessRunes([]rune(pkgA.name), []rune(pkgB.name))
|
||||
if a.separateSources {
|
||||
cmpSources := strings.Compare(pkgA.source, pkgB.source)
|
||||
if cmpSources != 0 {
|
||||
cmpResult = cmpSources > 0
|
||||
}
|
||||
}
|
||||
default:
|
||||
simA := a.calculateMetric(&pkgA)
|
||||
simB := a.calculateMetric(&pkgB)
|
||||
cmpResult = simA > simB
|
||||
}
|
||||
|
||||
return simA > simB
|
||||
if a.bottomUp {
|
||||
cmpResult = !cmpResult
|
||||
}
|
||||
|
||||
return cmpResult
|
||||
}
|
||||
|
||||
func (s *SourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Executor, pkgS []string) {
|
||||
var aurErr error
|
||||
|
||||
pkgS = RemoveInvalidTargets(pkgS, s.targetMode)
|
||||
pkgS = RemoveInvalidTargets(s.logger, pkgS, s.targetMode)
|
||||
|
||||
metric := &metrics.Hamming{
|
||||
CaseSensitive: false,
|
||||
@ -211,12 +234,12 @@ func (s *SourceQueryBuilder) Results(dbExecutor db.Executor, verboseSearch Searc
|
||||
}
|
||||
|
||||
pkg := s.queryMap[s.results[i].source][s.results[i].name]
|
||||
if s.results[i].source == sourceAUR {
|
||||
aurPkg := pkg.(aur.Pkg)
|
||||
toPrint += aurPkgSearchString(&aurPkg, dbExecutor, s.singleLineResults)
|
||||
} else {
|
||||
syncPkg := pkg.(alpm.IPackage)
|
||||
toPrint += syncPkgSearchString(syncPkg, dbExecutor, s.singleLineResults)
|
||||
|
||||
switch pPkg := pkg.(type) {
|
||||
case aur.Pkg:
|
||||
toPrint += aurPkgSearchString(&pPkg, dbExecutor, s.singleLineResults)
|
||||
case alpm.IPackage:
|
||||
toPrint += syncPkgSearchString(pPkg, dbExecutor, s.singleLineResults)
|
||||
}
|
||||
|
||||
s.logger.Println(toPrint)
|
||||
@ -230,15 +253,15 @@ func (s *SourceQueryBuilder) Len() int {
|
||||
}
|
||||
|
||||
func (s *SourceQueryBuilder) GetTargets(include, exclude intrange.IntRanges,
|
||||
otherExclude stringset.StringSet,
|
||||
otherExclude mapset.Set[string],
|
||||
) ([]string, error) {
|
||||
var (
|
||||
isInclude = len(exclude) == 0 && len(otherExclude) == 0
|
||||
isInclude = len(exclude) == 0 && otherExclude.Cardinality() == 0
|
||||
targets []string
|
||||
lenRes = len(s.results)
|
||||
)
|
||||
|
||||
for i := 0; i <= s.Len(); i++ {
|
||||
for i := 1; i <= s.Len(); i++ {
|
||||
target := i - 1
|
||||
if s.bottomUp {
|
||||
target = lenRes - i
|
||||
@ -266,7 +289,7 @@ func matchesSearch(pkg *aur.Pkg, terms []string) bool {
|
||||
desc := strings.ToLower(pkg.Description)
|
||||
targ := strings.ToLower(pkgN)
|
||||
|
||||
if !(strings.Contains(name, targ) || strings.Contains(desc, targ)) {
|
||||
if !strings.Contains(name, targ) && !strings.Contains(desc, targ) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,362 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/aur/rpc"
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMixedSourceQueryBuilder(t *testing.T) {
|
||||
func TestSourceQueryBuilder(t *testing.T) {
|
||||
t.Parallel()
|
||||
type testCase struct {
|
||||
desc string
|
||||
bottomUp bool
|
||||
want string
|
||||
desc string
|
||||
search []string
|
||||
bottomUp bool
|
||||
separateSources bool
|
||||
sortBy string
|
||||
verbosity SearchVerbosity
|
||||
targetMode parser.TargetMode
|
||||
singleLineResults bool
|
||||
searchBy string
|
||||
wantResults []string
|
||||
wantOutput []string
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "bottomup", bottomUp: true,
|
||||
want: "\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
desc: "sort-by-votes bottomup separatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "votes",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux-ck", "linux-zen", "linux"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "topdown", bottomUp: false,
|
||||
want: "\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
desc: "sort-by-votes topdown separatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: false,
|
||||
separateSources: true,
|
||||
sortBy: "votes",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux", "linux-zen", "linux-ck"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-votes bottomup noseparatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: false,
|
||||
sortBy: "votes",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux-zen", "linux-ck", "linux"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-votes topdown noseparatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: false,
|
||||
separateSources: false,
|
||||
sortBy: "votes",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux", "linux-ck", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name bottomup separatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux-ck", "linux", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name topdown separatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: false,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux-zen", "linux", "linux-ck"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name bottomup noseparatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: false,
|
||||
sortBy: "name",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux", "linux-ck", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name topdown noseparatesources",
|
||||
search: []string{"linux"},
|
||||
bottomUp: false,
|
||||
separateSources: false,
|
||||
sortBy: "name",
|
||||
verbosity: Detailed,
|
||||
wantResults: []string{"linux-zen", "linux-ck", "linux"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-votes bottomup separatesources number-menu",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "votes",
|
||||
verbosity: NumberMenu,
|
||||
wantResults: []string{"linux-ck", "linux-zen", "linux"},
|
||||
wantOutput: []string{
|
||||
"\x1b[35m3\x1b[0m \x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[35m2\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[35m1\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-votes topdown separatesources number-menu",
|
||||
search: []string{"linux"},
|
||||
bottomUp: false,
|
||||
separateSources: true,
|
||||
sortBy: "votes",
|
||||
verbosity: NumberMenu,
|
||||
wantResults: []string{"linux", "linux-zen", "linux-ck"},
|
||||
wantOutput: []string{
|
||||
"\x1b[35m1\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[35m2\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[35m3\x1b[0m \x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name bottomup separatesources number-menu",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: NumberMenu,
|
||||
wantResults: []string{"linux-ck", "linux", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"\x1b[35m3\x1b[0m \x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[35m2\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[35m1\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name topdown separatesources number-menu",
|
||||
search: []string{"linux"},
|
||||
bottomUp: false,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: NumberMenu,
|
||||
wantResults: []string{"linux-zen", "linux", "linux-ck"},
|
||||
wantOutput: []string{
|
||||
"\x1b[35m1\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n",
|
||||
"\x1b[35m2\x1b[0m \x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n",
|
||||
"\x1b[35m3\x1b[0m \x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name bottomup noseparatesources minimal",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: false,
|
||||
sortBy: "name",
|
||||
verbosity: Minimal,
|
||||
wantResults: []string{"linux", "linux-ck", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"linux\n",
|
||||
"linux-ck\n",
|
||||
"linux-zen\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "only-aur minimal",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: Minimal,
|
||||
targetMode: parser.ModeAUR,
|
||||
wantResults: []string{"linux-ck"},
|
||||
wantOutput: []string{
|
||||
"linux-ck\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "only-repo minimal",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: Minimal,
|
||||
targetMode: parser.ModeRepo,
|
||||
wantResults: []string{"linux", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"linux\n",
|
||||
"linux-zen\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name singleline",
|
||||
search: []string{"linux"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: Detailed,
|
||||
singleLineResults: true,
|
||||
wantResults: []string{"linux-ck", "linux", "linux-zen"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\tThe Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\tThe Linux kernel and modules\n",
|
||||
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\tThe Linux ZEN kernel and modules\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sort-by-name search-by-name",
|
||||
search: []string{"linux-ck"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
sortBy: "name",
|
||||
verbosity: Detailed,
|
||||
searchBy: "name",
|
||||
targetMode: parser.ModeAUR,
|
||||
wantResults: []string{"linux-ck"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "only-aur search-by-several-terms",
|
||||
search: []string{"linux-ck", "hrtimer"},
|
||||
bottomUp: true,
|
||||
separateSources: true,
|
||||
verbosity: Detailed,
|
||||
targetMode: parser.ModeAUR,
|
||||
wantResults: []string{"linux-ck"},
|
||||
wantOutput: []string{
|
||||
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
mockDB := &mock.DBExecutor{
|
||||
SyncPackagesFn: func(pkgs ...string) []mock.IPackage {
|
||||
mockDB := mock.NewDB("core")
|
||||
return []mock.IPackage{
|
||||
&mock.Package{
|
||||
PName: "linux",
|
||||
PVersion: "5.16.0",
|
||||
PDescription: "The Linux kernel and modules",
|
||||
PSize: 1,
|
||||
PISize: 1,
|
||||
PDB: mockDB,
|
||||
},
|
||||
&mock.Package{
|
||||
PName: "linux-zen",
|
||||
PVersion: "5.16.0",
|
||||
PDescription: "The Linux ZEN kernel and modules",
|
||||
PSize: 1,
|
||||
PISize: 1,
|
||||
PDB: mockDB,
|
||||
},
|
||||
}
|
||||
},
|
||||
LocalPackageFn: func(string) mock.IPackage {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
mockAUR := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{
|
||||
{
|
||||
Description: "The Linux-ck kernel and modules with ck's hrtimer patches",
|
||||
FirstSubmitted: 1311346274,
|
||||
ID: 1045311,
|
||||
LastModified: 1646250901,
|
||||
Maintainer: "graysky",
|
||||
Name: "linux-ck",
|
||||
NumVotes: 450,
|
||||
OutOfDate: 0,
|
||||
PackageBase: "linux-ck",
|
||||
PackageBaseID: 50911,
|
||||
Popularity: 1.511141,
|
||||
URL: "https://wiki.archlinux.org/index.php/Linux-ck",
|
||||
URLPath: "/cgit/aur.git/snapshot/linux-ck.tar.gz",
|
||||
Version: "5.16.12-1",
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
client, err := rpc.NewClient(rpc.WithHTTPClient(&mockDoer{}))
|
||||
|
||||
w := &strings.Builder{}
|
||||
queryBuilder := NewSourceQueryBuilder(client,
|
||||
text.NewLogger(w, strings.NewReader(""), false, "test"),
|
||||
"votes", parser.ModeAny, "", tc.bottomUp, false, false)
|
||||
search := []string{"linux"}
|
||||
mockStore := &mockDB{}
|
||||
queryBuilder := NewSourceQueryBuilder(mockAUR,
|
||||
text.NewLogger(w, io.Discard, strings.NewReader(""), false, "test"),
|
||||
tc.sortBy, tc.targetMode, tc.searchBy, tc.bottomUp,
|
||||
tc.singleLineResults, tc.separateSources)
|
||||
|
||||
require.NoError(t, err)
|
||||
queryBuilder.Execute(context.Background(), mockStore, search)
|
||||
assert.Len(t, queryBuilder.results, 3)
|
||||
assert.Equal(t, 3, queryBuilder.Len())
|
||||
queryBuilder.Execute(context.Background(), mockDB, tc.search)
|
||||
|
||||
if tc.bottomUp {
|
||||
assert.Equal(t, "linux-zen", queryBuilder.results[0].name)
|
||||
assert.Equal(t, "linux-ck", queryBuilder.results[1].name)
|
||||
assert.Equal(t, "linux", queryBuilder.results[2].name)
|
||||
} else {
|
||||
assert.Equal(t, "linux-zen", queryBuilder.results[2].name)
|
||||
assert.Equal(t, "linux-ck", queryBuilder.results[1].name)
|
||||
assert.Equal(t, "linux", queryBuilder.results[0].name)
|
||||
assert.Len(t, queryBuilder.results, len(tc.wantResults))
|
||||
assert.Equal(t, len(tc.wantResults), queryBuilder.Len())
|
||||
for i, name := range tc.wantResults {
|
||||
assert.Equal(t, name, queryBuilder.results[i].name)
|
||||
}
|
||||
|
||||
queryBuilder.Results(mockStore, Detailed)
|
||||
queryBuilder.Results(mockDB, tc.verbosity)
|
||||
|
||||
wString := w.String()
|
||||
require.GreaterOrEqual(t, len(wString), 1, wString)
|
||||
assert.Equal(t, tc.want, wString)
|
||||
assert.Equal(t, strings.Join(tc.wantOutput, ""), w.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -7,15 +7,6 @@ import (
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
type SearchVerbosity int
|
||||
|
||||
// Verbosity settings for search.
|
||||
const (
|
||||
NumberMenu SearchVerbosity = iota
|
||||
Detailed
|
||||
Minimal
|
||||
)
|
||||
|
||||
// queryAUR searches AUR and narrows based on subarguments.
|
||||
func queryAUR(ctx context.Context,
|
||||
aurClient aur.QueryClient,
|
||||
|
@ -1,134 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/aur/rpc"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/db/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const validPayload = `{
|
||||
"resultcount": 1,
|
||||
"results": [
|
||||
{
|
||||
"Description": "The Linux-ck kernel and modules with ck's hrtimer patches",
|
||||
"FirstSubmitted": 1311346274,
|
||||
"ID": 1045311,
|
||||
"LastModified": 1646250901,
|
||||
"Maintainer": "graysky",
|
||||
"Name": "linux-ck",
|
||||
"NumVotes": 450,
|
||||
"OutOfDate": null,
|
||||
"PackageBase": "linux-ck",
|
||||
"PackageBaseID": 50911,
|
||||
"Popularity": 1.511141,
|
||||
"URL": "https://wiki.archlinux.org/index.php/Linux-ck",
|
||||
"URLPath": "/cgit/aur.git/snapshot/linux-ck.tar.gz",
|
||||
"Version": "5.16.12-1"
|
||||
}
|
||||
],
|
||||
"type": "search",
|
||||
"version": 5
|
||||
}
|
||||
`
|
||||
|
||||
type mockDB struct {
|
||||
db.Executor
|
||||
}
|
||||
|
||||
func (m *mockDB) LocalPackage(string) alpm.IPackage {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockDB) PackageGroups(pkg alpm.IPackage) []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (m *mockDB) SyncPackages(...string) []alpm.IPackage {
|
||||
mockDB := mock.NewDB("core")
|
||||
linuxRepo := &mock.Package{
|
||||
PName: "linux",
|
||||
PVersion: "5.16.0",
|
||||
PDescription: "The Linux kernel and modules",
|
||||
PSize: 1,
|
||||
PISize: 1,
|
||||
PDB: mockDB,
|
||||
}
|
||||
|
||||
linuxZen := &mock.Package{
|
||||
PName: "linux-zen",
|
||||
PVersion: "5.16.0",
|
||||
PDescription: "The Linux ZEN kernel and modules",
|
||||
PSize: 1,
|
||||
PISize: 1,
|
||||
PDB: mockDB,
|
||||
}
|
||||
|
||||
return []alpm.IPackage{linuxRepo, linuxZen}
|
||||
}
|
||||
|
||||
type mockDoer struct{}
|
||||
|
||||
func (m *mockDoer) Do(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(validPayload)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestSourceQueryBuilder(t *testing.T) {
|
||||
t.Parallel()
|
||||
type testCase struct {
|
||||
desc string
|
||||
bottomUp bool
|
||||
want string
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{desc: "bottomup", bottomUp: true, want: "\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n"},
|
||||
{
|
||||
desc: "topdown", bottomUp: false,
|
||||
want: "\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
client, err := rpc.NewClient(rpc.WithHTTPClient(&mockDoer{}))
|
||||
require.NoError(t, err)
|
||||
|
||||
queryBuilder := NewSourceQueryBuilder(client,
|
||||
text.NewLogger(io.Discard, bytes.NewBufferString(""), false, "test"),
|
||||
"votes", parser.ModeAny, "", tc.bottomUp, false, true)
|
||||
search := []string{"linux"}
|
||||
mockStore := &mockDB{}
|
||||
|
||||
queryBuilder.Execute(context.Background(), mockStore, search)
|
||||
assert.Equal(t, 3, queryBuilder.Len())
|
||||
|
||||
if tc.bottomUp {
|
||||
assert.Equal(t, "linux-ck", queryBuilder.results[0].name)
|
||||
assert.Equal(t, "linux-zen", queryBuilder.results[1].name)
|
||||
assert.Equal(t, "linux", queryBuilder.results[2].name)
|
||||
} else {
|
||||
assert.Equal(t, "linux-ck", queryBuilder.results[2].name)
|
||||
assert.Equal(t, "linux-zen", queryBuilder.results[1].name)
|
||||
assert.Equal(t, "linux", queryBuilder.results[0].name)
|
||||
}
|
||||
|
||||
queryBuilder.Results(mockStore, Detailed)
|
||||
})
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type Pkg = aur.Pkg
|
||||
|
||||
func getSearchBy(value string) aur.By {
|
||||
switch value {
|
||||
case "name":
|
||||
|
79
pkg/query/version_diff.go
Normal file
79
pkg/query/version_diff.go
Normal file
@ -0,0 +1,79 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
|
||||
func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
|
||||
if oldVersion == newVersion {
|
||||
return oldVersion + text.Red(""), newVersion + text.Green("")
|
||||
}
|
||||
|
||||
diffPosition := 0
|
||||
|
||||
checkWords := func(str string, index int, words ...string) bool {
|
||||
// Make sure the word is not part of a longer word
|
||||
ongoingWord := unicode.IsLetter(rune(str[index]))
|
||||
if ongoingWord {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, word := range words {
|
||||
wordLength := len(word)
|
||||
|
||||
nextIndex := index + 1
|
||||
if (index < len(str)-wordLength) &&
|
||||
(str[nextIndex:(nextIndex+wordLength)] == word) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for index, char := range oldVersion {
|
||||
charIsSpecial := !unicode.IsLetter(char) && !unicode.IsNumber(char)
|
||||
|
||||
if (index >= len(newVersion)) || (char != rune(newVersion[index])) {
|
||||
if charIsSpecial {
|
||||
diffPosition = index
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if charIsSpecial ||
|
||||
(((index == len(oldVersion)-1) || (index == len(newVersion)-1)) &&
|
||||
((len(oldVersion) != len(newVersion)) ||
|
||||
(oldVersion[index] == newVersion[index]))) ||
|
||||
checkWords(oldVersion, index, "rc", "pre", "alpha", "beta") {
|
||||
diffPosition = index + 1
|
||||
}
|
||||
}
|
||||
|
||||
samePart := oldVersion[0:diffPosition]
|
||||
|
||||
left = samePart + text.Red(oldVersion[diffPosition:])
|
||||
right = samePart + text.Green(newVersion[diffPosition:])
|
||||
|
||||
return left, right
|
||||
}
|
||||
|
||||
func isDevelName(name string) bool {
|
||||
for _, suffix := range []string{"git", "svn", "hg", "bzr", "nightly", "insiders-bin"} {
|
||||
if strings.HasSuffix(name, "-"+suffix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Contains(name, "-always-")
|
||||
}
|
||||
|
||||
func isDevelPackage(pkg alpm.IPackage) bool {
|
||||
return isDevelName(pkg.Name()) || isDevelName(pkg.Base())
|
||||
}
|
68
pkg/query/version_diff_test.go
Normal file
68
pkg/query/version_diff_test.go
Normal file
@ -0,0 +1,68 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func TestVersionDiff(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
a string
|
||||
b string
|
||||
wantDiff string
|
||||
}{
|
||||
{
|
||||
name: "1.0.0-1 -> 1.0.0-2",
|
||||
a: "1.0.0-1",
|
||||
b: "1.0.0-2",
|
||||
wantDiff: "1.0.0-" + text.Red("1") + " " + "1.0.0-" + text.Green("2"),
|
||||
},
|
||||
{
|
||||
name: "1.0.0-1 -> 1.0.1-1",
|
||||
a: "1.0.0-1",
|
||||
b: "1.0.1-1",
|
||||
wantDiff: "1.0." + text.Red("0-1") + " " + "1.0." + text.Green("1-1"),
|
||||
},
|
||||
{
|
||||
name: "3.0.0~alpha7-3 -> 3.0.0~alpha7-4",
|
||||
a: "3.0.0~alpha7-3",
|
||||
b: "3.0.0~alpha7-4",
|
||||
wantDiff: "3.0.0~alpha7-" + text.Red("3") + " " + "3.0.0~alpha7-" + text.Green("4"),
|
||||
},
|
||||
{
|
||||
name: "3.0.0~beta7-3 -> 3.0.0~beta8-3",
|
||||
a: "3.0.0~beta7-3",
|
||||
b: "3.0.0~beta8-3",
|
||||
wantDiff: "3.0.0~" + text.Red("beta7-3") + " " + "3.0.0~" + text.Green("beta8-3"),
|
||||
},
|
||||
{
|
||||
name: "23.04.r131.b1bfe05-1 -> 23.04.r131.b1bfe07-1",
|
||||
a: "23.04.r131.b1bfe05-1",
|
||||
b: "23.04.r131.b1bfe07-1",
|
||||
wantDiff: "23.04.r131." + text.Red("b1bfe05-1") + " " + "23.04.r131." + text.Green("b1bfe07-1"),
|
||||
},
|
||||
{
|
||||
name: "1.0.arch0-1 -> 1.0.arch1-2",
|
||||
a: "1.0.arch0-1",
|
||||
b: "1.0.arch1-2",
|
||||
wantDiff: "1.0." + text.Red("arch0-1") + " " + "1.0." + text.Green("arch1-2"),
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
originalUseColor := text.UseColor
|
||||
text.UseColor = true
|
||||
left, right := GetVersionDiff(tc.a, tc.b)
|
||||
gotDiff := left + " " + right
|
||||
if gotDiff != tc.wantDiff {
|
||||
t.Errorf("VersionDiff(%s, %s) = %s, want %s", tc.a, tc.b, gotDiff, tc.wantDiff)
|
||||
}
|
||||
text.UseColor = originalUseColor
|
||||
})
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package settings
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
func RetrievePacmanConfig(cmdArgs *parser.Arguments, pacmanConfigPath string) (*pacmanconf.Config, bool, error) {
|
||||
func retrievePacmanConfig(cmdArgs *parser.Arguments, pacmanConfigPath string) (*pacmanconf.Config, bool, error) {
|
||||
root := "/"
|
||||
if value, _, exists := cmdArgs.GetArg("root", "r"); exists {
|
||||
root = value
|
66
pkg/runtime/pacman_test.go
Normal file
66
pkg/runtime/pacman_test.go
Normal file
@ -0,0 +1,66 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
)
|
||||
|
||||
func TestPacmanConf(t *testing.T) {
|
||||
t.Parallel()
|
||||
path := "../../testdata/pacman.conf"
|
||||
|
||||
absPath, err := filepath.Abs(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
// detect the architecture of the system
|
||||
expectedArch := []string{"x86_64"}
|
||||
if runtime.GOARCH == "arm64" {
|
||||
expectedArch = []string{"aarch64"}
|
||||
}
|
||||
|
||||
expectedPacmanConf := &pacmanconf.Config{
|
||||
RootDir: "/", DBPath: "/var/lib/pacman/",
|
||||
CacheDir: []string{"/var/cache/pacman/pkg/"},
|
||||
HookDir: []string{"/etc/pacman.d/hooks/"},
|
||||
GPGDir: "/etc/pacman.d/gnupg/", LogFile: "/var/log/pacman.log",
|
||||
HoldPkg: []string{"pacman", "glibc"}, IgnorePkg: []string{"xorm"},
|
||||
IgnoreGroup: []string{"yorm"}, Architecture: expectedArch,
|
||||
XferCommand: "/usr/bin/wget --passive-ftp -c -O %o %u",
|
||||
NoUpgrade: []string(nil), NoExtract: []string(nil), CleanMethod: []string{"KeepInstalled"},
|
||||
SigLevel: []string{"PackageRequired", "PackageTrustedOnly", "DatabaseOptional", "DatabaseTrustedOnly"},
|
||||
LocalFileSigLevel: []string{"PackageOptional", "PackageTrustedOnly"},
|
||||
RemoteFileSigLevel: []string{"PackageRequired", "PackageTrustedOnly"}, UseSyslog: true,
|
||||
Color: true, UseDelta: 0, TotalDownload: false, CheckSpace: true,
|
||||
VerbosePkgLists: true, DisableDownloadTimeout: false,
|
||||
Repos: []pacmanconf.Repository{
|
||||
{
|
||||
Name: "core", Servers: []string{"Core"},
|
||||
SigLevel: []string(nil), Usage: []string{"All"},
|
||||
},
|
||||
{
|
||||
Name: "extra", Servers: []string{"Extra"}, SigLevel: []string(nil),
|
||||
Usage: []string{"All"},
|
||||
},
|
||||
{
|
||||
Name: "multilib", Servers: []string{"repo3", "multilib"},
|
||||
SigLevel: []string(nil), Usage: []string{"All"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
pacmanConf, color, err := retrievePacmanConfig(parser.MakeArguments(), absPath)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, pacmanConf)
|
||||
assert.Equal(t, color, false)
|
||||
assert.EqualValues(t, expectedPacmanConf, pacmanConf)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package settings
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"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"
|
||||
@ -21,29 +21,40 @@ import (
|
||||
"github.com/Jguer/aur/rpc"
|
||||
"github.com/Jguer/votar/pkg/vote"
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
type Runtime struct {
|
||||
Cfg *settings.Configuration
|
||||
QueryBuilder query.Builder
|
||||
PacmanConf *pacmanconf.Config
|
||||
VCSStore vcs.Store
|
||||
CmdBuilder exe.ICmdBuilder
|
||||
HTTPClient *http.Client
|
||||
AURClient *rpc.Client
|
||||
VoteClient *vote.Client
|
||||
AURCache aur.QueryClient
|
||||
DBExecutor db.Executor
|
||||
AURClient aur.QueryClient
|
||||
Logger *text.Logger
|
||||
}
|
||||
|
||||
func BuildRuntime(cfg *Configuration, cmdArgs *parser.Arguments, version string) (*Runtime, error) {
|
||||
logger := text.NewLogger(os.Stdout, os.Stdin, cfg.Debug, "runtime")
|
||||
cmdBuilder := cfg.CmdBuilder(nil)
|
||||
func NewRuntime(cfg *settings.Configuration, cmdArgs *parser.Arguments, version string) (*Runtime, error) {
|
||||
logger := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, cfg.Debug, "runtime")
|
||||
runner := exe.NewOSRunner(logger.Child("runner"))
|
||||
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
if socks5_proxy := os.Getenv("SOCKS5_PROXY"); socks5_proxy != "" {
|
||||
dialer, err := proxy.SOCKS5("tcp", socks5_proxy, nil, proxy.Direct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
transport = &http.Transport{Dial: dialer.Dial}
|
||||
}
|
||||
|
||||
httpClient := &http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
userAgent := fmt.Sprintf("Yay/%s", version)
|
||||
@ -87,6 +98,16 @@ func BuildRuntime(cfg *Configuration, cmdArgs *parser.Arguments, version string)
|
||||
aurCache = aurClient
|
||||
}
|
||||
|
||||
pacmanConf, useColor, err := retrievePacmanConfig(cmdArgs, cfg.PacmanConf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// FIXME: get rid of global
|
||||
text.UseColor = useColor
|
||||
|
||||
cmdBuilder := exe.NewCmdBuilder(cfg, runner, logger.Child("cmdbuilder"), pacmanConf.DBPath)
|
||||
|
||||
vcsStore := vcs.NewInfoStore(
|
||||
cfg.VCSFilePath, cmdBuilder,
|
||||
logger.Child("vcs"))
|
||||
@ -95,18 +116,23 @@ func BuildRuntime(cfg *Configuration, cmdArgs *parser.Arguments, version string)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
runtime := &Runtime{
|
||||
QueryBuilder: nil,
|
||||
PacmanConf: nil,
|
||||
queryBuilder := query.NewSourceQueryBuilder(
|
||||
aurClient,
|
||||
logger.Child("mixed.querybuilder"), cfg.SortBy,
|
||||
cfg.Mode, cfg.SearchBy,
|
||||
cfg.BottomUp, cfg.SingleLineResults, cfg.SeparateSources)
|
||||
|
||||
run := &Runtime{
|
||||
Cfg: cfg,
|
||||
QueryBuilder: queryBuilder,
|
||||
PacmanConf: pacmanConf,
|
||||
VCSStore: vcsStore,
|
||||
CmdBuilder: cmdBuilder,
|
||||
HTTPClient: &http.Client{},
|
||||
AURClient: aurClient,
|
||||
VoteClient: voteClient,
|
||||
AURCache: aurCache,
|
||||
DBExecutor: nil,
|
||||
Logger: text.NewLogger(os.Stdout, os.Stdin, cfg.Debug, "runtime"),
|
||||
AURClient: aurCache,
|
||||
Logger: logger,
|
||||
}
|
||||
|
||||
return runtime, nil
|
||||
return run, nil
|
||||
}
|
52
pkg/runtime/runtime_test.go
Normal file
52
pkg/runtime/runtime_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package runtime_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/runtime"
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
)
|
||||
|
||||
func TestBuildRuntime(t *testing.T) {
|
||||
t.Parallel()
|
||||
path := "../../testdata/pacman.conf"
|
||||
|
||||
absPath, err := filepath.Abs(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Prepare test inputs
|
||||
cfg := &settings.Configuration{
|
||||
Debug: true,
|
||||
UseRPC: false,
|
||||
AURURL: "https://aur.archlinux.org",
|
||||
AURRPCURL: "https://aur.archlinux.org/rpc",
|
||||
BuildDir: "/tmp",
|
||||
VCSFilePath: "",
|
||||
PacmanConf: absPath,
|
||||
}
|
||||
cmdArgs := parser.MakeArguments()
|
||||
version := "1.0.0"
|
||||
|
||||
// Call the function being tested
|
||||
run, err := runtime.NewRuntime(cfg, cmdArgs, version)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert the function's output
|
||||
assert.NotNil(t, run)
|
||||
assert.NotNil(t, run.QueryBuilder)
|
||||
assert.NotNil(t, run.PacmanConf)
|
||||
assert.NotNil(t, run.VCSStore)
|
||||
assert.NotNil(t, run.CmdBuilder)
|
||||
assert.NotNil(t, run.HTTPClient)
|
||||
assert.NotNil(t, run.VoteClient)
|
||||
assert.NotNil(t, run.AURClient)
|
||||
assert.NotNil(t, run.Logger)
|
||||
}
|
@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func (c *Configuration) ParseCommandLine(a *parser.Arguments) error {
|
||||
@ -15,9 +14,6 @@ func (c *Configuration) ParseCommandLine(a *parser.Arguments) error {
|
||||
|
||||
c.extractYayOptions(a)
|
||||
|
||||
// Reload CmdBuilder
|
||||
c.Runtime.CmdBuilder = c.CmdBuilder(nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -46,29 +42,29 @@ func (c *Configuration) extractYayOptions(a *parser.Arguments) {
|
||||
}
|
||||
|
||||
func (c *Configuration) handleOption(option, value string) bool {
|
||||
boolValue, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
boolValue = true
|
||||
}
|
||||
|
||||
switch option {
|
||||
case "aururl":
|
||||
c.AURURL = value
|
||||
case "aurrpcurl":
|
||||
c.AURRPCURL = value
|
||||
case "save":
|
||||
c.SaveConfig = true
|
||||
c.SaveConfig = boolValue
|
||||
case "afterclean", "cleanafter":
|
||||
c.CleanAfter = true
|
||||
case "noafterclean", "nocleanafter":
|
||||
c.CleanAfter = false
|
||||
c.CleanAfter = boolValue
|
||||
case "keepsrc":
|
||||
c.KeepSrc = boolValue
|
||||
case "debug":
|
||||
c.Debug = true
|
||||
text.GlobalLogger.Debug = true
|
||||
return false
|
||||
c.Debug = boolValue
|
||||
return !boolValue
|
||||
case "devel":
|
||||
c.Devel = true
|
||||
case "nodevel":
|
||||
c.Devel = false
|
||||
c.Devel = boolValue
|
||||
case "timeupdate":
|
||||
c.TimeUpdate = true
|
||||
case "notimeupdate":
|
||||
c.TimeUpdate = false
|
||||
c.TimeUpdate = boolValue
|
||||
case "topdown":
|
||||
c.BottomUp = false
|
||||
case "bottomup":
|
||||
@ -87,7 +83,7 @@ func (c *Configuration) handleOption(option, value string) bool {
|
||||
case "searchby":
|
||||
c.SearchBy = value
|
||||
case "noconfirm":
|
||||
NoConfirm = true
|
||||
NoConfirm = boolValue
|
||||
case "config":
|
||||
c.PacmanConf = value
|
||||
case "redownload":
|
||||
@ -97,17 +93,15 @@ func (c *Configuration) handleOption(option, value string) bool {
|
||||
case "noredownload":
|
||||
c.ReDownload = "no"
|
||||
case "rebuild":
|
||||
c.ReBuild = "yes"
|
||||
c.ReBuild = parser.RebuildModeYes
|
||||
case "rebuildall":
|
||||
c.ReBuild = "all"
|
||||
c.ReBuild = parser.RebuildModeAll
|
||||
case "rebuildtree":
|
||||
c.ReBuild = "tree"
|
||||
c.ReBuild = parser.RebuildModeTree
|
||||
case "norebuild":
|
||||
c.ReBuild = "no"
|
||||
c.ReBuild = parser.RebuildModeNo
|
||||
case "batchinstall":
|
||||
c.BatchInstall = true
|
||||
case "nobatchinstall":
|
||||
c.BatchInstall = false
|
||||
c.BatchInstall = boolValue
|
||||
case "answerclean":
|
||||
c.AnswerClean = value
|
||||
case "noanswerclean":
|
||||
@ -158,44 +152,24 @@ func (c *Configuration) handleOption(option, value string) bool {
|
||||
c.RequestSplitN = n
|
||||
}
|
||||
case "sudoloop":
|
||||
c.SudoLoop = true
|
||||
case "nosudoloop":
|
||||
c.SudoLoop = false
|
||||
c.SudoLoop = boolValue
|
||||
case "provides":
|
||||
c.Provides = true
|
||||
case "noprovides":
|
||||
c.Provides = false
|
||||
c.Provides = boolValue
|
||||
case "pgpfetch":
|
||||
c.PGPFetch = true
|
||||
case "nopgpfetch":
|
||||
c.PGPFetch = false
|
||||
case "upgrademenu":
|
||||
c.UpgradeMenu = true
|
||||
case "noupgrademenu":
|
||||
c.UpgradeMenu = false
|
||||
c.PGPFetch = boolValue
|
||||
case "cleanmenu":
|
||||
c.CleanMenu = true
|
||||
case "nocleanmenu":
|
||||
c.CleanMenu = false
|
||||
c.CleanMenu = boolValue
|
||||
case "diffmenu":
|
||||
c.DiffMenu = true
|
||||
case "nodiffmenu":
|
||||
c.DiffMenu = false
|
||||
c.DiffMenu = boolValue
|
||||
case "editmenu":
|
||||
c.EditMenu = true
|
||||
case "noeditmenu":
|
||||
c.EditMenu = false
|
||||
c.EditMenu = boolValue
|
||||
case "useask":
|
||||
c.UseAsk = true
|
||||
case "nouseask":
|
||||
c.UseAsk = false
|
||||
c.UseAsk = boolValue
|
||||
case "combinedupgrade":
|
||||
c.CombinedUpgrade = true
|
||||
case "nocombinedupgrade":
|
||||
c.CombinedUpgrade = false
|
||||
c.CombinedUpgrade = boolValue
|
||||
case "a", "aur":
|
||||
c.Mode = parser.ModeAUR
|
||||
case "repo":
|
||||
case "N", "repo":
|
||||
c.Mode = parser.ModeRepo
|
||||
case "removemake":
|
||||
c.RemoveMake = "yes"
|
||||
@ -203,10 +177,10 @@ func (c *Configuration) handleOption(option, value string) bool {
|
||||
c.RemoveMake = "no"
|
||||
case "askremovemake":
|
||||
c.RemoveMake = "ask"
|
||||
case "askyesremovemake":
|
||||
c.RemoveMake = "askyes"
|
||||
case "separatesources":
|
||||
c.SeparateSources = true
|
||||
case "noseparatesources":
|
||||
c.SeparateSources = false
|
||||
c.SeparateSources = boolValue
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
@ -24,61 +23,60 @@ var NoConfirm = false
|
||||
|
||||
// Configuration stores yay's config.
|
||||
type Configuration struct {
|
||||
Runtime *Runtime `json:"-"`
|
||||
AURURL string `json:"aururl"`
|
||||
AURRPCURL string `json:"aurrpcurl"`
|
||||
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"`
|
||||
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"`
|
||||
SearchBy string `json:"searchby"`
|
||||
GitFlags string `json:"gitflags"`
|
||||
RemoveMake string `json:"removemake"`
|
||||
SudoBin string `json:"sudobin"`
|
||||
SudoFlags string `json:"sudoflags"`
|
||||
Version string `json:"version"`
|
||||
RequestSplitN int `json:"requestsplitn"`
|
||||
CompletionInterval int `json:"completionrefreshtime"`
|
||||
MaxConcurrentDownloads int `json:"maxconcurrentdownloads"`
|
||||
BottomUp bool `json:"bottomup"`
|
||||
SudoLoop bool `json:"sudoloop"`
|
||||
TimeUpdate bool `json:"timeupdate"`
|
||||
Devel bool `json:"devel"`
|
||||
CleanAfter bool `json:"cleanAfter"`
|
||||
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"`
|
||||
BatchInstall bool `json:"batchinstall"`
|
||||
SingleLineResults bool `json:"singlelineresults"`
|
||||
SeparateSources bool `json:"separatesources"`
|
||||
NewInstallEngine bool `json:"newinstallengine"`
|
||||
Debug bool `json:"debug"`
|
||||
UseRPC bool `json:"rpc"`
|
||||
AURURL string `json:"aururl"`
|
||||
AURRPCURL string `json:"aurrpcurl"`
|
||||
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"`
|
||||
ReDownload string `json:"redownload"`
|
||||
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"`
|
||||
SearchBy string `json:"searchby"`
|
||||
GitFlags string `json:"gitflags"`
|
||||
RemoveMake string `json:"removemake"`
|
||||
SudoBin string `json:"sudobin"`
|
||||
SudoFlags string `json:"sudoflags"`
|
||||
Version string `json:"version"`
|
||||
RequestSplitN int `json:"requestsplitn"`
|
||||
CompletionInterval int `json:"completionrefreshtime"`
|
||||
MaxConcurrentDownloads int `json:"maxconcurrentdownloads"`
|
||||
BottomUp bool `json:"bottomup"`
|
||||
SudoLoop bool `json:"sudoloop"`
|
||||
TimeUpdate bool `json:"timeupdate"`
|
||||
Devel bool `json:"devel"`
|
||||
CleanAfter bool `json:"cleanAfter"`
|
||||
KeepSrc bool `json:"keepSrc"`
|
||||
Provides bool `json:"provides"`
|
||||
PGPFetch bool `json:"pgpfetch"`
|
||||
CleanMenu bool `json:"cleanmenu"`
|
||||
DiffMenu bool `json:"diffmenu"`
|
||||
EditMenu bool `json:"editmenu"`
|
||||
CombinedUpgrade bool `json:"combinedupgrade"`
|
||||
UseAsk bool `json:"useask"`
|
||||
BatchInstall bool `json:"batchinstall"`
|
||||
SingleLineResults bool `json:"singlelineresults"`
|
||||
SeparateSources bool `json:"separatesources"`
|
||||
Debug bool `json:"debug"`
|
||||
UseRPC bool `json:"rpc"`
|
||||
DoubleConfirm bool `json:"doubleconfirm"` // confirm install before and after build
|
||||
|
||||
CompletionPath string `json:"-"`
|
||||
VCSFilePath string `json:"-"`
|
||||
// ConfigPath string `json:"-"`
|
||||
SaveConfig bool `json:"-"`
|
||||
Mode parser.TargetMode `json:"-"`
|
||||
SaveConfig bool `json:"-"`
|
||||
Mode parser.TargetMode `json:"-"`
|
||||
ReBuild parser.RebuildMode `json:"rebuild"`
|
||||
}
|
||||
|
||||
// SaveConfig writes yay config to file.
|
||||
@ -132,7 +130,7 @@ func (c *Configuration) expandEnv() {
|
||||
c.SudoBin = expandEnvOrHome(c.SudoBin)
|
||||
c.SudoFlags = os.ExpandEnv(c.SudoFlags)
|
||||
c.ReDownload = os.ExpandEnv(c.ReDownload)
|
||||
c.ReBuild = os.ExpandEnv(c.ReBuild)
|
||||
c.ReBuild = parser.RebuildMode(os.ExpandEnv(string(c.ReBuild)))
|
||||
c.AnswerClean = os.ExpandEnv(c.AnswerClean)
|
||||
c.AnswerDiff = os.ExpandEnv(c.AnswerDiff)
|
||||
c.AnswerEdit = os.ExpandEnv(c.AnswerEdit)
|
||||
@ -196,6 +194,7 @@ func DefaultConfig(version string) *Configuration {
|
||||
AURURL: "https://aur.archlinux.org",
|
||||
BuildDir: os.ExpandEnv("$HOME/.cache/yay"),
|
||||
CleanAfter: false,
|
||||
KeepSrc: false,
|
||||
Editor: "",
|
||||
EditorFlags: "",
|
||||
Devel: false,
|
||||
@ -209,7 +208,7 @@ func DefaultConfig(version string) *Configuration {
|
||||
GitFlags: "",
|
||||
BottomUp: true,
|
||||
CompletionInterval: 7,
|
||||
MaxConcurrentDownloads: 0,
|
||||
MaxConcurrentDownloads: 1,
|
||||
SortBy: "votes",
|
||||
SearchBy: "name-desc",
|
||||
SudoLoop: false,
|
||||
@ -228,30 +227,26 @@ func DefaultConfig(version string) *Configuration {
|
||||
AnswerUpgrade: "",
|
||||
RemoveMake: "ask",
|
||||
Provides: true,
|
||||
UpgradeMenu: true,
|
||||
CleanMenu: true,
|
||||
DiffMenu: true,
|
||||
EditMenu: false,
|
||||
UseAsk: false,
|
||||
CombinedUpgrade: false,
|
||||
CombinedUpgrade: true,
|
||||
SeparateSources: true,
|
||||
NewInstallEngine: true,
|
||||
Version: version,
|
||||
Debug: false,
|
||||
UseRPC: true,
|
||||
Runtime: &Runtime{
|
||||
Logger: text.GlobalLogger,
|
||||
},
|
||||
Mode: parser.ModeAny,
|
||||
DoubleConfirm: true,
|
||||
Mode: parser.ModeAny,
|
||||
}
|
||||
}
|
||||
|
||||
func NewConfig(configPath, version string) (*Configuration, error) {
|
||||
func NewConfig(logger *text.Logger, configPath, version string) (*Configuration, error) {
|
||||
newConfig := DefaultConfig(version)
|
||||
|
||||
cacheHome, errCache := getCacheHome()
|
||||
if errCache != nil {
|
||||
text.Errorln(errCache)
|
||||
if errCache != nil && logger != nil {
|
||||
logger.Errorln(errCache)
|
||||
}
|
||||
|
||||
newConfig.BuildDir = cacheHome
|
||||
@ -297,27 +292,3 @@ func (c *Configuration) load(configPath string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Configuration) CmdBuilder(runner exe.Runner) exe.ICmdBuilder {
|
||||
if runner == nil {
|
||||
runner = &exe.OSRunner{Log: c.Runtime.Logger.Child("runner")}
|
||||
}
|
||||
|
||||
return &exe.CmdBuilder{
|
||||
GitBin: c.GitBin,
|
||||
GitFlags: strings.Fields(c.GitFlags),
|
||||
GPGBin: c.GpgBin,
|
||||
GPGFlags: strings.Fields(c.GpgFlags),
|
||||
MakepkgFlags: strings.Fields(c.MFlags),
|
||||
MakepkgConfPath: c.MakepkgConf,
|
||||
MakepkgBin: c.MakepkgBin,
|
||||
SudoBin: c.SudoBin,
|
||||
SudoFlags: strings.Fields(c.SudoFlags),
|
||||
SudoLoopEnabled: c.SudoLoop,
|
||||
PacmanBin: c.PacmanBin,
|
||||
PacmanConfigPath: c.PacmanConf,
|
||||
PacmanDBPath: "",
|
||||
Runner: runner,
|
||||
Log: c.Runtime.Logger.Child("cmd_builder"),
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
@ -33,7 +36,7 @@ func TestNewConfig(t *testing.T) {
|
||||
_, err = f.WriteString(string(configJSON))
|
||||
assert.NoError(t, err)
|
||||
|
||||
newConfig, err := NewConfig(GetConfigPath(), "v1.0.0")
|
||||
newConfig, err := NewConfig(nil, GetConfigPath(), "v1.0.0")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, filepath.Join(cacheDir, "test-build-dir"), newConfig.BuildDir)
|
||||
@ -66,7 +69,7 @@ func TestNewConfigAURDEST(t *testing.T) {
|
||||
_, err = f.WriteString(string(configJSON))
|
||||
assert.NoError(t, err)
|
||||
|
||||
newConfig, err := NewConfig(GetConfigPath(), "v1.0.0")
|
||||
newConfig, err := NewConfig(nil, GetConfigPath(), "v1.0.0")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, filepath.Join(cacheDir, "test-build-dir"), newConfig.BuildDir)
|
||||
@ -99,7 +102,7 @@ func TestNewConfigAURDESTTildeExpansion(t *testing.T) {
|
||||
_, err = f.WriteString(string(configJSON))
|
||||
assert.NoError(t, err)
|
||||
|
||||
newConfig, err := NewConfig(GetConfigPath(), "v1.0.0")
|
||||
newConfig, err := NewConfig(nil, GetConfigPath(), "v1.0.0")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, filepath.Join(homeDir, "test-build-dir"), newConfig.BuildDir)
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
@ -38,7 +39,7 @@ type ICmdBuilder interface {
|
||||
BuildMakepkgCmd(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd
|
||||
BuildPacmanCmd(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd
|
||||
AddMakepkgFlag(string)
|
||||
SetPacmanDBPath(string)
|
||||
GetKeepSrc() bool
|
||||
SudoLoop()
|
||||
}
|
||||
|
||||
@ -56,10 +57,32 @@ type CmdBuilder struct {
|
||||
PacmanBin string
|
||||
PacmanConfigPath string
|
||||
PacmanDBPath string
|
||||
KeepSrc bool
|
||||
Runner Runner
|
||||
Log *text.Logger
|
||||
}
|
||||
|
||||
func NewCmdBuilder(cfg *settings.Configuration, runner Runner, logger *text.Logger, dbPath string) *CmdBuilder {
|
||||
return &CmdBuilder{
|
||||
GitBin: cfg.GitBin,
|
||||
GitFlags: strings.Fields(cfg.GitFlags),
|
||||
GPGBin: cfg.GpgBin,
|
||||
GPGFlags: strings.Fields(cfg.GpgFlags),
|
||||
MakepkgFlags: strings.Fields(cfg.MFlags),
|
||||
MakepkgConfPath: cfg.MakepkgConf,
|
||||
MakepkgBin: cfg.MakepkgBin,
|
||||
SudoBin: cfg.SudoBin,
|
||||
SudoFlags: strings.Fields(cfg.SudoFlags),
|
||||
SudoLoopEnabled: cfg.SudoLoop,
|
||||
PacmanBin: cfg.PacmanBin,
|
||||
PacmanConfigPath: cfg.PacmanConf,
|
||||
PacmanDBPath: dbPath,
|
||||
KeepSrc: cfg.KeepSrc,
|
||||
Runner: runner,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CmdBuilder) BuildGPGCmd(ctx context.Context, extraArgs ...string) *exec.Cmd {
|
||||
args := make([]string, len(c.GPGFlags), len(c.GPGFlags)+len(extraArgs))
|
||||
copy(args, c.GPGFlags)
|
||||
@ -135,10 +158,6 @@ func (c *CmdBuilder) BuildMakepkgCmd(ctx context.Context, dir string, extraArgs
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *CmdBuilder) SetPacmanDBPath(dbPath string) {
|
||||
c.PacmanDBPath = dbPath
|
||||
}
|
||||
|
||||
// deElevateCommand, `systemd-run` code based on pikaur.
|
||||
func (c *CmdBuilder) deElevateCommand(ctx context.Context, cmd *exec.Cmd) *exec.Cmd {
|
||||
if os.Geteuid() != 0 {
|
||||
@ -154,11 +173,12 @@ func (c *CmdBuilder) deElevateCommand(ctx context.Context, cmd *exec.Cmd) *exec.
|
||||
|
||||
if userFound, err := user.Lookup(ogCaller); err == nil {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
uid, _ := strconv.Atoi(userFound.Uid)
|
||||
gid, _ := strconv.Atoi(userFound.Gid)
|
||||
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||
|
||||
return cmd
|
||||
uid64, errUid := strconv.ParseUint(userFound.Uid, 10, 32)
|
||||
gid64, errGid := strconv.ParseUint(userFound.Gid, 10, 32)
|
||||
if errUid == nil && errGid == nil {
|
||||
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid64), Gid: uint32(gid64)}
|
||||
return cmd
|
||||
}
|
||||
}
|
||||
|
||||
cmdArgs := []string{
|
||||
@ -242,7 +262,7 @@ func (c *CmdBuilder) waitLock(dbPath string) {
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
if _, err := os.Stat(lockDBPath); err != nil {
|
||||
fmt.Println()
|
||||
c.Log.Println()
|
||||
|
||||
return
|
||||
}
|
||||
@ -280,3 +300,7 @@ func (c *CmdBuilder) Show(cmd *exec.Cmd) error {
|
||||
func (c *CmdBuilder) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) {
|
||||
return c.Runner.Capture(cmd)
|
||||
}
|
||||
|
||||
func (c *CmdBuilder) GetKeepSrc() bool {
|
||||
return c.KeepSrc
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ type OSRunner struct {
|
||||
Log *text.Logger
|
||||
}
|
||||
|
||||
func NewOSRunner(log *text.Logger) *OSRunner {
|
||||
return &OSRunner{log}
|
||||
}
|
||||
|
||||
func (r *OSRunner) Show(cmd *exec.Cmd) error {
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"sync"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
)
|
||||
@ -19,17 +20,25 @@ func (c *Call) String() string {
|
||||
}
|
||||
|
||||
type MockBuilder struct {
|
||||
Runner Runner
|
||||
BuildMakepkgCmdCalls []Call
|
||||
BuildMakepkgCmdFn func(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd
|
||||
BuildPacmanCmdFn func(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd
|
||||
Runner Runner
|
||||
BuildMakepkgCmdCallsMu sync.Mutex
|
||||
BuildMakepkgCmdCalls []Call
|
||||
BuildMakepkgCmdFn func(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd
|
||||
BuildPacmanCmdFn func(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd
|
||||
GetKeepSrcFn func() bool
|
||||
}
|
||||
|
||||
type MockRunner struct {
|
||||
ShowCalls []Call
|
||||
CaptureCalls []Call
|
||||
ShowFn func(cmd *exec.Cmd) error
|
||||
CaptureFn func(cmd *exec.Cmd) (stdout string, stderr string, err error)
|
||||
ShowCallsMu sync.Mutex
|
||||
ShowCalls []Call
|
||||
CaptureCallsMu sync.Mutex
|
||||
CaptureCalls []Call
|
||||
ShowFn func(cmd *exec.Cmd) error
|
||||
CaptureFn func(cmd *exec.Cmd) (stdout string, stderr string, err error)
|
||||
}
|
||||
|
||||
func (m *MockBuilder) BuildGPGCmd(ctx context.Context, extraArgs ...string) *exec.Cmd {
|
||||
return exec.CommandContext(ctx, "gpg", extraArgs...)
|
||||
}
|
||||
|
||||
func (m *MockBuilder) BuildMakepkgCmd(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd {
|
||||
@ -40,6 +49,7 @@ func (m *MockBuilder) BuildMakepkgCmd(ctx context.Context, dir string, extraArgs
|
||||
res = exec.CommandContext(ctx, "makepkg", extraArgs...)
|
||||
}
|
||||
|
||||
m.BuildMakepkgCmdCallsMu.Lock()
|
||||
m.BuildMakepkgCmdCalls = append(m.BuildMakepkgCmdCalls, Call{
|
||||
Res: []interface{}{res},
|
||||
Args: []interface{}{
|
||||
@ -48,6 +58,7 @@ func (m *MockBuilder) BuildMakepkgCmd(ctx context.Context, dir string, extraArgs
|
||||
extraArgs,
|
||||
},
|
||||
})
|
||||
m.BuildMakepkgCmdCallsMu.Unlock()
|
||||
|
||||
return res
|
||||
}
|
||||
@ -85,13 +96,19 @@ func (m *MockBuilder) Show(cmd *exec.Cmd) error {
|
||||
return m.Runner.Show(cmd)
|
||||
}
|
||||
|
||||
func (m *MockBuilder) GetKeepSrc() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *MockRunner) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) {
|
||||
m.CaptureCallsMu.Lock()
|
||||
m.CaptureCalls = append(m.CaptureCalls, Call{
|
||||
Args: []interface{}{
|
||||
cmd,
|
||||
},
|
||||
Dir: cmd.Dir,
|
||||
})
|
||||
m.CaptureCallsMu.Unlock()
|
||||
|
||||
if m.CaptureFn != nil {
|
||||
return m.CaptureFn(cmd)
|
||||
@ -106,12 +123,14 @@ func (m *MockRunner) Show(cmd *exec.Cmd) error {
|
||||
err = m.ShowFn(cmd)
|
||||
}
|
||||
|
||||
m.ShowCallsMu.Lock()
|
||||
m.ShowCalls = append(m.ShowCalls, Call{
|
||||
Args: []interface{}{
|
||||
cmd,
|
||||
},
|
||||
Dir: cmd.Dir,
|
||||
})
|
||||
m.ShowCallsMu.Unlock()
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func DefaultMigrations() []configMigration {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Configuration) RunMigrations(migrations []configMigration,
|
||||
func (c *Configuration) RunMigrations(logger *text.Logger, migrations []configMigration,
|
||||
configPath, newVersion string,
|
||||
) error {
|
||||
saveConfig := false
|
||||
@ -53,7 +53,7 @@ func (c *Configuration) RunMigrations(migrations []configMigration,
|
||||
for _, migration := range migrations {
|
||||
if db.VerCmp(migration.TargetVersion(), c.Version) > 0 {
|
||||
if migration.Do(c) {
|
||||
text.Infoln("Config migration executed (",
|
||||
logger.Infoln("Config migration executed (",
|
||||
migration.TargetVersion(), "):", migration)
|
||||
|
||||
saveConfig = true
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
@ -13,6 +16,10 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func newTestLogger() *text.Logger {
|
||||
return text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), true, "test")
|
||||
}
|
||||
|
||||
func TestMigrationNothingToDo(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Create temporary file for config
|
||||
@ -25,13 +32,10 @@ func TestMigrationNothingToDo(t *testing.T) {
|
||||
config := Configuration{
|
||||
Version: "99.0.0",
|
||||
// Create runtime with runtimeVersion
|
||||
Runtime: &Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), false, "test"),
|
||||
},
|
||||
}
|
||||
|
||||
// Run Migration
|
||||
err = config.RunMigrations(DefaultMigrations(), testFilePath, "20.0.0")
|
||||
err = config.RunMigrations(newTestLogger(), DefaultMigrations(), testFilePath, "20.0.0")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check file contents if wantSave otherwise check file empty
|
||||
@ -50,9 +54,6 @@ func TestProvidesMigrationDo(t *testing.T) {
|
||||
migration := &configProviderMigration{}
|
||||
config := Configuration{
|
||||
Provides: true,
|
||||
Runtime: &Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), false, "test"),
|
||||
},
|
||||
}
|
||||
|
||||
assert.True(t, migration.Do(&config))
|
||||
@ -132,13 +133,10 @@ func TestProvidesMigration(t *testing.T) {
|
||||
Version: tc.testConfig.Version,
|
||||
Provides: tc.testConfig.Provides,
|
||||
// Create runtime with runtimeVersion
|
||||
Runtime: &Runtime{
|
||||
Logger: text.NewLogger(io.Discard, strings.NewReader(""), false, "test"),
|
||||
},
|
||||
}
|
||||
|
||||
// Run Migration
|
||||
err = tcConfig.RunMigrations(
|
||||
err = tcConfig.RunMigrations(newTestLogger(),
|
||||
[]configMigration{&configProviderMigration{}},
|
||||
testFilePath, tc.newVersion)
|
||||
|
||||
|
@ -1,51 +0,0 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
)
|
||||
|
||||
func TestPacmanConf(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
expectedPacmanConf := &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: false,
|
||||
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"}},
|
||||
},
|
||||
}
|
||||
|
||||
pacmanConf, color, err := RetrievePacmanConfig(parser.MakeArguments(), "../../testdata/pacman.conf")
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, pacmanConf)
|
||||
assert.Equal(t, color, false)
|
||||
assert.EqualValues(t, expectedPacmanConf, pacmanConf)
|
||||
}
|
@ -25,7 +25,7 @@ func (o *Option) Add(args ...string) {
|
||||
}
|
||||
|
||||
func (o *Option) First() string {
|
||||
if o.Args == nil || len(o.Args) == 0 {
|
||||
if len(o.Args) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -372,16 +372,15 @@ func isArg(arg string) bool {
|
||||
case "y", "refresh":
|
||||
case "x", "regex":
|
||||
case "machinereadable":
|
||||
case "disable-sandbox":
|
||||
// yay options
|
||||
case "aururl":
|
||||
case "aurrpcurl":
|
||||
case "save":
|
||||
case "afterclean", "cleanafter":
|
||||
case "noafterclean", "nocleanafter":
|
||||
case "keepsrc":
|
||||
case "devel":
|
||||
case "nodevel":
|
||||
case "timeupdate":
|
||||
case "notimeupdate":
|
||||
case "topdown":
|
||||
case "bottomup":
|
||||
case "completioninterval":
|
||||
@ -395,7 +394,6 @@ func isArg(arg string) bool {
|
||||
case "rebuildtree":
|
||||
case "norebuild":
|
||||
case "batchinstall":
|
||||
case "nobatchinstall":
|
||||
case "answerclean":
|
||||
case "noanswerclean":
|
||||
case "answerdiff":
|
||||
@ -420,28 +418,19 @@ func isArg(arg string) bool {
|
||||
case "sudoflags":
|
||||
case "requestsplitn":
|
||||
case "sudoloop":
|
||||
case "nosudoloop":
|
||||
case "provides":
|
||||
case "noprovides":
|
||||
case "pgpfetch":
|
||||
case "nopgpfetch":
|
||||
case "upgrademenu":
|
||||
case "noupgrademenu":
|
||||
case "cleanmenu":
|
||||
case "nocleanmenu":
|
||||
case "diffmenu":
|
||||
case "nodiffmenu":
|
||||
case "editmenu":
|
||||
case "noeditmenu":
|
||||
case "useask":
|
||||
case "nouseask":
|
||||
case "combinedupgrade":
|
||||
case "nocombinedupgrade":
|
||||
case "a", "aur":
|
||||
case "repo":
|
||||
case "N", "repo":
|
||||
case "removemake":
|
||||
case "noremovemake":
|
||||
case "askremovemake":
|
||||
case "askyesremovemake":
|
||||
case "complete":
|
||||
case "stats":
|
||||
case "news":
|
||||
@ -450,7 +439,7 @@ func isArg(arg string) bool {
|
||||
case "defaultconfig":
|
||||
case "singlelineresults":
|
||||
case "doublelineresults":
|
||||
case "separatesources", "noseparatesources":
|
||||
case "separatesources":
|
||||
default:
|
||||
return false
|
||||
}
|
||||
@ -576,7 +565,6 @@ func (a *Arguments) parseShortOption(arg, param string) (usedNext bool, err erro
|
||||
break
|
||||
} else {
|
||||
err = a.AddArg(char)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package parser
|
||||
|
||||
import (
|
||||
|
10
pkg/settings/parser/rebuild_mode.go
Normal file
10
pkg/settings/parser/rebuild_mode.go
Normal file
@ -0,0 +1,10 @@
|
||||
package parser
|
||||
|
||||
type RebuildMode string
|
||||
|
||||
const (
|
||||
RebuildModeNo RebuildMode = "no"
|
||||
RebuildModeYes RebuildMode = "yes"
|
||||
RebuildModeTree RebuildMode = "tree"
|
||||
RebuildModeAll RebuildMode = "all"
|
||||
)
|
@ -1,107 +0,0 @@
|
||||
package stringset
|
||||
|
||||
// StringSet is a basic set implementation for strings.
|
||||
// This is used a lot so it deserves its own type.
|
||||
// Other types of sets are used throughout the code but do not have
|
||||
// their own typedef.
|
||||
// String sets and <type>sets should be used throughout the code when applicable,
|
||||
// they are a lot more flexible than slices and provide easy lookup.
|
||||
type StringSet map[string]struct{}
|
||||
|
||||
// MapStringSet is a Map of StringSets.
|
||||
type MapStringSet map[string]StringSet
|
||||
|
||||
// Add adds a new value to the Map.
|
||||
// If n is already in the map, then v is appended to the StringSet under that key.
|
||||
// Otherwise a new StringSet is creayed containing v.
|
||||
func (mss MapStringSet) Add(n, v string) {
|
||||
if _, ok := mss[n]; !ok {
|
||||
mss[n] = make(StringSet)
|
||||
}
|
||||
|
||||
mss[n].Set(v)
|
||||
}
|
||||
|
||||
// Set sets key in StringSet.
|
||||
func (set StringSet) Set(v string) {
|
||||
set[v] = struct{}{}
|
||||
}
|
||||
|
||||
// Extend sets multiple keys in StringSet.
|
||||
func (set StringSet) Extend(s ...string) {
|
||||
for _, v := range s {
|
||||
set[v] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns true if the key exists in the set.
|
||||
func (set StringSet) Get(v string) bool {
|
||||
_, exists := set[v]
|
||||
return exists
|
||||
}
|
||||
|
||||
// Remove deletes a key from the set.
|
||||
func (set StringSet) Remove(v string) {
|
||||
delete(set, v)
|
||||
}
|
||||
|
||||
// ToSlice turns all keys into a string slice.
|
||||
func (set StringSet) ToSlice() []string {
|
||||
slice := make([]string, 0, len(set))
|
||||
|
||||
for v := range set {
|
||||
slice = append(slice, v)
|
||||
}
|
||||
|
||||
return slice
|
||||
}
|
||||
|
||||
// Copy copies a StringSet into a new structure of the same type.
|
||||
func (set StringSet) Copy() StringSet {
|
||||
newSet := make(StringSet)
|
||||
|
||||
for str := range set {
|
||||
newSet.Set(str)
|
||||
}
|
||||
|
||||
return newSet
|
||||
}
|
||||
|
||||
// FromSlice creates a new StringSet from an input slice.
|
||||
func FromSlice(in []string) StringSet {
|
||||
set := make(StringSet)
|
||||
|
||||
for _, v := range in {
|
||||
set.Set(v)
|
||||
}
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
// Make creates a new StringSet from a set of arguments.
|
||||
func Make(in ...string) StringSet {
|
||||
return FromSlice(in)
|
||||
}
|
||||
|
||||
// Equal compares if two StringSets have the same values.
|
||||
func Equal(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
|
||||
}
|
67
pkg/sync/build/errors.go
Normal file
67
pkg/sync/build/errors.go
Normal file
@ -0,0 +1,67 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
)
|
||||
|
||||
var ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
|
||||
|
||||
type FailedIgnoredPkgError struct {
|
||||
pkgErrors map[string]error
|
||||
}
|
||||
|
||||
func (e *FailedIgnoredPkgError) Error() string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(gotext.Get("Failed to install the following packages. Manual intervention is required:"))
|
||||
|
||||
for pkg, err := range e.pkgErrors {
|
||||
sb.WriteString("\n")
|
||||
sb.WriteString(pkg)
|
||||
sb.WriteString(" - ")
|
||||
sb.WriteString(err.Error())
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
type PkgDestNotInListError struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (e *PkgDestNotInListError) Error() string {
|
||||
return gotext.Get("could not find PKGDEST for: %s", e.name)
|
||||
}
|
||||
|
||||
type FindPkgDestError struct {
|
||||
name, pkgDest string
|
||||
}
|
||||
|
||||
func (e *FindPkgDestError) Error() string {
|
||||
return gotext.Get(
|
||||
"the PKGDEST for %s is listed by makepkg but does not exist: %s",
|
||||
e.name, e.pkgDest)
|
||||
}
|
||||
|
||||
type SetPkgReasonError struct {
|
||||
exp bool // explicit
|
||||
}
|
||||
|
||||
func (e *SetPkgReasonError) Error() string {
|
||||
reason := gotext.Get("explicit")
|
||||
if !e.exp {
|
||||
reason = gotext.Get("dependency")
|
||||
}
|
||||
|
||||
return gotext.Get("error updating package install reason to %s", reason)
|
||||
}
|
||||
|
||||
type NoPkgDestsFoundError struct {
|
||||
dir string
|
||||
}
|
||||
|
||||
func (e *NoPkgDestsFoundError) Error() string {
|
||||
return gotext.Get("could not find any package archives listed in %s", e.dir)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -27,33 +27,39 @@ type (
|
||||
exeCmd exe.ICmdBuilder
|
||||
vcsStore vcs.Store
|
||||
targetMode parser.TargetMode
|
||||
rebuildMode parser.RebuildMode
|
||||
origTargets mapset.Set[string]
|
||||
downloadOnly bool
|
||||
log *text.Logger
|
||||
|
||||
manualConfirmRequired bool
|
||||
}
|
||||
)
|
||||
|
||||
func NewInstaller(dbExecutor db.Executor,
|
||||
exeCmd exe.ICmdBuilder, vcsStore vcs.Store, targetMode parser.TargetMode,
|
||||
downloadOnly bool, logger *text.Logger,
|
||||
rebuildMode parser.RebuildMode, downloadOnly bool, logger *text.Logger,
|
||||
) *Installer {
|
||||
return &Installer{
|
||||
dbExecutor: dbExecutor,
|
||||
postInstallHooks: []PostInstallHookFunc{},
|
||||
failedAndIgnored: map[string]error{},
|
||||
exeCmd: exeCmd,
|
||||
vcsStore: vcsStore,
|
||||
targetMode: targetMode,
|
||||
downloadOnly: downloadOnly,
|
||||
log: logger,
|
||||
dbExecutor: dbExecutor,
|
||||
postInstallHooks: []PostInstallHookFunc{},
|
||||
failedAndIgnored: map[string]error{},
|
||||
exeCmd: exeCmd,
|
||||
vcsStore: vcsStore,
|
||||
targetMode: targetMode,
|
||||
rebuildMode: rebuildMode,
|
||||
downloadOnly: downloadOnly,
|
||||
log: logger,
|
||||
manualConfirmRequired: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (installer *Installer) CompileFailedAndIgnored() error {
|
||||
func (installer *Installer) CompileFailedAndIgnored() (map[string]error, error) {
|
||||
if len(installer.failedAndIgnored) == 0 {
|
||||
return nil
|
||||
return installer.failedAndIgnored, nil
|
||||
}
|
||||
|
||||
return &FailedIgnoredPkgError{
|
||||
return installer.failedAndIgnored, &FailedIgnoredPkgError{
|
||||
pkgErrors: installer.failedAndIgnored,
|
||||
}
|
||||
}
|
||||
@ -83,7 +89,17 @@ func (installer *Installer) Install(ctx context.Context,
|
||||
targets []map[string]*dep.InstallInfo,
|
||||
pkgBuildDirs map[string]string,
|
||||
excluded []string,
|
||||
manualConfirmRequired bool,
|
||||
) error {
|
||||
installer.log.Debugln("manualConfirmRequired:", manualConfirmRequired)
|
||||
installer.manualConfirmRequired = manualConfirmRequired
|
||||
|
||||
installer.origTargets = mapset.NewThreadUnsafeSet[string]()
|
||||
for _, targetString := range cmdArgs.Targets {
|
||||
installer.origTargets.Add(dep.ToTarget(targetString).Name)
|
||||
}
|
||||
installer.log.Debugln("origTargets:", installer.origTargets)
|
||||
|
||||
// Reorganize targets into layers of dependencies
|
||||
var errMulti multierror.MultiError
|
||||
for i := len(targets) - 1; i >= 0; i-- {
|
||||
@ -117,6 +133,10 @@ func mergeLayers(layer1, layer2 map[string]*dep.InstallInfo) map[string]*dep.Ins
|
||||
return layer1
|
||||
}
|
||||
|
||||
func (installer *Installer) appendNoConfirm() bool {
|
||||
return !installer.manualConfirmRequired || settings.NoConfirm
|
||||
}
|
||||
|
||||
func (installer *Installer) handleLayer(ctx context.Context,
|
||||
cmdArgs *parser.Arguments,
|
||||
layer map[string]*dep.InstallInfo,
|
||||
@ -125,15 +145,20 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
||||
excluded []string,
|
||||
) error {
|
||||
// Install layer
|
||||
nameToBaseMap := make(map[string]string, 0)
|
||||
syncDeps, syncExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
aurDeps, aurExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
nameToBaseMap := make(map[string]string, len(layer))
|
||||
syncDeps, syncExp, syncGroups := mapset.NewThreadUnsafeSet[string](),
|
||||
mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
aurDeps, aurExp, aurOrigTargetBases := mapset.NewThreadUnsafeSet[string](),
|
||||
mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
|
||||
|
||||
upgradeSync := false
|
||||
for name, info := range layer {
|
||||
switch info.Source {
|
||||
case dep.AUR, dep.SrcInfo:
|
||||
nameToBaseMap[name] = *info.AURBase
|
||||
if installer.origTargets.Contains(name) {
|
||||
aurOrigTargetBases.Add(*info.AURBase)
|
||||
}
|
||||
|
||||
switch info.Reason {
|
||||
case dep.Explicit:
|
||||
@ -152,6 +177,11 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
||||
}
|
||||
compositePkgName := fmt.Sprintf("%s/%s", *info.SyncDBName, name)
|
||||
|
||||
if info.IsGroup {
|
||||
syncGroups.Add(compositePkgName)
|
||||
continue
|
||||
}
|
||||
|
||||
switch info.Reason {
|
||||
case dep.Explicit:
|
||||
if cmdArgs.ExistsArg("asdeps", "asdep") {
|
||||
@ -165,52 +195,66 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
text.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
|
||||
installer.log.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
|
||||
"aurDeps", aurDeps, "aurExp", aurExp, "upgrade", upgradeSync)
|
||||
|
||||
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp, excluded, upgradeSync)
|
||||
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp, syncGroups,
|
||||
excluded, upgradeSync, installer.appendNoConfirm())
|
||||
if errShow != nil {
|
||||
return ErrInstallRepoPkgs
|
||||
}
|
||||
|
||||
errAur := installer.installAURPackages(ctx, cmdArgs, aurDeps, aurExp,
|
||||
nameToBaseMap, pkgBuildDirs, true, lastLayer)
|
||||
aurOrigTargetBases, nameToBaseMap, pkgBuildDirs, true, lastLayer,
|
||||
installer.appendNoConfirm())
|
||||
|
||||
return errAur
|
||||
}
|
||||
|
||||
func (installer *Installer) installAURPackages(ctx context.Context,
|
||||
cmdArgs *parser.Arguments,
|
||||
aurDepNames, aurExpNames mapset.Set[string],
|
||||
aurDepNames, aurExpNames, aurOrigTargetBases mapset.Set[string],
|
||||
nameToBase, pkgBuildDirsByBase map[string]string,
|
||||
installIncompatible bool,
|
||||
lastLayer bool,
|
||||
noConfirm bool,
|
||||
) error {
|
||||
all := aurDepNames.Union(aurExpNames).ToSlice()
|
||||
if len(all) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
deps, exps := make([]string, 0, aurDepNames.Cardinality()), make([]string, 0, aurExpNames.Cardinality())
|
||||
pkgArchives := make([]string, 0, len(exps)+len(deps))
|
||||
builtPkgDests := make(map[string]map[string]string)
|
||||
deps := make([]string, 0, aurDepNames.Cardinality())
|
||||
exps := make([]string, 0, aurExpNames.Cardinality())
|
||||
pkgArchives := make([]string, 0, len(all))
|
||||
|
||||
for _, name := range all {
|
||||
base := nameToBase[name]
|
||||
dir := pkgBuildDirsByBase[base]
|
||||
|
||||
pkgdests, errMake := installer.buildPkg(ctx, dir, base, installIncompatible, cmdArgs.ExistsArg("needed"))
|
||||
if errMake != nil {
|
||||
if !lastLayer {
|
||||
return fmt.Errorf("%s - %w", gotext.Get("error making: %s", base), errMake)
|
||||
}
|
||||
pkgdests, ok := builtPkgDests[base]
|
||||
if ok {
|
||||
installer.log.Debugln("skipping built pkgbase", base, "package", name)
|
||||
} else {
|
||||
var errMake error
|
||||
installer.log.Debugln("building pkgbase", base, "package", name)
|
||||
pkgdests, errMake = installer.buildPkg(ctx, dir, base,
|
||||
installIncompatible, cmdArgs.ExistsArg("needed"), aurOrigTargetBases.Contains(base))
|
||||
builtPkgDests[base] = pkgdests
|
||||
if errMake != nil {
|
||||
if !lastLayer {
|
||||
return fmt.Errorf("%s - %w", gotext.Get("error making: %s", base), errMake)
|
||||
}
|
||||
|
||||
installer.failedAndIgnored[name] = errMake
|
||||
text.Errorln(gotext.Get("error making: %s", base), "-", errMake)
|
||||
continue
|
||||
installer.failedAndIgnored[name] = errMake
|
||||
installer.log.Errorln(gotext.Get("error making: %s", base), "-", errMake)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if len(pkgdests) == 0 {
|
||||
text.Warnln(gotext.Get("nothing to install for %s", text.Cyan(base)))
|
||||
installer.log.Warnln(gotext.Get("nothing to install for %s", text.Cyan(base)))
|
||||
continue
|
||||
}
|
||||
|
||||
@ -232,7 +276,8 @@ func (installer *Installer) installAURPackages(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
if err := installPkgArchive(ctx, installer.exeCmd, installer.targetMode, installer.vcsStore, cmdArgs, pkgArchives); err != nil {
|
||||
if err := installPkgArchive(ctx, installer.exeCmd, installer.targetMode,
|
||||
installer.vcsStore, cmdArgs, pkgArchives, noConfirm); err != nil {
|
||||
return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v", pkgArchives), err)
|
||||
}
|
||||
|
||||
@ -245,9 +290,13 @@ func (installer *Installer) installAURPackages(ctx context.Context,
|
||||
|
||||
func (installer *Installer) buildPkg(ctx context.Context,
|
||||
dir, base string,
|
||||
installIncompatible, needed bool,
|
||||
installIncompatible, needed, isTarget bool,
|
||||
) (map[string]string, error) {
|
||||
args := []string{"--nobuild", "-fC"}
|
||||
args := []string{"--nobuild", "-f"}
|
||||
|
||||
if !installer.exeCmd.GetKeepSrc() {
|
||||
args = append(args, "-C")
|
||||
}
|
||||
|
||||
if installIncompatible {
|
||||
args = append(args, "--ignorearch")
|
||||
@ -266,19 +315,23 @@ func (installer *Installer) buildPkg(ctx context.Context,
|
||||
|
||||
switch {
|
||||
case needed && installer.pkgsAreAlreadyInstalled(pkgdests, pkgVersion) || installer.downloadOnly:
|
||||
args = []string{"-c", "--nobuild", "--noextract", "--ignorearch"}
|
||||
args = []string{"--nobuild", "--noextract", "--ignorearch"}
|
||||
pkgdests = map[string]string{}
|
||||
text.Warnln(gotext.Get("%s is up to date -- skipping", text.Cyan(base+"-"+pkgVersion)))
|
||||
case pkgsAreBuilt(pkgdests):
|
||||
args = []string{"-c", "--nobuild", "--noextract", "--ignorearch"}
|
||||
text.Warnln(gotext.Get("%s already made -- skipping build", text.Cyan(base+"-"+pkgVersion)))
|
||||
installer.log.Warnln(gotext.Get("%s is up to date -- skipping", text.Cyan(base+"-"+pkgVersion)))
|
||||
case installer.skipAlreadyBuiltPkg(isTarget, pkgdests):
|
||||
args = []string{"--nobuild", "--noextract", "--ignorearch"}
|
||||
installer.log.Warnln(gotext.Get("%s already made -- skipping build", text.Cyan(base+"-"+pkgVersion)))
|
||||
default:
|
||||
args = []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
|
||||
args = []string{"-f", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
|
||||
if installIncompatible {
|
||||
args = append(args, "--ignorearch")
|
||||
}
|
||||
}
|
||||
|
||||
if !installer.exeCmd.GetKeepSrc() {
|
||||
args = append(args, "-c")
|
||||
}
|
||||
|
||||
errMake := installer.exeCmd.Show(
|
||||
installer.exeCmd.BuildMakepkgCmd(ctx,
|
||||
dir, args...))
|
||||
@ -303,10 +356,10 @@ func (installer *Installer) pkgsAreAlreadyInstalled(pkgdests map[string]string,
|
||||
return true
|
||||
}
|
||||
|
||||
func pkgsAreBuilt(pkgdests map[string]string) bool {
|
||||
func pkgsAreBuilt(logger *text.Logger, pkgdests map[string]string) bool {
|
||||
for _, pkgdest := range pkgdests {
|
||||
if _, err := os.Stat(pkgdest); err != nil {
|
||||
text.Debugln("pkgIsBuilt:", pkgdest, "does not exist")
|
||||
logger.Debugln("pkgIsBuilt:", pkgdest, "does not exist")
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -314,6 +367,20 @@ func pkgsAreBuilt(pkgdests map[string]string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (installer *Installer) skipAlreadyBuiltPkg(isTarget bool, pkgdests map[string]string) bool {
|
||||
switch installer.rebuildMode {
|
||||
case parser.RebuildModeNo:
|
||||
return pkgsAreBuilt(installer.log, pkgdests)
|
||||
case parser.RebuildModeYes:
|
||||
return !isTarget && pkgsAreBuilt(installer.log, pkgdests)
|
||||
// case parser.RebuildModeTree: // TODO
|
||||
// case parser.RebuildModeAll: // TODO
|
||||
default:
|
||||
// same as RebuildModeNo
|
||||
return pkgsAreBuilt(installer.log, pkgdests)
|
||||
}
|
||||
}
|
||||
|
||||
func (*Installer) isDep(cmdArgs *parser.Arguments, aurExpNames mapset.Set[string], name string) bool {
|
||||
switch {
|
||||
case cmdArgs.ExistsArg("asdeps", "asdep"):
|
||||
@ -359,10 +426,12 @@ func (installer *Installer) getNewTargets(pkgdests map[string]string, name strin
|
||||
func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Arguments,
|
||||
syncDeps, // repo targets that are deps
|
||||
syncExp mapset.Set[string], // repo targets that are exp
|
||||
syncGroups mapset.Set[string], // repo targets that are groups
|
||||
excluded []string,
|
||||
upgrade bool, // run even without targets
|
||||
noConfirm bool,
|
||||
) error {
|
||||
repoTargets := syncDeps.Union(syncExp).ToSlice()
|
||||
repoTargets := syncDeps.Union(syncExp).Union(syncGroups).ToSlice()
|
||||
if len(repoTargets) == 0 && !upgrade {
|
||||
return nil
|
||||
}
|
||||
@ -374,12 +443,21 @@ func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *pa
|
||||
arguments.Op = "S"
|
||||
arguments.ClearTargets()
|
||||
arguments.AddTarget(repoTargets...)
|
||||
|
||||
// Don't upgrade all repo packages if only AUR upgrades are specified
|
||||
if installer.targetMode == parser.ModeAUR {
|
||||
arguments.DelArg("u", "upgrades")
|
||||
}
|
||||
|
||||
if len(excluded) > 0 {
|
||||
arguments.CreateOrAppendOption("ignore", excluded...)
|
||||
}
|
||||
|
||||
errShow := installer.exeCmd.Show(installer.exeCmd.BuildPacmanCmd(ctx,
|
||||
arguments, installer.targetMode, settings.NoConfirm))
|
||||
arguments, installer.targetMode, noConfirm))
|
||||
if errShow != nil {
|
||||
return errShow
|
||||
}
|
||||
|
||||
if errD := asdeps(ctx, installer.exeCmd, installer.targetMode, cmdArgs, syncDeps.ToSlice()); errD != nil {
|
||||
return errD
|
||||
@ -389,5 +467,5 @@ func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *pa
|
||||
return errE
|
||||
}
|
||||
|
||||
return errShow
|
||||
return nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -21,7 +21,9 @@ import (
|
||||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
)
|
||||
|
||||
var testLogger = text.NewLogger(io.Discard, strings.NewReader(""), true, "test")
|
||||
func newTestLogger() *text.Logger {
|
||||
return text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), true, "test")
|
||||
}
|
||||
|
||||
func ptrString(s string) *string {
|
||||
return &s
|
||||
@ -54,8 +56,8 @@ func TestInstaller_InstallNeeded(t *testing.T) {
|
||||
isInstalled: false,
|
||||
isBuilt: false,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --needed --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config -- yay",
|
||||
},
|
||||
@ -66,7 +68,7 @@ func TestInstaller_InstallNeeded(t *testing.T) {
|
||||
isInstalled: false,
|
||||
isBuilt: true,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --needed --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config -- yay",
|
||||
@ -78,7 +80,7 @@ func TestInstaller_InstallNeeded(t *testing.T) {
|
||||
isInstalled: true,
|
||||
isBuilt: false,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
@ -131,7 +133,8 @@ func TestInstaller_InstallNeeded(t *testing.T) {
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, false, testLogger)
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddArg("needed")
|
||||
@ -153,7 +156,7 @@ func TestInstaller_InstallNeeded(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
@ -209,8 +212,8 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
wantShow: []string{
|
||||
"pacman -S --config /etc/pacman.conf -- core/linux",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- linux",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- yay",
|
||||
},
|
||||
@ -238,8 +241,8 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
wantShow: []string{
|
||||
"pacman -S --config /etc/pacman.conf -- core/linux",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- linux",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- yay",
|
||||
},
|
||||
@ -290,10 +293,10 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
{
|
||||
desc: "same layer -- aur",
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- yay",
|
||||
},
|
||||
@ -320,12 +323,12 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
{
|
||||
desc: "different layer -- aur",
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.8-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- jellyfin-server",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- yay",
|
||||
},
|
||||
@ -371,13 +374,13 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
if strings.Contains(cmd.String(), "makepkg -cf --noconfirm") && cmd.Dir == tmpDir {
|
||||
if strings.Contains(cmd.String(), "makepkg -f --noconfirm") && cmd.Dir == tmpDir {
|
||||
f, err := os.OpenFile(pkgTar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(td, err)
|
||||
require.NoError(td, f.Close())
|
||||
}
|
||||
|
||||
if strings.Contains(cmd.String(), "makepkg -cf --noconfirm") && cmd.Dir == tmpDirJfin {
|
||||
if strings.Contains(cmd.String(), "makepkg -f --noconfirm") && cmd.Dir == tmpDirJfin {
|
||||
f, err := os.OpenFile(jfinPkgTar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(td, err)
|
||||
require.NoError(td, f.Close())
|
||||
@ -405,7 +408,7 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, false, testLogger)
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("yay")
|
||||
@ -415,7 +418,7 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
||||
"jellyfin": tmpDirJfin,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
@ -458,7 +461,8 @@ func TestInstaller_RunPostHooks(t *testing.T) {
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, false, testLogger)
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
called := false
|
||||
hook := func(ctx context.Context) error {
|
||||
@ -566,7 +570,7 @@ func TestInstaller_CompileFailed(t *testing.T) {
|
||||
}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
if tc.failBuild && strings.Contains(cmd.String(), "makepkg -cf --noconfirm") && cmd.Dir == tmpDir {
|
||||
if tc.failBuild && strings.Contains(cmd.String(), "makepkg -f --noconfirm") && cmd.Dir == tmpDir {
|
||||
return errors.New("makepkg failed")
|
||||
}
|
||||
return nil
|
||||
@ -588,7 +592,8 @@ func TestInstaller_CompileFailed(t *testing.T) {
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, false, testLogger)
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddArg("needed")
|
||||
@ -598,16 +603,27 @@ func TestInstaller_CompileFailed(t *testing.T) {
|
||||
"yay": tmpDir,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
if tc.wantErrInstall {
|
||||
require.Error(td, errI)
|
||||
} else {
|
||||
require.NoError(td, errI)
|
||||
}
|
||||
err := installer.CompileFailedAndIgnored()
|
||||
failed, err := installer.CompileFailedAndIgnored()
|
||||
if tc.wantErrCompile {
|
||||
require.Error(td, err)
|
||||
assert.ErrorContains(td, err, "yay")
|
||||
for key := range failed {
|
||||
assert.ErrorContains(td, err, key)
|
||||
}
|
||||
uniqueBases := make(map[string]struct{})
|
||||
for _, layer := range tc.targets {
|
||||
for _, info := range layer {
|
||||
if info.AURBase != nil {
|
||||
uniqueBases[*info.AURBase] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
require.Len(td, failed, len(uniqueBases))
|
||||
} else {
|
||||
require.NoError(td, err)
|
||||
}
|
||||
@ -688,18 +704,16 @@ func TestInstaller_InstallSplitPackage(t *testing.T) {
|
||||
wantShow: []string{
|
||||
"pacman -S --config /etc/pacman.conf -- community/dotnet-runtime-6.0 community/aspnet-runtime community/dotnet-sdk-6.0",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 aspnet-runtime dotnet-sdk-6.0",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asdeps --config /etc/pacman.conf -- jellyfin-server jellyfin-web",
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist", "makepkg --packagelist", "makepkg --packagelist"},
|
||||
wantCapture: []string{"makepkg --packagelist", "makepkg --packagelist"},
|
||||
},
|
||||
}
|
||||
|
||||
@ -746,7 +760,8 @@ func TestInstaller_InstallSplitPackage(t *testing.T) {
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, false, testLogger)
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("jellyfin")
|
||||
@ -755,7 +770,7 @@ func TestInstaller_InstallSplitPackage(t *testing.T) {
|
||||
"jellyfin": tmpDir,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
@ -811,7 +826,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
isInstalled: false,
|
||||
isBuilt: false,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
@ -821,7 +836,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
isInstalled: false,
|
||||
isBuilt: true,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
@ -831,7 +846,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
isInstalled: true,
|
||||
isBuilt: false,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -fC --ignorearch",
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
@ -884,7 +899,8 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, true, testLogger)
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, true, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("yay")
|
||||
@ -905,7 +921,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
@ -932,3 +948,504 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstaller_InstallGroup(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
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())
|
||||
|
||||
type testCase struct {
|
||||
desc string
|
||||
wantShow []string
|
||||
wantCapture []string
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "group",
|
||||
wantShow: []string{
|
||||
"pacman -S --noconfirm --config -- community/kubernetes-tools",
|
||||
},
|
||||
wantCapture: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(td *testing.T) {
|
||||
tmpDir := td.TempDir()
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return "", "", nil
|
||||
}
|
||||
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
mockDB := &mock.DBExecutor{}
|
||||
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
MakepkgBin: makepkgBin,
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, true, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("kubernetes-tools")
|
||||
|
||||
pkgBuildDirs := map[string]string{}
|
||||
|
||||
targets := []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"kubernetes-tools": {
|
||||
Source: dep.Sync,
|
||||
Reason: dep.Explicit,
|
||||
Version: "",
|
||||
IsGroup: true,
|
||||
SyncDBName: ptrString("community"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
require.Len(td, mockRunner.CaptureCalls, len(tc.wantCapture))
|
||||
require.Empty(td, installer.failedAndIgnored)
|
||||
|
||||
for i, call := range mockRunner.ShowCalls {
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
show = strings.ReplaceAll(show, makepkgBin, "makepkg")
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
|
||||
// options are in a different order on different systems and on CI root user is used
|
||||
assert.Subset(td, strings.Split(show, " "), strings.Split(tc.wantShow[i], " "), show)
|
||||
}
|
||||
|
||||
for i, call := range mockRunner.CaptureCalls {
|
||||
capture := call.Args[0].(*exec.Cmd).String()
|
||||
capture = strings.ReplaceAll(capture, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
capture = strings.ReplaceAll(capture, makepkgBin, "makepkg")
|
||||
capture = strings.ReplaceAll(capture, pacmanBin, "pacman")
|
||||
assert.Subset(td, strings.Split(capture, " "), strings.Split(tc.wantCapture[i], " "), capture)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstaller_InstallRebuild(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
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())
|
||||
|
||||
type testCase struct {
|
||||
desc string
|
||||
rebuildOption parser.RebuildMode
|
||||
isInstalled bool
|
||||
isBuilt bool
|
||||
wantShow []string
|
||||
wantCapture []string
|
||||
targets []map[string]*dep.InstallInfo
|
||||
}
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "--norebuild(default) when built and not installed",
|
||||
rebuildOption: parser.RebuildModeNo,
|
||||
isBuilt: true,
|
||||
isInstalled: false,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -c --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config -- yay",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
targets: []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"yay": {
|
||||
Source: dep.AUR,
|
||||
Reason: dep.Explicit,
|
||||
Version: "91.0.0-1",
|
||||
SrcinfoPath: ptrString(tmpDir + "/.SRCINFO"),
|
||||
AURBase: ptrString("yay"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "--rebuild when built and not installed",
|
||||
rebuildOption: parser.RebuildModeYes,
|
||||
isBuilt: true,
|
||||
isInstalled: false,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config -- yay",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
targets: []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"yay": {
|
||||
Source: dep.AUR,
|
||||
Reason: dep.Explicit,
|
||||
Version: "91.0.0-1",
|
||||
SrcinfoPath: ptrString(tmpDir + "/.SRCINFO"),
|
||||
AURBase: ptrString("yay"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "--rebuild when built and installed",
|
||||
rebuildOption: parser.RebuildModeYes,
|
||||
isInstalled: true,
|
||||
isBuilt: true,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config -- yay",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
targets: []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"yay": {
|
||||
Source: dep.AUR,
|
||||
Reason: dep.Explicit,
|
||||
Version: "91.0.0-1",
|
||||
SrcinfoPath: ptrString(tmpDir + "/.SRCINFO"),
|
||||
AURBase: ptrString("yay"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "--rebuild when built and installed previously as dep",
|
||||
rebuildOption: parser.RebuildModeYes,
|
||||
isInstalled: true,
|
||||
isBuilt: true,
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -f -C --ignorearch",
|
||||
"makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch",
|
||||
"pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asdeps --config -- yay",
|
||||
},
|
||||
wantCapture: []string{"makepkg --packagelist"},
|
||||
targets: []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"yay": {
|
||||
Source: dep.AUR,
|
||||
Reason: dep.Dep,
|
||||
Version: "91.0.0-1",
|
||||
SrcinfoPath: ptrString(tmpDir + "/.SRCINFO"),
|
||||
AURBase: ptrString("yay"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(td *testing.T) {
|
||||
tmpDir := td.TempDir()
|
||||
pkgTar := tmpDir + "/yay-91.0.0-1-x86_64.pkg.tar.zst"
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return pkgTar, "", nil
|
||||
}
|
||||
|
||||
i := 0
|
||||
showOverride := func(cmd *exec.Cmd) error {
|
||||
i++
|
||||
if i == 2 {
|
||||
if !tc.isBuilt {
|
||||
f, err := os.OpenFile(pkgTar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(td, err)
|
||||
require.NoError(td, f.Close())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// create a mock file
|
||||
if tc.isBuilt {
|
||||
f, err := os.OpenFile(pkgTar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(td, err)
|
||||
require.NoError(td, f.Close())
|
||||
}
|
||||
|
||||
isCorrectInstalledOverride := func(string, string) bool {
|
||||
return tc.isInstalled
|
||||
}
|
||||
|
||||
mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFn: isCorrectInstalledOverride}
|
||||
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
MakepkgBin: makepkgBin,
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
cmdBuilder.Runner = mockRunner
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
tc.rebuildOption, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("yay")
|
||||
|
||||
pkgBuildDirs := map[string]string{
|
||||
"yay": tmpDir,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
require.Len(td, mockRunner.CaptureCalls, len(tc.wantCapture))
|
||||
|
||||
for i, call := range mockRunner.ShowCalls {
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
show = strings.ReplaceAll(show, makepkgBin, "makepkg")
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
|
||||
// options are in a different order on different systems and on CI root user is used
|
||||
assert.Subset(td, strings.Split(show, " "), strings.Split(tc.wantShow[i], " "), show)
|
||||
}
|
||||
|
||||
for i, call := range mockRunner.CaptureCalls {
|
||||
capture := call.Args[0].(*exec.Cmd).String()
|
||||
capture = strings.ReplaceAll(capture, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
capture = strings.ReplaceAll(capture, makepkgBin, "makepkg")
|
||||
capture = strings.ReplaceAll(capture, pacmanBin, "pacman")
|
||||
assert.Subset(td, strings.Split(capture, " "), strings.Split(tc.wantCapture[i], " "), capture)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstaller_InstallUpgrade(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
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())
|
||||
|
||||
type testCase struct {
|
||||
desc string
|
||||
targetMode parser.TargetMode
|
||||
}
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "target any",
|
||||
targetMode: parser.ModeAny,
|
||||
},
|
||||
{
|
||||
desc: "target repo",
|
||||
targetMode: parser.ModeRepo,
|
||||
},
|
||||
{
|
||||
desc: "target aur",
|
||||
targetMode: parser.ModeAUR,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(td *testing.T) {
|
||||
mockDB := &mock.DBExecutor{}
|
||||
mockRunner := &exe.MockRunner{}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
MakepkgBin: makepkgBin,
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, tc.targetMode,
|
||||
parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddArg("u", "upgrades") // Make sure both args are removed
|
||||
|
||||
targets := []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"linux": {
|
||||
Source: dep.Sync,
|
||||
Reason: dep.Dep,
|
||||
Version: "17.0.0-1",
|
||||
SyncDBName: ptrString("core"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, map[string]string{}, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.NotEmpty(td, mockRunner.ShowCalls)
|
||||
|
||||
// The first call is the only call being test
|
||||
call := mockRunner.ShowCalls[0]
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
show = strings.ReplaceAll(show, makepkgBin, "makepkg")
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
|
||||
if tc.targetMode == parser.ModeAUR {
|
||||
assert.NotContains(td, show, "--upgrades")
|
||||
assert.NotContains(td, show, "-u")
|
||||
} else {
|
||||
assert.Contains(td, show, "--upgrades")
|
||||
assert.Contains(td, show, "-u")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstaller_KeepSrc(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
makepkgBin := t.TempDir() + "/makepkg"
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
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())
|
||||
|
||||
type testCase struct {
|
||||
desc string
|
||||
wantShow []string
|
||||
targets []map[string]*dep.InstallInfo
|
||||
}
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "--keepsrc",
|
||||
wantShow: []string{
|
||||
"makepkg --nobuild -f --ignorearch",
|
||||
"makepkg --nobuild --noextract --ignorearch",
|
||||
"pacman -U --config -- /testdir/yay-92.0.0-1-x86_64.pkg.tar.zst",
|
||||
"pacman -D -q --asexplicit --config -- yay",
|
||||
},
|
||||
targets: []map[string]*dep.InstallInfo{
|
||||
{
|
||||
"yay": {
|
||||
Source: dep.AUR,
|
||||
Reason: dep.Explicit,
|
||||
Version: "92.0.0-1",
|
||||
SrcinfoPath: ptrString(tmpDir + "/.SRCINFO"),
|
||||
AURBase: ptrString("yay"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(td *testing.T) {
|
||||
tmpDir := td.TempDir()
|
||||
pkgTar := tmpDir + "/yay-92.0.0-1-x86_64.pkg.tar.zst"
|
||||
|
||||
captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
|
||||
return pkgTar, "", nil
|
||||
}
|
||||
|
||||
// create a mock file
|
||||
f, err := os.OpenFile(pkgTar, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||
require.NoError(td, err)
|
||||
require.NoError(td, f.Close())
|
||||
|
||||
mockDB := &mock.DBExecutor{}
|
||||
mockRunner := &exe.MockRunner{CaptureFn: captureOverride}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
MakepkgBin: makepkgBin,
|
||||
SudoBin: "su",
|
||||
PacmanBin: pacmanBin,
|
||||
KeepSrc: true,
|
||||
Runner: mockRunner,
|
||||
SudoLoopEnabled: false,
|
||||
}
|
||||
|
||||
installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny,
|
||||
parser.RebuildModeNo, false, newTestLogger())
|
||||
|
||||
cmdArgs := parser.MakeArguments()
|
||||
cmdArgs.AddTarget("yay")
|
||||
|
||||
pkgBuildDirs := map[string]string{
|
||||
"yay": tmpDir,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
|
||||
for i, call := range mockRunner.ShowCalls {
|
||||
show := call.Args[0].(*exec.Cmd).String()
|
||||
show = strings.ReplaceAll(show, tmpDir, "/testdir") // replace the temp dir with a static path
|
||||
show = strings.ReplaceAll(show, makepkgBin, "makepkg")
|
||||
show = strings.ReplaceAll(show, pacmanBin, "pacman")
|
||||
|
||||
// options are in a different order on different systems and on CI root user is used
|
||||
assert.Subset(td, strings.Split(show, " "), strings.Split(tc.wantShow[i], " "), show)
|
||||
|
||||
// Only assert makepkg commands don't have clean arguments
|
||||
if strings.HasPrefix(show, "makepkg") {
|
||||
assert.NotContains(td, show, "-c")
|
||||
assert.NotContains(td, show, "-C")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
164
pkg/sync/build/pkg_archive.go
Normal file
164
pkg/sync/build/pkg_archive.go
Normal file
@ -0,0 +1,164 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"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/vcs"
|
||||
)
|
||||
|
||||
func installPkgArchive(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode,
|
||||
vcsStore vcs.Store,
|
||||
cmdArgs *parser.Arguments,
|
||||
pkgArchives []string,
|
||||
noConfirm bool,
|
||||
) error {
|
||||
if len(pkgArchives) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arguments := cmdArgs.Copy()
|
||||
arguments.ClearTargets()
|
||||
arguments.Op = "U"
|
||||
arguments.DelArg("confirm")
|
||||
arguments.DelArg("noconfirm")
|
||||
arguments.DelArg("c", "clean")
|
||||
arguments.DelArg("i", "install")
|
||||
arguments.DelArg("q", "quiet")
|
||||
arguments.DelArg("y", "refresh")
|
||||
arguments.DelArg("u", "sysupgrade")
|
||||
arguments.DelArg("w", "downloadonly")
|
||||
arguments.DelArg("asdeps", "asdep")
|
||||
arguments.DelArg("asexplicit", "asexp")
|
||||
|
||||
arguments.AddTarget(pkgArchives...)
|
||||
|
||||
if errShow := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, mode, noConfirm)); errShow != nil {
|
||||
return errShow
|
||||
}
|
||||
|
||||
if errStore := vcsStore.Save(); errStore != nil {
|
||||
fmt.Fprintln(os.Stderr, errStore)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setInstallReason(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder, mode parser.TargetMode,
|
||||
cmdArgs *parser.Arguments, deps, exps []string,
|
||||
) error {
|
||||
if len(deps)+len(exps) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if errDeps := asdeps(ctx, cmdBuilder, mode, cmdArgs, deps); errDeps != nil {
|
||||
return errDeps
|
||||
}
|
||||
|
||||
return asexp(ctx, cmdBuilder, mode, cmdArgs, exps)
|
||||
}
|
||||
|
||||
func setPkgReason(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode,
|
||||
cmdArgs *parser.Arguments, pkgs []string, exp bool,
|
||||
) error {
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
cmdArgs = cmdArgs.CopyGlobal()
|
||||
if exp {
|
||||
if err := cmdArgs.AddArg("q", "D", "asexplicit"); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := cmdArgs.AddArg("q", "D", "asdeps"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, compositePkgName := range pkgs {
|
||||
pkgSplit := strings.Split(compositePkgName, "/")
|
||||
|
||||
pkgName := pkgSplit[0]
|
||||
if len(pkgSplit) > 1 {
|
||||
pkgName = pkgSplit[1]
|
||||
}
|
||||
|
||||
cmdArgs.AddTarget(pkgName)
|
||||
}
|
||||
|
||||
if err := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
cmdArgs, mode, settings.NoConfirm)); err != nil {
|
||||
return &SetPkgReasonError{exp: exp}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func asdeps(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode, cmdArgs *parser.Arguments, pkgs []string,
|
||||
) error {
|
||||
return setPkgReason(ctx, cmdBuilder, mode, cmdArgs, pkgs, false)
|
||||
}
|
||||
|
||||
func asexp(ctx context.Context,
|
||||
cmdBuilder exe.ICmdBuilder,
|
||||
mode parser.TargetMode, cmdArgs *parser.Arguments, pkgs []string,
|
||||
) error {
|
||||
return setPkgReason(ctx, cmdBuilder, mode, cmdArgs, pkgs, true)
|
||||
}
|
||||
|
||||
func parsePackageList(ctx context.Context, cmdBuilder exe.ICmdBuilder,
|
||||
dir string,
|
||||
) (pkgdests map[string]string, pkgVersion string, err error) {
|
||||
stdout, stderr, err := cmdBuilder.Capture(
|
||||
cmdBuilder.BuildMakepkgCmd(ctx, dir, "--packagelist"))
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%s %w", stderr, err)
|
||||
}
|
||||
|
||||
lines := strings.Split(stdout, "\n")
|
||||
pkgdests = make(map[string]string, len(lines))
|
||||
|
||||
for _, line := range lines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
fileName := filepath.Base(line)
|
||||
split := strings.Split(fileName, "-")
|
||||
|
||||
if len(split) < 4 {
|
||||
return nil, "", errors.New(gotext.Get("cannot find package name: %v", split))
|
||||
}
|
||||
|
||||
// pkgname-pkgver-pkgrel-arch.pkgext
|
||||
// This assumes 3 dashes after the pkgname, Will cause an error
|
||||
// if the PKGEXT contains a dash. Please no one do that.
|
||||
pkgName := strings.Join(split[:len(split)-3], "-")
|
||||
pkgVersion = strings.Join(split[len(split)-3:len(split)-1], "-")
|
||||
pkgdests[pkgName] = line
|
||||
}
|
||||
|
||||
if len(pkgdests) == 0 {
|
||||
return nil, "", &NoPkgDestsFoundError{dir}
|
||||
}
|
||||
|
||||
return pkgdests, pkgVersion, nil
|
||||
}
|
167
pkg/sync/build/pkg_archive_test.go
Normal file
167
pkg/sync/build/pkg_archive_test.go
Normal file
@ -0,0 +1,167 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
)
|
||||
|
||||
func TestParsePackageList(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type testCase struct {
|
||||
desc string
|
||||
mockStdout string
|
||||
mockStderr string
|
||||
mockErr error
|
||||
wantPkgDests map[string]string
|
||||
wantPkgVersion string
|
||||
wantErr bool
|
||||
wantErrText string // Optional: specific error text to check
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "Standard package",
|
||||
mockStdout: "/path/to/package-1.2.3-4-x86_64.pkg.tar.zst\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"package": "/path/to/package-1.2.3-4-x86_64.pkg.tar.zst",
|
||||
},
|
||||
wantPkgVersion: "1.2.3-4",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "Package with dash in name",
|
||||
mockStdout: "/path/to/package-name-with-dash-1.0.0-1-any.pkg.tar.gz\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"package-name-with-dash": "/path/to/package-name-with-dash-1.0.0-1-any.pkg.tar.gz",
|
||||
},
|
||||
wantPkgVersion: "1.0.0-1",
|
||||
wantErr: false, // This should fail with current logic but pass with regex
|
||||
},
|
||||
{
|
||||
desc: "Multiple packages",
|
||||
mockStdout: "/path/to/pkg1-1.0-1-x86_64.pkg.tar.zst\n/other/path/pkg2-2.5-3-any.pkg.tar.xz\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"pkg1": "/path/to/pkg1-1.0-1-x86_64.pkg.tar.zst",
|
||||
"pkg2": "/other/path/pkg2-2.5-3-any.pkg.tar.xz",
|
||||
},
|
||||
wantPkgVersion: "2.5-3", // Version of the last package processed
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "Empty input",
|
||||
mockStdout: "",
|
||||
wantErr: true, // Expect NoPkgDestsFoundError
|
||||
},
|
||||
{
|
||||
desc: "Input with only newline",
|
||||
mockStdout: "\n",
|
||||
wantErr: true, // Expect NoPkgDestsFoundError
|
||||
},
|
||||
{
|
||||
desc: "Makepkg error",
|
||||
mockStderr: "makepkg failed",
|
||||
mockErr: fmt.Errorf("exit status 1"),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
desc: "Malformed filename (too few dashes)",
|
||||
mockStdout: "/path/to/malformed-package.pkg.tar.zst\n",
|
||||
wantErr: true, // Expect "cannot find package name" error
|
||||
},
|
||||
{
|
||||
desc: "Package with epoch",
|
||||
mockStdout: "/path/to/epochpkg-1:2.0.0-1-x86_64.pkg.tar.zst\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"epochpkg": "/path/to/epochpkg-1:2.0.0-1-x86_64.pkg.tar.zst",
|
||||
},
|
||||
wantPkgVersion: "1:2.0.0-1",
|
||||
wantErr: false, // This might fail with current logic
|
||||
},
|
||||
{
|
||||
desc: "Package with .zst extension",
|
||||
mockStdout: "/path/to/zstdpkg-3.3-1-any.pkg.tar.zst\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"zstdpkg": "/path/to/zstdpkg-3.3-1-any.pkg.tar.zst",
|
||||
},
|
||||
wantPkgVersion: "3.3-1",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "Package with .gz extension",
|
||||
mockStdout: "/path/to/gzpkg-3.3-1-any.pkg.tar.gz\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"gzpkg": "/path/to/gzpkg-3.3-1-any.pkg.tar.gz",
|
||||
},
|
||||
wantPkgVersion: "3.3-1",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "Package with .xz extension",
|
||||
mockStdout: "/path/to/xzpkg-3.3-1-any.pkg.tar.xz\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"xzpkg": "/path/to/xzpkg-3.3-1-any.pkg.tar.xz",
|
||||
},
|
||||
wantPkgVersion: "3.3-1",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "Package with .bz2 extension",
|
||||
mockStdout: "/path/to/bz2pkg-3.3-1-any.pkg.tar.bz2\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"bz2pkg": "/path/to/bz2pkg-3.3-1-any.pkg.tar.bz2",
|
||||
},
|
||||
wantPkgVersion: "3.3-1",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "Package with .tar extension (uncompressed)",
|
||||
mockStdout: "/path/to/tarpkg-3.3-1-any.pkg.tar\n",
|
||||
wantPkgDests: map[string]string{
|
||||
"tarpkg": "/path/to/tarpkg-3.3-1-any.pkg.tar",
|
||||
},
|
||||
wantPkgVersion: "3.3-1",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc // capture range variable
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockRunner := &exe.MockRunner{
|
||||
CaptureFn: func(cmd *exec.Cmd) (string, string, error) {
|
||||
// Basic check to ensure the command looks right
|
||||
require.Contains(t, cmd.String(), "--packagelist")
|
||||
return tc.mockStdout, tc.mockStderr, tc.mockErr
|
||||
},
|
||||
}
|
||||
cmdBuilder := &exe.CmdBuilder{Runner: mockRunner} // Simplified for this test
|
||||
|
||||
pkgdests, pkgVersion, err := parsePackageList(context.Background(), cmdBuilder, "/fake/dir")
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(t, err)
|
||||
if tc.wantErrText != "" {
|
||||
assert.Contains(t, err.Error(), tc.wantErrText)
|
||||
}
|
||||
// Check for specific error types if needed
|
||||
if tc.desc == "Empty input" || tc.desc == "Input with only newline" {
|
||||
assert.IsType(t, &NoPkgDestsFoundError{}, err)
|
||||
}
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.wantPkgDests, pkgdests)
|
||||
assert.Equal(t, tc.wantPkgVersion, pkgVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
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