Skip to content

Commit

Permalink
Fix for OSGi bundles listing (incorrect total and missing last line).…
Browse files Browse the repository at this point in the history
… Fix has been partially implemented in response to issue wttech#17.
  • Loading branch information
Jakub Wadolowski committed Jan 16, 2015
1 parent 267f798 commit afde14b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cqosgi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ symbolicName\":\"([^\"]+)\",\"category\":\"([^\"]*)\".*"
items=$(printf "%s" "${filtered_items}" \
| ${SEDX} "s#${REGEXP}#\1${TB}\6${TB}\4${TB}\5${TB}\2#"\
| sort -nk1 -t "${TB}")
total=$(printf "%s" "${items}" | wc -l | tr -d ' ')
total=$(printf "%s\n" "${items}" | wc -l | tr -d ' ')
if [ "${machine_friendly}" -eq 0 ]
then
printf "%s bundles\n\n" "${total}"
Expand All @@ -76,15 +76,15 @@ symbolicName\":\"([^\"]+)\",\"category\":\"([^\"]*)\".*"
fi
if [ "${machine_friendly}" -eq 1 ]
then
printf "%s" "${output}"
printf "%s\n" "${output}"
else
COLUMN=$(which column)
if [ ${?} -ne 0 -o -z "${COLUMN}" ]
then
echo "Cannot find column utility" >&2
exit 1
fi
printf "%s" "${output}" | tr '\t' "${SEP}" | ${COLUMN} -xt -c 5 \
printf "%s\n" "${output}" | tr '\t' "${SEP}" | ${COLUMN} -xt -c 5 \
-s "${SEP}" 2>/dev/null
fi
}
Expand Down

1 comment on commit afde14b

@kitarek
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jakub,

I cannot confirm that on my side I'm missing the last bundle. This seems a bit different on my system than on yours one.
This is almost the same patch as in 1.1.2 but you have additional \n in line 87:

+        printf "%s\n" "${output}" | tr '\t' "${SEP}" | ${COLUMN} -xt -c 5 \

Please have a look at my cqosgi patch in master

git diff HEAD~1 cqosgi

diff --git a/cqosgi b/cqosgi
index 6f968b3..625ca62 100755
--- a/cqosgi
+++ b/cqosgi
@@ -65,7 +65,7 @@ symbolicName\":\"([^\"]+)\",\"category\":\"([^\"]*)\".*"
     items=$(printf "%s" "${filtered_items}" \
         | ${SEDX} "s#${REGEXP}#\1${TB}\6${TB}\4${TB}\5${TB}\2#"\
         | sort -nk1 -t "${TB}")
-    total=$(printf "%s" "${items}" | wc -l | tr -d ' ')
+    total=$(printf "%s\n" "${items}" | wc -l | tr -d ' ')
     if [ "${machine_friendly}" -eq 0 ]
     then
         printf "%s bundles\n\n" "${total}"
@@ -76,7 +76,7 @@ symbolicName\":\"([^\"]+)\",\"category\":\"([^\"]*)\".*"
     fi
     if [ "${machine_friendly}" -eq 1 ]
     then
-        printf "%s" "${output}"
+        printf "%s\n" "${output}"
     else
         COLUMN=$(which column)
         if [ ${?} -ne 0 -o -z "${COLUMN}" ]

For my system it seems that I don't have problems in any mode for both dash and bash shells.
Please have a look at my instance bundle line state in OSGI:

Bundle information: 324 bundles in total, 316 bundles active, 8 active fragments, 0 bundles resolved, 0 bundles installed.

My tests (-j option is JSON raw format obtained directly from CQ) for master branch:

$ cqosgi -j -u admin | grep -o 'Fragment' | grep -c 'Fragment'
8
$ cqosgi -j -u admin | grep -o 'Active' | grep -c 'Active'
316

Machine format:

$ cqosgi -m -u admin | grep -o 'Active' | grep -c 'Active'
316
$ cqosgi -m -u admin | grep -o 'Fragment' | grep -c 'Fragment'
8

Pretty printed format:

$ cqosgi -u admin | grep -o 'Fragment' | grep -c 'Fragment'
8
$ cqosgi -u admin | grep -o 'Active' | grep -c 'Active'
316

I even have correct line ending for pretty printed format. The last line is correctly ended with \n.

Could you please confirm if you have similar tests on 1.1.2.
Default shell:
$ readlink -f /bin/sh
/usr/bin/bash

My bash version:
$ bash -version
GNU bash, wersja 4.3.33(1)-release (x86_64-unknown-linux-gnu)

I'm not against merging this patch but I would like to figure out potentially dangerous differences between our systems.

Thanks in advance,
Arek

Please sign in to comment.