Skip to content

Commit 03b18df

Browse files
committed
fixup! Introduce script testing
1 parent 1007e7b commit 03b18df

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

scripts/detectChangedFiles.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ while [[ $# -gt 0 ]]; do
6565
shift || true # ignore error when there are no more arguments
6666
done
6767

68+
exit_failed() {
69+
case "$0" in
70+
*/sh) return 1 ;; # Script is sourced
71+
*) exit 1 ;; # Script is executed directly
72+
esac
73+
}
74+
75+
exit_successful() {
76+
case "$0" in
77+
*/sh) return 0 ;; # Script is sourced
78+
*) exit 0 ;; # Script is executed directly
79+
esac
80+
}
81+
6882
if ${readonlyMode}; then
6983
echo -e "${COLOR_INFO}detectChangedFiles: Readonly mode activated. Change detection file won't be created.${COLOR_DEFAULT}" >&2
7084
else
@@ -74,8 +88,8 @@ fi
7488
# Check if the paths parameter exist
7589
if [ -z "${paths}" ] ; then
7690
echo 0 # 0=No change detected. The path list is empty. There is nothing to compare. Therefore assume that there are no changes.
77-
exit 0
78-
fi
91+
exit_successful
92+
fi
7993

8094
# Check all paths if they are valid files or valid directories
8195
for path in ${paths//,/ }; do
@@ -87,7 +101,7 @@ for path in ${paths//,/ }; do
87101
fi
88102
# Neither a valid directory and file
89103
echo -e "${COLOR_ERROR}detectChangedFiles: Error: Invalid path: ${path}${COLOR_DEFAULT}" >&2
90-
exit 1
104+
exit_failed
91105
done
92106

93107
# Function to get file size
@@ -102,6 +116,9 @@ get_file_size() {
102116
# Function to process a single path
103117
file_names_and_sizes() {
104118
if [ -d "$1" ]; then
119+
# TODO Remove after debugging
120+
echo "detectChangedFiles: Checking directory $1" >&2
121+
105122
# If it's a directory, list all files inside
106123
# except for "node_modules", "target", "temp" and the change detection file itself
107124
find -L "$1" \
@@ -114,6 +131,8 @@ file_names_and_sizes() {
114131
-exec stat -f "%N %z" {} + \
115132
| sort
116133
elif [ -f "$1" ]; then
134+
# TODO Remove after debugging
135+
echo "detectChangedFiles: Checking file $1" >&2
117136
# If it's a file, just echo the file path
118137
stat -f "%N %z" < "$1"
119138
fi
@@ -157,7 +176,7 @@ if [ ! -f "${hashFilePath}" ] ; then
157176
echo -e "${COLOR_INFO}detectChangedFiles: Skipping file creation with content (=hash) ${CURRENT_FILES_HASH}${COLOR_DEFAULT}" >&2
158177
fi
159178
echo 1 # 1=Change detected and change detection file created
160-
exit 0
179+
exit_successful
161180
fi
162181

163182
# Assume that there is no change if the saved hash is equal to the current one.

0 commit comments

Comments
 (0)