~asac/live-build/virtual-hdd-mtab-hack

« back to all changes in this revision

Viewing changes to functions/cache.sh

  • Committer: Daniel Baumann
  • Date: 2009-11-22 13:38:00 UTC
  • Revision ID: git-v1:a62f12110b19a52a58d7eae871012202cfa16055
Renaming categories to archive areas (Closes: #519690).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# cache.sh - manage package cache
 
4
# Copyright (C) 2006-2009 Daniel Baumann <daniel@debian.org>
 
5
#
 
6
# live-helper 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.
 
9
 
 
10
Restore_cache ()
 
11
{
 
12
        DIRECTORY="${1}"
 
13
 
 
14
        if [ "${LH_CACHE}" = "enabled" ] && [ "${LH_CACHE_PACKAGES}" = "enabled" ]
 
15
        then
 
16
                if [ -d "${DIRECTORY}" ]
 
17
                then
 
18
                        # Restore old cache
 
19
                        if [ "$(stat --printf %d ${DIRECTORY})" = "$(stat --printf %d chroot/var/cache/apt/archives)" ]
 
20
                        then
 
21
                                # with hardlinks
 
22
                                cp -fl "${DIRECTORY}"/*.deb chroot/var/cache/apt/archives
 
23
                        else
 
24
                                # without hardlinks
 
25
                                cp "${DIRECTORY}"/*.deb chroot/var/cache/apt/archives
 
26
                        fi
 
27
                fi
 
28
        fi
 
29
}
 
30
 
 
31
Save_cache ()
 
32
{
 
33
        DIRECTORY="${1}"
 
34
 
 
35
        if [ "${LH_CACHE}" = "enabled" ] && [ "${LH_CACHE_PACKAGES}" = "enabled" ]
 
36
        then
 
37
                # Cleaning current cache
 
38
                Chroot chroot "apt-get autoclean"
 
39
 
 
40
                if ls chroot/var/cache/apt/archives/*.deb > /dev/null 2>&1
 
41
                then
 
42
                        # Creating cache directory
 
43
                        mkdir -p "${DIRECTORY}"
 
44
 
 
45
                        # Saving new cache
 
46
                        for PACKAGE in chroot/var/cache/apt/archives/*.deb
 
47
                        do
 
48
                                if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ]
 
49
                                then
 
50
                                        rm -f "${PACKAGE}"
 
51
                                else
 
52
                                        mv "${PACKAGE}" "${DIRECTORY}"
 
53
                                fi
 
54
                        done
 
55
                fi
 
56
        else
 
57
                # Purging current cache
 
58
                rm -f chroot/var/cache/apt/archives/*.deb
 
59
        fi
 
60
}