sortbydeps: include local pkgs in dep graph

Detecting indirect dependencies by traversing a package's entire
dependency tree is prohibitively slow for larger transactions.  Instead
add local packages to the dependency graph.  This additionally requires
delaying dependency ordering for sync operations so that removed
packages may be excluded from dependency detection.

tests/sync012.py was also updated to ensure that the dependency cycle
was actually detected.

Fixes FS#37380

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
makepkg: allow empty source arrays

Necessary for metapackages.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
libalpm/db.c: default to ALPM_DB_USAGE_ALL

This allows existing front-ends other than pacman to continue working
normally.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
callback.c: check for negative xfered size

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
upgrade.c: use iterator variable

remote was being used to loop over itself, making the FREELIST
ineffective.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
check for -1 return value from getopt_long

getopt_long returns -1 when it has finished parsing all args.  A return
value of 0 indicates that a flag was set directly by getopt_long and
parsing should continue.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
alpm_handle: store lock file descriptor

There was a brief window between opening the file descriptor and
creating a stream to it.  If the process was interrupted during that
window the lock file would not be removed correctly.

The pid is no longer printed to the lock file as this was virtually
meaningless for lock files on NFS.

Fixes FS#35603

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
deps.c: pass alpm_list** to _alpm_recursedeps

Improves consistency and makes it clear that targs will be modified by
_alpm_recursedeps.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
_alpm_recursedeps: consider trans->add packages

Dependencies shouldn't be removed if a package being added also depends
on them.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
trans_prepare: always prepare removed packages

* allows proper combined add/remove transaction support with removal
  transaction flags honored
* adds the ability to use ALPM_TRANS_FLAG_RECURSE with sync transactions
  to remove unneeded dependencies of conflicts (but not the upgraded
  package itself)
* enforces proper ordering for removed conflicts on sync transactions

Fixes FS#9694

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>