Issues
======
1. Both functions aim to do the same thing.
2. The current `validate_folder_is_empty` function uses an erroneous
way of checking if a folder is empty. `ls -A` returns zero on
success; it doesn't return the number of files and sub-folders. A
correct way to get the number of elements in a directory is to pipe
the output of `ls -A` to `wc -l`.
3. The `local_path` variable is used undefined in the current
`validate_directory_empty` function.
It just happens that the `local_path` variable is defined in all
but one of the callsites of this function so those calls work as
expected.
The other call to this function was
bogus (tests/regression/tools/clear/test_ust:323) because it uses
the `$TRACE_PATH` variable name.
Fixes
=====
- Merge both functions into one, keeping the name
`validate_directory_empty`,
- Fix the emptiness check,
- Fix usages of `validate_directory_empty` in tests.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Id75baf16f42866e3b978389f9aada4a2f6b6f2ae
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0
stop_lttng_tracing_ok $SESSION_NAME
do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0
stop_lttng_tracing_ok $SESSION_NAME
- validate_directory_empty $local_path
+ if [[ "$buffer_type" == "uid" ]]; then
+ validate_trace_empty $local_path
+ else # pid
+ validate_directory_empty $local_path
+ fi
destroy_lttng_session_ok $SESSION_NAME
}
destroy_lttng_session_ok $SESSION_NAME
}
if [[ "$buffer_type" == "uid" ]]; then
validate_trace_empty $TRACE_PATH
else # pid
if [[ "$buffer_type" == "uid" ]]; then
validate_trace_empty $TRACE_PATH
else # pid
- validate_directory_empty $TRACE_PATH
+
+ # The sessiond always created a `ust/ directory
+ # whenever the UST domain is active
+ validate_directory_empty $TRACE_PATH/ust/
add_context_lttng 1 -k "$@"
}
add_context_lttng 1 -k "$@"
}
-function validate_directory_empty ()
-{
- local trace_path=$1
-
- ls -A $local_path > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- pass "Directory empty"
- else
- fail "Directory empty"
- fi
-}
-
function wait_live_trace_ready ()
{
local url=$1
function wait_live_trace_ready ()
{
local url=$1
-function validate_folder_is_empty()
+function validate_directory_empty ()
+ local trace_path="$1"
+
+ files="$(ls -A "$trace_path")"
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ fail "Failed to list content of directory \"$trace_path\""
+ return $ret
+ fi
- test -z "$(ls -A "$folder")"
- ok $? "Folder ${folder} is empty"
+ nb_files="$(echo -n "$files" | wc -l)"
+ ok $nb_files "Directory \"$trace_path\" is empty"
}
function validate_trace_session_ust_empty()
{
}
function validate_trace_session_ust_empty()
{
- validate_folder_is_empty "$1"/ust
+ validate_directory_empty "$1"/ust
}
function validate_trace_session_kernel_empty()
}
function validate_trace_session_kernel_empty()