@@ -27,29 +27,39 @@ if ! validate_compression "${COMPRESS}"; then
2727 exit 1
2828fi
2929
30- SAVE_LEVELS=()
31- if plugin_read_list_into_result SAVE ; then
32- for LEVEL in " ${result[@]} " ; do
33- SAVE_LEVELS+=( " ${LEVEL} " )
30+ if ! plugin_read_list_into_result SAVE ; then
31+ echo ' Cache not setup for saving '
32+ exit 0
33+ fi
3434
35- # this validates the level as well
36- KEY= $( build_key " ${LEVEL} " " ${CACHE_PATH} " " ${COMPRESS} " )
35+ ORDERED_LEVELS=(file step branch pipeline all)
36+ SAVE_LEVELS=( )
3737
38- if [ " ${LEVEL} " = ' file' ] && [ -z " $( plugin_read_config MANIFEST) " ]; then
39- echo " +++ 🚨 Missing manifest option in the cache plugin for file-level saving"
40- exit 1
38+ # array intersection keeping the order of the first array
39+ for O_LEVEL in " ${ORDERED_LEVELS[@]} " ; do
40+ for R_LEVEL in " ${result[@]} " ; do
41+ if [ " ${O_LEVEL} " = " ${R_LEVEL} " ]; then
42+ SAVE_LEVELS+=(" ${O_LEVEL} " )
4143 fi
4244 done
43- else
44- echo ' Cache not setup for saving'
45- exit 0
45+ done
46+
47+ if [ " ${# SAVE_LEVELS[@]} " -ne " ${# result[@]} " ]; then
48+ echo ' Invalid levels in the save list'
49+ exit 1
4650fi
4751
4852ACTUAL_PATH=" ${CACHE_PATH} "
4953
5054for LEVEL in " ${SAVE_LEVELS[@]} " ; do
55+ # this validates the level as well
5156 KEY=$( build_key " ${LEVEL} " " ${CACHE_PATH} " " ${COMPRESS} " )
5257
58+ if [ " ${LEVEL} " = ' file' ] && [ -z " $( plugin_read_config MANIFEST) " ]; then
59+ echo " +++ 🚨 Missing manifest option in the cache plugin for file-level saving"
60+ exit 1
61+ fi
62+
5363 if [ " $( plugin_read_config FORCE ' false' ) " != ' false' ] ||
5464 [ " ${lower_level_updated:- false} " = ' true' ] ||
5565 ! backend_exec exists " ${KEY} " ; then
0 commit comments