Patchwork [V2,4/5] populate-volatile.sh: improve the handling of link config items

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Feb. 20, 2013, 9:36 a.m.
Message ID <333ad1f10e30bb33a4cc7d9f2447d0bf8d3255d0.1361352762.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/44917/
State Accepted
Commit a54287d8e3d75a727c8ed5654a822bda256b0849
Headers show

Comments

Qi.Chen@windriver.com - Feb. 20, 2013, 9:36 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

Previously, if there's a link config item in the config file like

	    l root root 1777 /tmp /var/tmp

and /tmp has existed, the symlink will not be created correctly.

Another example is the /run directory. If /run directory has been
created by some recipe or script before populate-volatile.sh runs,
the symlink of /run to /var/run will not be created correctly.

This patch ensures that the system creates symlinks exactly as the
config file tells it.

[YOCTO #3404]
[YOCTO #3406]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 .../initscripts-1.0/populate-volatile.sh           |   37 +++++++++++---------
 1 file changed, 21 insertions(+), 16 deletions(-)

Patch

diff --git a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
index c4bf70e..fec3b0c 100755
--- a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
+++ b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
@@ -68,20 +68,27 @@  mk_dir() {
 }
 
 link_file() {
-	EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/tty0 2>&1" 
+	EXEC="
+	if [ -L \"$2\" ]; then
+		[ \"\$(readlink -f \"$2\")\" != \"\$(readlink -f \"$1\")\" ] && { rm -f \"$2\"; ln -sf \"$1\" \"$2\"; };
+	elif [ -d \"$2\" ]; then
+		for f in $2/* $2/.[^.]*; do [ -e \$f ] && cp -rf \$f $1; done;
+		rm -rf \"$2\";
+		ln -sf \"$1\" \"$2\";
+	else
+		ln -sf \"$1\" \"$2\";
+	fi
+        "
 
 	test "$VOLATILE_ENABLE_CACHE" = yes && echo "	$EXEC" >> /etc/volatile.cache.build
-	[ -e "$2" ] && {
-		echo "Cannot create link over existing -${TNAME}-." >&2
-	} || {
-		if [ "$ROOT_DIR" = "/" ]; then
-			eval $EXEC &
-		else
-			# For the same reason with create_file(), failures should
-			# not be logged.
-			eval $EXEC > /dev/null 2>&1 &
-		fi
-	}
+
+	if [ "$ROOT_DIR" = "/" ]; then
+		eval $EXEC &
+	else
+		# For the same reason with create_file(), failures should
+		# not be logged.
+		eval $EXEC > /dev/null 2>&1 &
+	fi
 }
 
 check_requirements() {
@@ -148,10 +155,8 @@  apply_cfgfile() {
 
 		[ "${TTYPE}" = "l" ] && {
 			TSOURCE="$TLTARGET"
-			[ -L "${TNAME}" ] || {
-				[ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
-				link_file "${TSOURCE}" "${TNAME}" &
-			}
+			[ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
+			link_file "${TSOURCE}" "${TNAME}" &
 			continue
 		}