lib/update.utils
changeset 98 a3734856e0fa
parent 95 a756f317d083
--- a/lib/update.utils	Sat Dec 21 22:43:38 2013 +0200
+++ b/lib/update.utils	Sun Dec 22 15:33:32 2013 +0200
@@ -60,36 +60,40 @@
     echo "$SRV/$path"
 }
 
+function _list {
+    local glob="$1"
+    local test="$2"
+    local prefix="$3"
+
+    for file in $glob; do
+        [ $test "$file" ] || continue
+        [ -n "$prefix" ] && file="${file#$prefix}"
+
+        echo -n "$file "
+    done
+}
+
+## List names of all files in dir
+function list {
+    _list "$1/*" '-e' ${2:-$1/}
+}
+
 ## List names of files in dir:
 #
-#   list_files $dir $glob
+#   list_files $dir
 #
 function list_files {
-    local dir="$1"
-    local glob="${2:-*}"
-    local name=
-
-    for file in $dir/$glob; do
-        # only files
-        [ -f "$file" ] || continue
-
-        # strip prefix
-        name=${file#$dir/}
-        name=${name%$glob}
-
-        echo -n "$name "
-    done
+    _list "$1/*" '-f' ${2:-$1/}
 }
 
 ## List names of dirs in dir:
 function list_dirs {
-    local dir="$1"
+    _list "$1/*" '-d' ${2:-$1/}
+}
 
-    for file in $dir/*; do
-        [ -d "$file" ] || continue
-
-        echo -n "${file#$dir/} "
-    done
+## List names of any files underneath dir or file:
+function expand_files {
+    _list "$1 $1/**" '-f' ''
 }
 
 ## Get current unix (utc) timestamp