@@ -70,7 +70,7 @@ get_file_size() {
7070}
7171
7272# Function to process a single path
73- unwind_directories () {
73+ file_names_and_sizes () {
7474 if [ -d " $1 " ]; then
7575 # If it's a directory, list all files inside
7676 # except for "node_modules", "target", "temp" and the change detection file itself
@@ -80,10 +80,11 @@ unwind_directories() {
8080 -type d -name " temp" -prune -o \
8181 -not -name " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE} " \
8282 -type f \
83+ -exec stat -f " %N %z" {} + \
8384 | sort
8485 elif [ -f " $1 " ]; then
8586 # If it's a file, just echo the file path
86- echo " $1 "
87+ stat -f " %N %z " < " $1 "
8788 fi
8889}
8990
@@ -92,16 +93,17 @@ unwind_directories() {
9293# and calculates the md5 hash for every of these .
9394get_md5_checksum_of_all_file_names_and_sizes () {
9495 local paths=${1}
96+ local total_paths; total_paths=$( echo " ${paths} " | awk -F ' [\t,]' ' {print NF}' )
9597 local files_and_sizes=" "
9698
9799 for path in ${paths// ,/ } ; do
98- files=$( unwind_directories " ${path} " )
99- for file in ${ files}; do
100- size =$( get_file_size " ${file} " )
101- files_and_sizes= " ${files_and_sizes}${file}${size} "
102- done
100+ local files; files =$( file_names_and_sizes " ${path} " )
101+ local files_and_sizes= " ${files_and_sizes}${ files}"
102+ local processed_paths =$(( processed_paths + 1 ) )
103+ local progress= $(( processed_paths * 100 / total_paths ))
104+ echo -ne " detectChangedArtifacts: Calculate checksum progress: [ $progress %] ( $processed_paths / $total_paths )\r " >&2
103105 done
104-
106+ echo " " >&2
105107 echo " ${files_and_sizes} " | openssl md5 | awk ' {print $2}'
106108}
107109
@@ -118,6 +120,8 @@ if [ ! -f "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}" ] ; then
118120 mkdir -p " ${ARTIFACTS_DIRECTORY} "
119121 echo " ${CURRENT_ARTIFACTS_HASH} " > " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH} "
120122 echo " detectChangedArtifacts: Change detection file created" >&2
123+ else
124+ echo " detectChangedArtifacts: Skipping file creation with content (=hash) ${CURRENT_ARTIFACTS_HASH} " >&2
121125 fi
122126 echo 1 # 1=Change detected and change detection file created
123127 exit 0
132136 # Write the updated hash into the file containing the hash of the files list for the next call
133137 echo " $CURRENT_ARTIFACTS_HASH " > " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH} "
134138 echo " detectChangedArtifacts: Change detection file updated" >&2
139+ else
140+ echo " detectChangedArtifacts: Skipping file update with content (=hash) ${CURRENT_ARTIFACTS_HASH} " >&2
135141 fi
136142 echo 2 # 2=Change detected and change detection file updated
137143fi
0 commit comments