Skip to content

Commit 079480a

Browse files
committed
fixup! Introduce script testing
1 parent 1007e7b commit 079480a

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

scripts/detectChangedFiles.sh

Lines changed: 29 additions & 6 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,8 +131,14 @@ file_names_and_sizes() {
114131
-exec stat -f "%N %z" {} + \
115132
| sort
116133
elif [ -f "$1" ]; then
117-
# If it's a file, just echo the file path
118-
stat -f "%N %z" < "$1"
134+
# TODO Remove after debugging
135+
echo "detectChangedFiles: Checking file $1" >&2
136+
# If it's a file, just echo the file path
137+
if [[ "$(uname)" == "Darwin" ]]; then
138+
stat -f "%N %z" "$1" # macOS
139+
else
140+
stat --printf="%n %s\n" "$1" # Linux
141+
fi
119142
fi
120143
}
121144

@@ -157,7 +180,7 @@ if [ ! -f "${hashFilePath}" ] ; then
157180
echo -e "${COLOR_INFO}detectChangedFiles: Skipping file creation with content (=hash) ${CURRENT_FILES_HASH}${COLOR_DEFAULT}" >&2
158181
fi
159182
echo 1 # 1=Change detected and change detection file created
160-
exit 0
183+
exit_successful
161184
fi
162185

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

0 commit comments

Comments
 (0)