From 5f650f7d17f2e84950d20c15c023f6540fd1a94f Mon Sep 17 00:00:00 2001 From: jutty Date: Fri, 13 Sep 2024 21:57:31 -0300 Subject: [PATCH] Add file tracking status query function --- src/package/package_tracking.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/package/package_tracking.sh b/src/package/package_tracking.sh index 9567efc..633f24b 100644 --- a/src/package/package_tracking.sh +++ b/src/package/package_tracking.sh @@ -1,8 +1,26 @@ +# functions to track, untrack and query tracked state of packages + +# returns 0 if all packages are tracked, 1 if any is untracked +query_packages() { + local packages="$1" + + echo "$packages" | xargs | sed 's/ /\n/g' | while read -r package; do + if ! cat "$CONFIG_ROOT/packages" | grep -q "^$package$"; then + return 1 + fi + return 0 + done +} + track_packages() { local packages="$1" echo "$packages" | xargs | sed 's/ /\n/g' | while read -r package; do - echo "$package" >> "$CONFIG_ROOT/packages" + if query_packages "$package"; then + log info "Package $package was not tracked because it is already tracked" + else + echo "$package" >> "$CONFIG_ROOT/packages" + fi done }