@@ -16,12 +16,13 @@ set -o errexit -o pipefail
1616
1717# Overrideable defaults
1818ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:- " artifacts" }
19- ARTIFACTS_CHANGE_DETECTION_HASH_FILE=${ARTIFACTS_CHANGE_DETECTION_HASH_FILE:- " artifactsChangeDetectionHash.txt" } # Name of the file that contains the hash code of the file list for change detection
20- ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH=" ./${ARTIFACTS_DIRECTORY} /$ARTIFACTS_CHANGE_DETECTION_HASH_FILE "
19+ ARTIFACTS_CHANGE_DETECTION_HASH_FILE=${ARTIFACTS_CHANGE_DETECTION_HASH_FILE:- " artifactsChangeDetectionHash.txt" } # !DEPRECATED! Use CHANGE_DETECTION_HASH_FILE.
20+ CHANGE_DETECTION_HASH_FILE=${CHANGE_DETECTION_HASH_FILE:- " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE} " } # Name of the file that contains the hash code of the file list for change detection
21+ CHANGE_DETECTION_HASH_FILE_PATH=${CHANGE_DETECTION_HASH_FILE_PATH:- " ./${ARTIFACTS_DIRECTORY} /${CHANGE_DETECTION_HASH_FILE} " } # Path of the file that contains the hash code of the file list for change detection
2122
2223# Function to display script usage
2324usage () {
24- echo " Usage: $0 [--readonly] [--paths <comma separated list of file and directory names>]"
25+ echo " Usage: $0 [--readonly] [--paths <comma separated list of file and directory names> (default=artifacts) ]"
2526 exit 1
2627}
2728
@@ -43,18 +44,20 @@ while [[ $# -gt 0 ]]; do
4344 shift
4445 ;;
4546 * )
46- echo " detectChangedArtifacts : Error: Unknown option: ${key} "
47+ echo " detectChangedFiles : Error: Unknown option: ${key} "
4748 usage
4849 ;;
4950 esac
5051 shift || true # ignore error when there are no more arguments
5152done
5253
5354if ${readonlyMode} ; then
54- echo " detectChangedArtifacts: Readonly mode activated. Change detection file won't be created." >&2
55+ echo " detectChangedFiles: Readonly mode activated. Change detection file won't be created." >&2
56+ else
57+ echo " detectChangedFiles: ${CHANGE_DETECTION_HASH_FILE_PATH} will be used as change detection file." >&2
5558fi
5659
57- # Check if the artifacts directory exists
60+ # Check if the paths parameter exist
5861if [ -z " ${paths} " ] ; then
5962 echo 0 # 0=No change detected. The path list is empty. There is nothing to compare. Therefore assume that there are no changes.
6063 exit 0
@@ -78,7 +81,7 @@ file_names_and_sizes() {
7881 -type d -name " node_modules" -prune -o \
7982 -type d -name " target" -prune -o \
8083 -type d -name " temp" -prune -o \
81- -not -name " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE } " \
84+ -not -path " ${CHANGE_DETECTION_HASH_FILE_PATH } " \
8285 -type f \
8386 -exec stat -f " %N %z" {} + \
8487 | sort
@@ -101,7 +104,7 @@ get_md5_checksum_of_all_file_names_and_sizes() {
101104 local files_and_their_size; files_and_their_size=$( file_names_and_sizes " ${path} " )
102105 all_files_and_sizes=" ${all_files_and_sizes}${files_and_their_size} "
103106 processed_paths=$(( processed_paths + 1 ))
104- echo -ne " detectChangedArtifacts : Calculate checksum progress: ($processed_paths /$total_paths )\r" >&2
107+ echo -ne " detectChangedFiles : Calculate checksum progress: ($processed_paths /$total_paths )\r" >&2
105108 done
106109 echo " " >&2
107110 echo " ${all_files_and_sizes} " | openssl md5 | awk ' {print $2}'
@@ -111,33 +114,35 @@ get_md5_checksum_of_all_file_names_and_sizes() {
111114# sort the output, and pipe it to md5 to create a hash
112115# Use openssl md5 that is at least available on Mac and Linux.
113116# See: https://github.com/TRON-US/go-btfs/issues/90#issuecomment-517409369
114- CURRENT_ARTIFACTS_HASH =$( get_md5_checksum_of_all_file_names_and_sizes " ${paths} " )
117+ CURRENT_FILES_HASH =$( get_md5_checksum_of_all_file_names_and_sizes " ${paths} " )
115118
116119# Assume that the files where changed if the file containing the hash of the file list does not exist yet.
117- if [ ! -f " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH } " ] ; then
120+ if [ ! -f " ${CHANGE_DETECTION_HASH_FILE_PATH } " ] ; then
118121 if [ " ${readonlyMode} " = false ] ; then
122+ # Create the directory for the hash file if it hadn't existed yet.
123+ hash_file_directory=$( dirname " ${CHANGE_DETECTION_HASH_FILE_PATH} " )
124+ mkdir -p " ${hash_file_directory} "
119125 # Create the file containing the hash of the files list to a new file for the next call
120- mkdir -p " ${ARTIFACTS_DIRECTORY} "
121- echo " ${CURRENT_ARTIFACTS_HASH} " > " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH} "
122- echo " detectChangedArtifacts: Change detection file created" >&2
126+ echo " ${CURRENT_FILES_HASH} " > " ${CHANGE_DETECTION_HASH_FILE_PATH} "
127+ echo " detectChangedFiles: Change detection file created" >&2
123128 else
124- echo " detectChangedArtifacts : Skipping file creation with content (=hash) ${CURRENT_ARTIFACTS_HASH } " >&2
129+ echo " detectChangedFiles : Skipping file creation with content (=hash) ${CURRENT_FILES_HASH } " >&2
125130 fi
126131 echo 1 # 1=Change detected and change detection file created
127132 exit 0
128133fi
129134
130135# Assume that there is no change if the saved hash is equal to the current one.
131136# Otherwise assume that the files where changed and overwrite the hash with the current one for the next call
132- if [[ $( < " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH } " ) == " $CURRENT_ARTIFACTS_HASH " ]] ; then
137+ if [[ $( < " ${CHANGE_DETECTION_HASH_FILE_PATH } " ) == " $CURRENT_FILES_HASH " ]] ; then
133138 echo 0 # 0=No change detected
134139else
135140 if ! ${readonlyMode} ; then
136141 # Write the updated hash into the file containing the hash of the files list for the next call
137- echo " $CURRENT_ARTIFACTS_HASH " > " ${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH } "
138- echo " detectChangedArtifacts : Change detection file updated" >&2
142+ echo " $CURRENT_FILES_HASH " > " ${CHANGE_DETECTION_HASH_FILE_PATH } "
143+ echo " detectChangedFiles : Change detection file updated" >&2
139144 else
140- echo " detectChangedArtifacts : Skipping file update with content (=hash) ${CURRENT_ARTIFACTS_HASH } " >&2
145+ echo " detectChangedFiles : Skipping file update with content (=hash) ${CURRENT_FILES_HASH } " >&2
141146 fi
142147 echo 2 # 2=Change detected and change detection file updated
143148fi
0 commit comments