diff options
| -rwxr-xr-x | meta/recipes-core/volatile-binds/files/mount-copybind | 30 |
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 |
| 9 | fi | 9 | fi |
| 10 | 10 | ||
| 11 | # e.g. /var/volatile/lib | ||
| 11 | spec=$1 | 12 | spec=$1 |
| 13 | |||
| 14 | # e.g. /var/lib | ||
| 12 | mountpoint=$2 | 15 | mountpoint=$2 |
| 13 | 16 | ||
| 14 | if [ $# -gt 2 ]; then | 17 | if [ $# -gt 2 ]; then |
| @@ -20,15 +23,34 @@ fi | |||
| 20 | [ -n "$options" ] && options=",$options" | 23 | [ -n "$options" ] && options=",$options" |
| 21 | 24 | ||
| 22 | mkdir -p "${spec%/*}" | 25 | mkdir -p "${spec%/*}" |
| 26 | |||
| 23 | if [ -d "$mountpoint" ]; then | 27 | if [ -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 |
| 28 | elif [ -f "$mountpoint" ]; then | 50 | elif [ -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 |
| 32 | fi | ||
| 33 | 54 | ||
| 34 | mount -o "bind$options" "$spec" "$mountpoint" | 55 | mount -o "bind$options" "$spec" "$mountpoint" |
| 56 | fi | ||
