flatcar-scripts/chroot_version_hooks.d/24_distfiles_migration
Brian Harring 7ee892d95a Mount bind external distfiles into the chroot.
Purpose of this is to allow us to avoid re-downloading everything
every time we rebuild the chroot.

This maintains two directories; host and target.  Future enhancement
involves collapsing this into one- this requires some host work however,
and has some potential gotchas in doing so.

Meanwhile, we now store distfiles in repo/distfiles/{host,target},
and mount bind repo/distfiles into /var/cache/distfiles.

An upgrade script in turn optimistically tries to move the content
into the new location; if it can't complete the move, it wipes the
content and the user has to redownload it (acceptable, if annoying).

BUG=chromium-os:13115
TEST=cbuildbot x86-generic-full

Change-Id: Iea96429df0e1fdc4ac0860fbce0daabc90c4c2a3
Reviewed-on: https://gerrit.chromium.org/gerrit/15189
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Brian Harring <ferringb@chromium.org>
Commit-Ready: Brian Harring <ferringb@chromium.org>
2012-02-06 21:49:37 -08:00

34 lines
1.2 KiB
Plaintext

# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Previously distfiles were stored entirely in the chroot, forcing us
# to download it everytime. This content is now stored externally, exposed
# to the chroot via mount binds.
#
# What we're doing here is moving any existing content from the old locations,
# into the new locations- which will already have a mount bind in place.
# If it *doesn't*, meaning parallel cros_sdk usage, we just wipe the content
# (user can redownload it after all).
#
# Once that's done, upgrade the chroot directory structure installing
# syms pointing back to the new location.
upgrade_path() {
local src="/var/lib/portage/$1"
local dest="/var/cache/distfiles/$2"
if [ -L "$src" ]; then
# Already upgraded- skip this one.
return 0
fi
# Suppress failures. User just has to download in that case.
sudo find "$src"/ -maxdepth 1 -mindepth 1 -exec sudo mv -t "$dest/" {} + || :
sudo rm -rf "$src"
sudo ln -s ../../cache/distfiles/"$2" "$src"
}
upgrade_path distfiles host
upgrade_path distfiles-target target
exit 0