@@ -65,6 +65,20 @@ while [[ $# -gt 0 ]]; do
65
65
shift || true # ignore error when there are no more arguments
66
66
done
67
67
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
+
68
82
if ${readonlyMode} ; then
69
83
echo -e " ${COLOR_INFO} detectChangedFiles: Readonly mode activated. Change detection file won't be created.${COLOR_DEFAULT} " >&2
70
84
else
74
88
# Check if the paths parameter exist
75
89
if [ -z " ${paths} " ] ; then
76
90
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
79
93
80
94
# Check all paths if they are valid files or valid directories
81
95
for path in ${paths// ,/ } ; do
@@ -87,7 +101,7 @@ for path in ${paths//,/ }; do
87
101
fi
88
102
# Neither a valid directory and file
89
103
echo -e " ${COLOR_ERROR} detectChangedFiles: Error: Invalid path: ${path}${COLOR_DEFAULT} " >&2
90
- exit 1
104
+ exit_failed
91
105
done
92
106
93
107
# Function to get file size
@@ -102,6 +116,9 @@ get_file_size() {
102
116
# Function to process a single path
103
117
file_names_and_sizes () {
104
118
if [ -d " $1 " ]; then
119
+ # TODO Remove after debugging
120
+ echo " detectChangedFiles: Checking directory $1 " >&2
121
+
105
122
# If it's a directory, list all files inside
106
123
# except for "node_modules", "target", "temp" and the change detection file itself
107
124
find -L " $1 " \
@@ -114,8 +131,14 @@ file_names_and_sizes() {
114
131
-exec stat -f " %N %z" {} + \
115
132
| sort
116
133
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
119
142
fi
120
143
}
121
144
@@ -157,7 +180,7 @@ if [ ! -f "${hashFilePath}" ] ; then
157
180
echo -e " ${COLOR_INFO} detectChangedFiles: Skipping file creation with content (=hash) ${CURRENT_FILES_HASH}${COLOR_DEFAULT} " >&2
158
181
fi
159
182
echo 1 # 1=Change detected and change detection file created
160
- exit 0
183
+ exit_successful
161
184
fi
162
185
163
186
# Assume that there is no change if the saved hash is equal to the current one.
0 commit comments