@@ -65,6 +65,20 @@ while [[ $# -gt 0 ]]; do
6565 shift || true # ignore error when there are no more arguments
6666done
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+
6882if ${readonlyMode} ; then
6983 echo -e " ${COLOR_INFO} detectChangedFiles: Readonly mode activated. Change detection file won't be created.${COLOR_DEFAULT} " >&2
7084else
7488# Check if the paths parameter exist
7589if [ -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
8195for 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
91105done
92106
93107# Function to get file size
@@ -99,23 +113,46 @@ get_file_size() {
99113 fi
100114}
101115
116+ isMacOS () {
117+ [ " $( uname -s) " = " Darwin" ]
118+ }
119+
102120# Function to process a single path
103121file_names_and_sizes () {
104122 if [ -d " $1 " ]; then
123+ # TODO Remove after debugging
124+ echo " detectChangedFiles: Checking directory $1 " >&2
125+
105126 # If it's a directory, list all files inside
106127 # except for "node_modules", "target", "temp" and the change detection file itself
107- find -L " $1 " \
108- -type d -name " node_modules" -prune -o \
109- -type d -name " target" -prune -o \
110- -type d -name " temp" -prune -o \
111- -type d -name " .reports" -prune -o \
112- -not -path " ${hashFilePath} " \
113- -type f \
114- -exec stat -f " %N %z" {} + \
115- | sort
128+ if isMacOS; then
129+ find -L " $1 " \
130+ -type d -name " node_modules" -prune -o \
131+ -type d -name " target" -prune -o \
132+ -type d -name " temp" -prune -o \
133+ -type d -name " .reports" -prune -o \
134+ -not -path " ${hashFilePath} " \
135+ -type f \
136+ -exec stat -f " %N %z" {} + \
137+ | sort
138+ else
139+ find -L " $1 " \
140+ -type d -name " node_modules" -prune -o \
141+ -type d -name " target" -prune -o \
142+ -type d -name " temp" -prune -o \
143+ -type d -name " .reports" -prune -o \
144+ -not -path " ${hashFilePath} " \
145+ -type f \
146+ -exec stat --printf=" %n %s\n" {} + \
147+ | sort
148+ fi
116149 elif [ -f " $1 " ]; then
117- # If it's a file, just echo the file path
118- stat -f " %N %z" < " $1 "
150+ # The path is a file. Print its path and size.
151+ if isMacOS; then
152+ stat -f " %N %z" " $1 "
153+ else
154+ stat --printf=" %n %s\n" " $1 "
155+ fi
119156 fi
120157}
121158
@@ -157,7 +194,7 @@ if [ ! -f "${hashFilePath}" ] ; then
157194 echo -e " ${COLOR_INFO} detectChangedFiles: Skipping file creation with content (=hash) ${CURRENT_FILES_HASH}${COLOR_DEFAULT} " >&2
158195 fi
159196 echo 1 # 1=Change detected and change detection file created
160- exit 0
197+ exit_successful
161198fi
162199
163200# Assume that there is no change if the saved hash is equal to the current one.
0 commit comments