summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rwxr-xr-xmeta/recipes-core/volatile-binds/files/mount-copybind30
1 files changed, 26 insertions, 4 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind
index 2aeaf84ddb..fddf520053 100755
--- a/meta/recipes-core/volatile-binds/files/mount-copybind
+++ b/meta/recipes-core/volatile-binds/files/mount-copybind
@@ -8,7 +8,10 @@ if [ $# -lt 2 ]; then
8 exit 1 8 exit 1
9fi 9fi
10 10
11# e.g. /var/volatile/lib
11spec=$1 12spec=$1
13
14# e.g. /var/lib
12mountpoint=$2 15mountpoint=$2
13 16
14if [ $# -gt 2 ]; then 17if [ $# -gt 2 ]; then
@@ -20,15 +23,34 @@ fi
20[ -n "$options" ] && options=",$options" 23[ -n "$options" ] && options=",$options"
21 24
22mkdir -p "${spec%/*}" 25mkdir -p "${spec%/*}"
26
23if [ -d "$mountpoint" ]; then 27if [ -d "$mountpoint" ]; then
24 if [ ! -d "$spec" ]; then 28
29 if [ -d "$spec" ]; then
30 specdir_existed=yes
31 else
32 specdir_existed=no
25 mkdir "$spec" 33 mkdir "$spec"
26 cp -pPR "$mountpoint"/. "$spec/" 34 fi
35
36 # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work
37 overlay_workdir="${spec%/*}/.${spec##*/}-work"
38 mkdir "${overlay_workdir}"
39
40 # Try to mount using overlay, which is must faster than copying files.
41 # If that fails, fall back to slower copy.
42 if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir" "$mountpoint" > /dev/null 2>&1; then
43
44 if [ "$specdir_existed" != "yes" ]; then
45 cp -pPR "$mountpoint"/. "$spec/"
46 fi
47
48 mount -o "bind$options" "$spec" "$mountpoint"
27 fi 49 fi
28elif [ -f "$mountpoint" ]; then 50elif [ -f "$mountpoint" ]; then
29 if [ ! -f "$spec" ]; then 51 if [ ! -f "$spec" ]; then
30 cp -pP "$mountpoint" "$spec" 52 cp -pP "$mountpoint" "$spec"
31 fi 53 fi
32fi
33 54
34mount -o "bind$options" "$spec" "$mountpoint" 55 mount -o "bind$options" "$spec" "$mountpoint"
56fi