Patchwork [14/20] udev-cache: refactor; improve verbosity and error handling

login
register
mail settings
Submitter Ben Shelton
Date Aug. 4, 2014, 6:41 p.m.
Message ID <1b88abb2483607f2ed69b8fba1094f06ab73a212.1407177403.git.ben.shelton@ni.com>
Download mbox | patch
Permalink /patch/77231/
State New
Headers show

Comments

Ben Shelton - Aug. 4, 2014, 6:41 p.m.
From: Richard Tollerton <rich.tollerton@ni.com>

Most of /etc/init.d/udev-cache is in a conditional block which can be
replaced by a `[ ... ] || exit 0` to reduce nesting. This eliminates
a `rm -f` which was dead code anyway.

This also provides the opportunity to emit a few more messages if
VERBOSE is set, which may help with future debugging.

Finally, make installing the new $DEVCACHE_SYSCONF contingent on
successfully creating the cache tarball.

Natinst-Rally-ID: TA44427
Acked-by: Gratian Crisan <gratian.crisan@ni.com>
Natinst-ReviewBoard-ID: 58620
Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
---
 meta/recipes-core/udev/udev/udev-cache | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Patch

diff --git a/meta/recipes-core/udev/udev/udev-cache b/meta/recipes-core/udev/udev/udev-cache
index 29700e0..7eea5fb 100644
--- a/meta/recipes-core/udev/udev/udev-cache
+++ b/meta/recipes-core/udev/udev/udev-cache
@@ -23,13 +23,15 @@  if [ "$ROOTFS_READ_ONLY" = "yes" ]; then
     exit 0
 fi
 
-if [ "$DEVCACHE" != "" -a -e "$DEVCACHE_CURRENT_SYSCONF" ]; then
-	[ "${VERBOSE}" != "no" ] && echo "Populating dev cache"
-	(
-		tar czf "${DEVCACHE}.tmp" dev -C / $DEVCACHE_CREATE_OPTS
-		mv -f "${DEVCACHE}.tmp" "$DEVCACHE"
+[ "$DEVCACHE" != "" ] || exit 0
+[ "${VERBOSE}" == "no" ] || echo -n "$0: checking for ${DEVCACHE_CURRENT_SYSCONF}... "
+[ -e "$DEVCACHE_CURRENT_SYSCONF" ] || { echo "not found"; exit 0; }
+[ "${VERBOSE}" == "no" ] || echo "found; building cache."
+
+(
+	tar czf "${DEVCACHE}.tmp" dev -C / $DEVCACHE_CREATE_OPTS && \
+		mv -f "${DEVCACHE}.tmp" "$DEVCACHE" && \
 		mv "$DEVCACHE_CURRENT_SYSCONF" "$DEVCACHE_SYSCONF"
-	) &
-fi
+) &
 
 exit 0