Skip to content
This repository has been archived by the owner on Aug 9, 2019. It is now read-only.

Add caching to yaourt #286

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions src/lib/abs.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -395,32 +395,59 @@ sync_packages() {
fi
[[ $1 ]] || return 0
# Install from arguments
declare -A pkgs_search pkgs_found
declare -a repo_pkgs aur_pkgs bin_pkgs
declare -A pkgs_search pkgs_found pkgs_cached repo_pkgs aur_pkgs cached_pkgs
declare -a bin_pkgs
local _arg=("$@") _pkg repo pkg target
[[ $SP_ARG ]] && _arg=($(pacman_parse -T "${_arg[@]}"))
for _pkg in "${_arg[@]}"; do pkgs_search[$_pkg]=1; done

# Search for exact match, pkg which provides it, then in AUR
while read repo pkg target; do
((pkgs_search[$target])) || continue
unset pkgs_search[$target]
((pkgs_found[$pkg])) && continue
pkgs_found[$pkg]=1
if [[ "${repo}" != "aur" ]]; then
repo_pkgs+=("${repo}/${pkg}")
else
((NEEDED)) && pkgquery -Qqii "$target" && continue
aur_pkgs+=("$pkg")
fi
done < <(pkgquery -f "%r %n %t" -1SAii "${!pkgs_search[@]}")
local tmpfile=$(mktemp --tmpdir="$YAOURTTMPDIR")

pkgquery -f "%r %n %t %v" -1SAii "${!pkgs_search[@]}" 2>/dev/null >$tmpfile
[[ "$?" != "0" ]] && warning "no network connection" ||
while read repo pkg target version; do
((pkgs_search[$target])) || continue
unset pkgs_search[$target]
((pkgs_found[$pkg])) && continue
pkgs_found[$pkg]=1
[[ "$(ls "$CACHE_DIR" | grep "^${pkg}")" ]] &&
pkgs_cached["${pkg}"]="${version}"
if [[ "${repo}" != "aur" ]]; then
repo_pkgs[$pkg]="${repo}/${pkg}"
else
((NEEDED)) && pkgquery -Qqii "$target" && continue
aur_pkgs[$pkg]=1
fi
done < $tmpfile

# In case there is a double version check, eg. pkg1>0.1 pkg2<0.3
# package-query does only one check, so perform the remaining checks
for pkg in "${!pkgs_search[@]}"; do
_pkg=${pkg%%[<>=]*}
local _pkg=${pkg%%[<>=]*}
local _cached="$(ls "$CACHE_DIR" | grep "^$_pkg")"
if [[ " ${!pkgs_found[@]} " =~ " $_pkg " ]]; then
pkgquery -q -1SAii "$pkg" && unset pkgs_search[$pkg]
elif [[ $_cached ]]; then
cached_pkgs[$_pkg]="$CACHE_DIR/$_cached" && unset pkgs_search[$pkg]
fi
done

# Install from cached packages
for _pkg in "${!pkgs_cached[@]}"; do
local _cached="$(ls "$CACHE_DIR" | grep "^$_pkg")"
if [[ $_cached ]]; then
[[ "$_cached" = ${_pkg}-${pkgs_cached["$_pkg"]}* ]] &&
cached_pkgs[$_pkg]="$CACHE_DIR/$_cached"
fi
done
(( ! DOWNLOAD_ONLY)) && for _pkg in "${!cached_pkgs[@]}"; do
local _file="${cached_pkgs[$_pkg]}"
su_pacman -U "${PACMAN_S_ARG[@]}" "$_file" &&
unset aur_pkgs[$_pkg] && unset repo_pkgs[$_pkg] ||
manage_error "$_pkg" || return 1
done

bin_pkgs=("${!pkgs_search[@]}")
for _pkg in "${repo_pkgs[@]}"; do
install_from_abs "$_pkg" || return 1
Expand All @@ -432,7 +459,7 @@ sync_packages() {
su_pacman -S "${PACMAN_S_ARG[@]}" "${bin_pkgs[@]}" || return 1
fi
fi
for _pkg in "${aur_pkgs[@]}"; do
for _pkg in "${!aur_pkgs[@]}"; do
install_from_aur "$_pkg" || return 1
done
return 0
Expand Down
9 changes: 7 additions & 2 deletions src/lib/pkgbuild.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ build_package() {
# Build
SRCDEST="$YSRCDEST" PKGDEST="$YPKGDEST" y_makepkg -s -c -f -p ./PKGBUILD

# Cache it
msg $(_gettext 'Caching locally: %s %s-%s' "$pkgbase" "$pkgver" "$pkgrel")
cp -uv "$YPKGDEST/"*.pkg.* "$CACHE_DIR" || failed=1

if (( $? )); then
error $(_gettext 'Makepkg was unable to build %s.' "$pkgbase")
return 1
Expand Down Expand Up @@ -403,11 +407,12 @@ package_loop() {
*) return 99 ;; # should never execute
esac
done
(( ! ret )) && (( ! failed )) &&
(( ! ret )) && (( ! failed )) && (( ! DOWNLOAD_ONLY )) &&
( [[ $MAJOR == "pkgbuild" ]] && (( INSTALL_FLAG )) || ! [[ $MAJOR == "pkgbuild" ]] ) &&
{ install_package || failed=1; }

[[ $MAJOR == "pkgbuild" ]] && (( ! INSTALL_FLAG )) && cp -v "$YPKGDEST/"*.pkg.* "$YPKGBUILDDIR"
[[ $MAJOR == "pkgbuild" ]] && (( ! INSTALL_FLAG )) && cp -v "$YPKGDEST/"*.pkg.* $YPKGBUILDDIR

rm -r "$YPKGDEST"
return $failed
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/util.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ init_paths() {
YAOURTTMPDIR="$TMPDIR/yaourt-tmp-$(id -un)"
mkdir -p "$YAOURTTMPDIR" || check_dir YAOURTTMPDIR || die 1
(( EXPORT )) && [[ $EXPORTDIR ]] && { check_dir EXPORTDIR || die 1; }
[[ ! "$CACHE_DIR" ]] && CACHE_DIR="@cachedir@" &&
! [[ -d "$CACHE_DIR" ]] && { mkdir -p "$CACHE_DIR" || die 1; }
check_dir CACHE_DIR || die 1;
parse_pacman_conf
}

Expand Down
10 changes: 10 additions & 0 deletions src/man/yaourt.8
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Specify a custom AUR url (default to https://aur.archlinux.org)\&.
Build from sources, ABS for official packages, or AUR if packages is not found\&. Specify this option twice to build all dependencies\&.
.RE
.PP
\fB\-\-cachedir <dir>\fR
.RS 4
Use <dir> as a local cache for \fByaourt\fR, rather than the standard location, /var/cache/pacman/pkg.
.RE
.PP
\fB\-\-devel\fR
.RS 4
With
Expand Down Expand Up @@ -295,6 +300,11 @@ option, put them in quotes.
.RS 4
Upgrade all packages that are out of date\&.
.RE
.PP
\fB\-w, \-\-download-only\fR
.RS 4
Download and compile packages, but do not install. Place output in <cache dir>. See \fI--cachedir\fR\&.
.RE
.SH "HANDLING CONFIG FILES"
.sp
With AUTOSAVEBACKUPFILE (\fByaourtrc\fR(5)), yaourt will search and save all files marked as backup\&. These files can be used later with \fIyaourt \-C\fR to automerge current configuration files with new ones\&.
Expand Down
8 changes: 5 additions & 3 deletions src/yaourt.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ unset MAJOR AUR SEARCH BUILD REFRESH SYSUPGRADE CLEAN \
IGNOREGRP IGNOREPKG CHANGELOG LIST INFO RSORT SORT UNREQUIRED \
FOREIGN GROUP QUERYTYPE QUIET DEPENDS PRINT \
AURVOTEINSTALLED CUSTOMIZEPKGINSTALLED PACMAN_CMD \
NEEDED
NEEDED CACHE_DIR DOWNLOAD_ONLY_DIR

# Disable color if output is not a terminal
[[ -t 1 ]] || { ((USECOLOR!=2)) && USECOLOR=0; USEPAGER=0; TERMINALTITLE=0; }
Expand Down Expand Up @@ -364,14 +364,12 @@ while [[ $1 ]]; do
-u|--upgrades) (( UPGRADES ++ )); program_arg $A_PQ $1;;
-V|--version) version; exit 0;;
-v|--verbose) program_arg $((A_PQ | A_PS)) $1;;
-w|--downloadonly) PACMAN_CMD=1;;
-y|--refresh) (( REFRESH ++ ));;

--asdeps) program_arg $A_PS $1;;
--asexplicit) program_arg $A_PS $1;;
--assume-installed) program_arg $A_PS $1 "$2"; shift;;
--arch) program_arg $A_PC $1 "$2"; shift;;
--cachedir) program_arg $A_PC $1 "$2"; shift;;
--changelog) [[ ! $PACMAN_CMD ]] && PACMAN_CMD=0;;
--clean) ((CLEAN++));;
--color) USECOLOR=2;;
Expand Down Expand Up @@ -405,10 +403,12 @@ while [[ $1 ]]; do
-) break;; # support smth like echo package | yaourt -S -
-a|--aur) AUR=1; AURUPGRADE=1; AURSEARCH=1;;
-b|--build) ((BUILD++));;
-w|--downloadonly) DOWNLOAD_ONLY="1";;

--) shift; ARGS+=("$@"); break;;
--aur-url) AURURL=$2; shift;;
--backupfile) BACKUPFILE=$2; shift;;
--cachedir) CACHE_DIR="$2"; shift;;
--conflicts) QUERYTYPE=${1:2};;
--date) SORT=1;;
--depends) QUERYTYPE=${1:2};;
Expand Down Expand Up @@ -441,6 +441,8 @@ init_paths
init_color
[[ $PACMAN_CMD ]] && pacman_cmd $PACMAN_CMD

[[ $CACHE_DIR ]] && program_arg $A_PC --cachedir "$CACHE_DIR"

# No options
[[ -z $MAJOR ]] && yaourt_no_action
# Complete options
Expand Down