]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Avoid chellcheck warning SC2012 (ls for file list)
authorMartin Schwenke <martin@meltin.net>
Wed, 13 Jul 2016 01:50:58 +0000 (11:50 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 21 Jul 2016 00:24:27 +0000 (02:24 +0200)
SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

Make this cope better with unexpected whitespace.

Unfortunately, this results in shellcheck warning:

  SC2035: Use ./*.tdb.* so names with dashes won't become options.

No!  Then stat(1) will print ./file.tdb.X.  We want the basenames and
we know the filenames don't start with dashes.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/debug_locks.sh

index 5d4400443d97c6263ba95d1f61fbbfdc8093cf94..8c9b46657faf333ebc5d4a26e3ac48743214664b 100755 (executable)
@@ -24,11 +24,13 @@ loadconfig ctdb
 
     echo "===== Start of debug locks PID=$$ ====="
 
-    # Create sed expression to convert inodes to names
-    sed_cmd=$( ls -li "$CTDB_DBDIR"/*.tdb.* "$CTDB_DBDIR_PERSISTENT"/*.tdb.* |
-          sed -e "s#${CTDB_DBDIR}/\(.*\)#\1#" \
-              -e "s#${CTDB_DBDIR_PERSISTENT}/\(.*\)#\1#" |
-          awk '{printf "s#[0-9a-f]*:[0-9a-f]*:%s #%s #\n", $1, $10}' )
+    # Create sed expression to convert inodes to names.
+    # Filenames don't contain dashes and we want basenames
+    # shellcheck disable=SC2035
+    sed_cmd=$(cd "$CTDB_DBDIR" &&
+                 stat -c "s#[0-9a-f]*:[0-9a-f]*:%i #%n #" *.tdb.* 2>/dev/null ;
+             cd "$CTDB_DBDIR_PERSISTENT" &&
+                 stat -c "s#[0-9a-f]*:[0-9a-f]*:%i #%n #" *.tdb.* 2>/dev/null)
 
     # Parse /proc/locks and extract following information
     #    pid process_name tdb_name offsets [W]