aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2016-12-24 22:27:30 +0100
committerLeah Rowe <info@minifree.org>2017-01-15 14:24:46 +0000
commitd0b1906801bd62029acd6ae9c015d95ab33af657 (patch)
tree09730ded73eb33dbb974d3e9da26dd81cccc27e2 /libs
parent4394e7ef874398eeb22922b395c5a0880a28d7bf (diff)
downloadlibrebootfr-d0b1906801bd62029acd6ae9c015d95ab33af657.tar.gz
librebootfr-d0b1906801bd62029acd6ae9c015d95ab33af657.zip
libs: tool: Add utility functions for files
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'libs')
-rwxr-xr-xlibs/tool82
1 files changed, 82 insertions, 0 deletions
diff --git a/libs/tool b/libs/tool
index 889ee8d5..6bf57be1 100755
--- a/libs/tool
+++ b/libs/tool
@@ -285,3 +285,85 @@ tool_usage_arguments_recursive() {
done
fi
}
+
+tool_file_path() {
+ local tool=$1
+ shift
+ local directory=$1
+ shift
+ local file=$1
+ shift
+
+ local tool_path=$( tool_path "$tool" )
+ local path="$tool_path/$directory"
+ local argument
+ local file_path
+
+ for argument in "" "$@"
+ do
+ if ! [ -z "$argument" ]
+ then
+ path="$path/$argument"
+ fi
+
+ if ! [ -f "$path/$file" ]
+ then
+ continue
+ fi
+
+ file_path="$path/$file"
+ done
+
+ if [ -z "$file_path" ]
+ then
+ return 1
+ fi
+
+ echo "$file_path"
+}
+
+tool_file_test() {
+ local file_path=$( tool_file_path "$@" )
+
+ test -f "$file_path"
+}
+
+tool_file_contents() {
+ local file_path=$( tool_file_path "$@" )
+
+ if [ -f "$file_path" ]
+ then
+ cat "$file_path"
+ fi
+}
+
+tool_file_contents_herit() {
+ local tool=$1
+ shift
+ local directory=$1
+ shift
+ local file=$1
+ shift
+
+ local tool_path=$( tool_path "$tool" )
+ local path="$tool_path/$directory"
+ local argument
+ local file_path
+
+ for argument in "" "$@"
+ do
+ if ! [ -z "$argument" ]
+ then
+ path="$path/$argument"
+ fi
+
+ file_path="$path/$file"
+
+ if ! [ -f "$file_path" ]
+ then
+ continue
+ fi
+
+ cat "$file_path"
+ done
+}