Releasing debian version 4.0~alpha39-1.
[debian-live-build.git] / functions / cache.sh
blob42d45d63af7cae022c7d10614500f8d16a81cd9f
1 #!/bin/sh
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
5 ##
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
11 Restore_cache ()
13 DIRECTORY="${1}"
15 if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ]
16 then
17 if [ -e "${DIRECTORY}" ]
18 then
19 # Restore old cache
20 if [ "$(stat --printf %d ${DIRECTORY})" = "$(stat --printf %d chroot/var/cache/apt/archives)" ]
21 then
22 # with hardlinks
23 find "${DIRECTORY}" -name "*.deb" | xargs cp -fl -t chroot/var/cache/apt/archives
24 else
25 # without hardlinks
26 find "${DIRECTORY}" -name "*.deb" | xargs cp -t chroot/var/cache/apt/archives
32 Save_cache ()
34 DIRECTORY="${1}"
36 if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ]
37 then
38 # Cleaning current cache
39 # In case of interrupted or incomplete builds, this may return an error,
40 # but we still do want to save the cache.
41 Chroot chroot "apt-get autoclean" || true
43 if ls chroot/var/cache/apt/archives/*.deb > /dev/null 2>&1
44 then
45 # Creating cache directory
46 mkdir -p "${DIRECTORY}"
48 # Saving new cache
49 for PACKAGE in chroot/var/cache/apt/archives/*.deb
51 if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ]
52 then
53 rm -f "${PACKAGE}"
54 else
55 mv "${PACKAGE}" "${DIRECTORY}"
57 done
59 else
60 # Purging current cache
61 rm -f chroot/var/cache/apt/archives/*.deb