pkg_cache_data(): No need to mkdir -p, pkg_cache_dir() already does
Use a shadow directory with hard links during build

This keeps the repository untouched until the very end. It is not quite
atomic yet, but is better than having the repository broken for several
hours or days while a build is running, or has failed.

The repository is only 'committed' if the build does not crash. Failing
packages still will not be in the new repository yet. Keeping old packages
may come later.
Implement fully atomic package repository updating.

This builds on the previous commit which runs the build in a shadow
directory of hardlinks.

The new format entails moving all top-level package files and dirs,
such as repo.txz, All/ and Latest, to a .real_TS directory.

There is a .latest symlink that just points to the .real_TS directory.

Then all top-level files/dirs point to .latest/FILE

This allows the completion of package building to just update the .latest
symlink to point to the new repository location atomically.

On first run, the repository will be updated to the new format.
Add ATOMIC_PACKAGE_REPOSITORY option to allow disabling
bulk: Add -n for dry-run mode.

No packages will actually be deleted or built. Show what would
be done. Requires ATOMIC_PACKAGE_REPOSITORY to be enabled
bulk -c: Move cleaning so that it supports -n
Add KEEP_OLD_PACKAGES which will keep KEEP_OLD_PACKAGES_COUNT number of old repositories.

This can be useful for rollbacks or bisecting. Requires
ATOMIC_PACKAGE_REPOSITORY

Default: no

Suggested by:	will
Ticket:		[a69b25cefd]
When committing packages, symlink new top-level dirs
When committing packages, delete broken top-level links
ln(1) is not atomic, but mv(1)->rename(2) is
Fix creating initial package repository
Atomic repo: If the build fails, keep the packages for the next build

Ticket:	[5ca5cc78fc]
Set defaults for global vars once in common.sh
Move log_path() by similar functions
pkg_cache_dir(): Avoid forking
cache_dir(): Avoid forking
pkg_get_origin(): Avoid forking

Rename origin to _origin in pkg_get_origin() to avoid eating variable
"origin" in parent space due to being local
deps_file(): Avoid forking

Rename depfile to _depfile in deps_file() to avoid 'local depfile'
eating the result in the parent if it passes in "depfile" as the
var name.
pkg_get_dep_origin(): Avoid forking
cache_get_pkgname(): Avoid forking

Rename pkgname to _pkgname in cache_get_pkgname() to avoid
local clash with parent namespace