@@ -793,7 +793,7 @@ initialize()
793793 DATA_INIT_STATUS=1
794794 ui_debug " Mounted: ${DATA_PATH:- } "
795795 else
796- ui_warning " The data partition cannot be mounted, so updates of installed / removed apps cannot be deleted and their Dalvik cache cannot be cleaned, but it doesn't matter if you do a factory reset"
796+ ui_warning " The data partition cannot be mounted, so updates of installed / removed apps cannot be automatically deleted and their Dalvik cache cannot be automatically cleaned. I suggest to manually do a factory reset after flashing this ZIP. "
797797 fi
798798 fi
799799 readonly DATA_PATH
@@ -876,7 +876,7 @@ clean_previous_installations()
876876 ui_error " Something is wrong because '${SYS_PATH?} ' is NOT really writable!!!"
877877 fi
878878
879- _initial_free_space=" $( _get_free_space ) " || _initial_free_space=' -1'
879+ _initial_free_space=" $( get_free_disk_space_of_partition " ${SYS_PATH :? } " ) " || _initial_free_space=' -1'
880880
881881 rm -f -- " ${SYS_PATH:? } /etc/write-test-file.dat" || ui_error ' Failed to delete the test file'
882882
@@ -1006,11 +1006,11 @@ _something_exists()
10061006 return 1
10071007}
10081008
1009- _get_free_space ()
1009+ _get_free_disk_space_of_partition_using_df ()
10101010{
10111011 local _skip_first=' true'
10121012
1013- df -P -- " ${SYS_MOUNTPOINT :? } " | while IFS=' ' read -r _ _ _ available_space _; do
1013+ df -B1 - P -- " ${1 :? } " | while IFS=' ' read -r _ _ _ available_space _; do
10141014 if test " ${_skip_first?} " = ' true' ; then
10151015 _skip_first=' false'
10161016 continue
@@ -1027,14 +1027,16 @@ _get_free_space()
10271027
10281028_wait_free_space_changes ()
10291029{
1030- local _max_attempts=' 15'
1030+ local _max_attempts
1031+
1032+ _max_attempts=' 15'
10311033 if test -n " ${1?} " ; then _max_attempts=" ${1:? } " ; fi
10321034
10331035 printf ' Waiting..'
10341036
10351037 while test " ${_max_attempts:? } " -gt 0 && _max_attempts=" $(( _max_attempts - 1 )) " ; do
10361038 printf ' .'
1037- if test " $( _get_free_space || true ) " ! = " ${2:? } " ; then
1039+ if test " $( get_free_disk_space_of_partition " ${SYS_PATH :? } " || : ) " ! = " ${2:? } " ; then
10381040 break
10391041 fi
10401042 sleep 1
@@ -1058,7 +1060,7 @@ _do_rollback_last_app_internal()
10581060 local _backup_ifs _skip_first _initial_free_space _vanity_name _installed_file_list
10591061 if test ! -s " ${TMP_PATH:? } /processed-${1:? } s.log" ; then return 1; fi
10601062
1061- _initial_free_space=" $( _get_free_space ) " || return 2
1063+ _initial_free_space=" $( get_free_disk_space_of_partition " ${SYS_PATH :? } " ) " || return 2
10621064 _installed_file_list=" $( tail -n ' 1' -- " ${TMP_PATH:? } /processed-${1:? } s.log" ) " || ui_error " Failed to read processed-${1?} s.log"
10631065 test -n " ${_installed_file_list?} " || return 3
10641066
@@ -1087,7 +1089,7 @@ _do_rollback_last_app_internal()
10871089 _wait_free_space_changes ' ' " ${_initial_free_space:? } " # Reclaiming free space may take some time
10881090 ui_debug ' '
10891091
1090- sed -ie ' $ d' -- " ${TMP_PATH:? } /processed-${1:? } s.log" || ui_error " Failed to remove the last line from read processed-${1?} s.log"
1092+ sed -ie ' $ d' " ${TMP_PATH:? } /processed-${1:? } s.log" || ui_error " Failed to remove the last line from processed-${1?} s.log"
10911093
10921094 if command 1> /dev/null -v ' rollback_complete_callback' ; then
10931095 export CURRENTLY_ROLLBACKING=' true'
@@ -1124,16 +1126,55 @@ _is_free_space_error()
11241126 return 1 # NOT found
11251127}
11261128
1129+ get_size_of_file ()
1130+ {
1131+ local _stat_result
1132+
1133+ if _stat_result=" $( stat 2> /dev/null -c ' %s' -- " ${1:? } " ) " ; then
1134+ : # OK
1135+ elif test -n " ${DEVICE_STAT?} " && _stat_result=" $( PATH=" ${PREVIOUS_PATH:? } " " ${DEVICE_STAT:? } " -c ' %s' -- " ${1:? } " ) " ; then
1136+ : # OK
1137+ else
1138+ _stat_result=' '
1139+ fi
1140+
1141+ if test -n " ${_stat_result?} " && printf ' %s\n' " ${_stat_result:? } " ; then
1142+ return 0
1143+ fi
1144+
1145+ return 1
1146+ }
1147+
1148+ get_free_disk_space_of_partition ()
1149+ {
1150+ local _stat_result
1151+
1152+ if _stat_result=" $( stat 2> /dev/null -f -c ' %f * %S' -- " ${1:? } " ) " ; then
1153+ : # OK
1154+ elif test -n " ${DEVICE_STAT?} " && _stat_result=" $( PATH=" ${PREVIOUS_PATH:? } " " ${DEVICE_STAT:? } " 2> /dev/null -f -c ' %f * %S' -- " ${1:? } " ) " ; then
1155+ : # OK
1156+ else
1157+ _stat_result=' '
1158+ fi
1159+
1160+ if test -n " ${_stat_result?} " && printf ' %s\n' " $(( _stat_result)) " ; then
1161+ return 0
1162+ fi
1163+
1164+ printf ' %s\n' ' -1'
1165+ return 1
1166+ }
1167+
11271168get_disk_space_usage_of_file_or_folder ()
11281169{
11291170 local _result
11301171
1131- if _result=" $( du 2> /dev/null -s -B 1 -- " ${1:? } " | cut -f 1 -s) " && test -n " ${_result?} " ; then
1132- printf ' %u \n' " ${_result:? } "
1172+ if _result=" $( du 2> /dev/null -s -B1 -- " ${1:? } " | cut -f 1 -s) " && test -n " ${_result?} " ; then
1173+ printf ' %s \n' " ${_result:? } "
11331174 elif _result=" $( du -s -k -- " ${1:? } " | cut -f 1 -s) " && test -n " ${_result?} " ; then
1134- printf ' %u \n' " $(( _result * 1024 )) "
1175+ printf ' %s \n' " $(( _result * 1024 )) "
11351176 else
1136- printf ' %d \n' ' -1'
1177+ printf ' %s \n' ' -1'
11371178 return 1
11381179 fi
11391180}
@@ -1184,21 +1225,30 @@ verify_disk_space()
11841225{
11851226 local _needed_space_bytes _free_space_bytes
11861227
1187- _needed_space_bytes=" $( get_disk_space_usage_of_file_or_folder " ${TMP_PATH:? } /files" ) " || _needed_space_bytes=' -1'
1188- _free_space_bytes=" $(( $(stat - f - c '% f * % S' -- "${1:? } ")) )" || _free_space_bytes=' -1'
1228+ if _needed_space_bytes=" $( get_disk_space_usage_of_file_or_folder " ${TMP_PATH:? } /files" ) " && test -n " ${_needed_space_bytes?} " ; then
1229+ ui_msg " Disk space required: $( convert_bytes_to_mb " ${_needed_space_bytes:? } " || :) MB"
1230+ else
1231+ _needed_space_bytes=' -1'
1232+ fi
11891233
1190- ui_msg " Disk space required: $( convert_bytes_to_mb " ${_needed_space_bytes:? } " || true) MB"
1191- ui_msg " Free disk space: $( convert_bytes_to_mb " ${_free_space_bytes:? } " || true) MB ($( convert_bytes_to_human_readable_format " ${_free_space_bytes:? } " || true) )"
1234+ if _free_space_bytes=" $( get_free_disk_space_of_partition " ${1:? } " ) " && test -n " ${_free_space_bytes?} " ; then
1235+ ui_msg " Free disk space: $( convert_bytes_to_mb " ${_free_space_bytes:? } " || :) MB ($( convert_bytes_to_human_readable_format " ${_free_space_bytes:? } " || :) )"
1236+ else
1237+ ui_warning " Unable to get free disk space, output for '${1?} ' => $( stat -f -c ' %f * %S' -- " ${1:? } " || :) "
1238+ _free_space_bytes=' -1'
1239+ fi
11921240
1193- if test " ${_needed_space_bytes:? } " -lt 0 || test " ${_free_space_bytes:? } " -lt 0; then
1241+ if test " ${_needed_space_bytes:? } " -gt 0 && test " ${_free_space_bytes:? } " -ge 0; then
1242+ : # OK
1243+ else
11941244 ui_msg_empty_line
1195- ui_warning " Unable to verify needed space, continuing anyway"
1245+ ui_warning ' Unable to verify needed space, continuing anyway'
11961246 return 0
11971247 fi
11981248
1199- if test " ${_needed_space_bytes :? } " -ge " ${_free_space_bytes :? } " ; then return 1 ; fi
1249+ if test " ${_free_space_bytes :? } " -gt " ${_needed_space_bytes :? } " ; then return 0 ; fi
12001250
1201- return 0
1251+ return 1
12021252}
12031253
12041254perform_secure_copy_to_device ()
@@ -1230,8 +1280,15 @@ perform_secure_copy_to_device()
12301280 touch 2> /dev/null " ${SYS_PATH:? } /etc/zips/${MODULE_ID:? } .failed" || :
12311281
12321282 ui_debug ' '
1233- df -h -T -- " ${SYS_MOUNTPOINT:? } " || true
1283+ df 2> /dev/null -B1 -P -- " ${SYS_MOUNTPOINT:? } " || :
12341284 ui_debug ' '
1285+ df 2> /dev/null -h -T -- " ${SYS_MOUNTPOINT:? } " || df -h -- " ${SYS_MOUNTPOINT:? } " || :
1286+ ui_debug ' '
1287+
1288+ local _free_space_bytes
1289+ if _free_space_bytes=" $( get_free_disk_space_of_partition " ${SYS_PATH:? } " ) " && test -n " ${_free_space_bytes?} " ; then
1290+ ui_debug " Free disk space: $( convert_bytes_to_mb " ${_free_space_bytes:? } " || :) MB ($( convert_bytes_to_human_readable_format " ${_free_space_bytes:? } " || :) )"
1291+ fi
12351292
12361293 if test -n " ${_error_text?} " ; then
12371294 ui_error " Failed to copy '${1?} ' to the device due to => $( printf ' %s\n' " ${_error_text?} " | head -n 1 || :) "
@@ -1770,7 +1827,7 @@ select_lib()
17701827
17711828extract_libs ()
17721829{
1773- local _lib_selected
1830+ local _lib_selected _curr_arch _backup_ifs
17741831
17751832 ui_msg " Extracting libs from ${1:? } /${2:? } .apk..."
17761833 create_dir " ${TMP_PATH:? } /libs"
@@ -1781,29 +1838,20 @@ extract_libs()
17811838
17821839 _lib_selected=' false'
17831840
1784- if test " ${ARCH_X64 :? } " = ' true ' && select_lib ' x86_64 ' ; then
1785- _lib_selected= ' true '
1786- fi
1787- if test " ${ARCH_ARM64 : ? } " = ' true ' && select_lib ' arm64-v8a ' ; then
1788- _lib_selected=' true'
1789- fi
1790- if test " ${ARCH_MIPS64 :? } " = ' true ' && select_lib ' mips64 ' ; then
1791- _lib_selected= ' true '
1792- fi
1841+ _backup_ifs= " ${IFS-} "
1842+ IFS= ' , '
1843+ for _curr_arch in ${ARCH_LIST?} ; do
1844+ if test -n " ${_curr_arch ?} " && select_lib " ${_curr_arch :? } " ; then
1845+ _lib_selected=' true'
1846+ break
1847+ fi
1848+ done
1849+ IFS= " ${_backup_ifs?} "
17931850
1794- if test " ${ARCH_X86:? } " = ' true' && select_lib ' x86' ; then
1795- _lib_selected=' true'
1796- fi
1797- if test " ${ARCH_ARM:? } " = ' true' && select_lib ' armeabi-v7a' ; then
1798- _lib_selected=' true'
1799- elif test " ${ARCH_LEGACY_ARM:? } " = ' true' && select_lib ' armeabi' ; then
1800- _lib_selected=' true'
1801- elif test " ${ARCH_ARM:? } " = ' true' && select_lib ' armeabi-v7a-hard' ; then # Use the deprecated Hard Float ABI only as fallback
1802- _lib_selected=' true'
1803- fi
18041851 # armeabi-v7a-hard is not a real ABI. No devices are built with this. The "hard float" variant only changes the function call ABI.
18051852 # More info: https://android.googlesource.com/platform/ndk/+/master/docs/HardFloatAbi.md
1806- if test " ${ARCH_MIPS:? } " = ' true' && select_lib ' mips' ; then
1853+ # Use the deprecated Hard Float ABI only as fallback
1854+ if test " ${_lib_selected:? } " = ' false' && test " ${ARCH_ARM:? } " = ' true' && select_lib ' armeabi-v7a-hard' ; then
18071855 _lib_selected=' true'
18081856 fi
18091857
@@ -1915,12 +1963,12 @@ setup_app()
19151963 move_rename_file " ${TMP_PATH:? } /origin/etc/default-permissions/default-permissions-${_filename:? } .xml" " ${TMP_PATH:? } /files/etc/default-permissions/default-permissions-${_output_name:? } .xml" || ui_error " Failed to setup the default permissions xml of '${_vanity_name?} '"
19161964 _installed_file_list=" ${_installed_file_list?} |etc/default-permissions/default-permissions-${_output_name:? } .xml"
19171965 fi
1918- if test " ${_url_handling:? } " ! = ' false' ; then
1966+ if test " ${_url_handling:? } " ! = ' false' && test " ${CURRENTLY_ROLLBACKING :- false} " ! = ' true ' ; then
19191967 add_line_in_file_after_string " ${TMP_PATH:? } /files/etc/sysconfig/google.xml" ' <!-- %CUSTOM_APP_LINKS-START% -->' " <app-link package=\" ${_internal_name:? } \" />" || ui_error " Failed to auto-enable URL handling for '${_vanity_name?} '"
19201968 fi
19211969 move_rename_file " ${TMP_PATH:? } /origin/${_dir:? } /${_filename:? } .apk" " ${TMP_PATH:? } /files/${_output_dir:? } /${_output_name:? } .apk" || ui_error " Failed to setup the app => '${_vanity_name?} '"
19221970
1923- if test " ${CURRENTLY_ROLLBACKING:- false} " ! = ' true' && test " ${_optional:? } " = ' true' && test " $( stat -c ' %s ' -- " ${TMP_PATH:? } /files/${_output_dir:? } /${_output_name:? } .apk" || printf ' 0' || true ) " -gt 300000 ; then
1971+ if test " ${CURRENTLY_ROLLBACKING:- false} " ! = ' true' && test " ${_optional:? } " = ' true' && test " $( get_size_of_file " ${TMP_PATH:? } /files/${_output_dir:? } /${_output_name:? } .apk" || printf ' 0' || : ) " -gt 102400 ; then
19241972 _installed_file_list=" ${_installed_file_list# |} "
19251973 printf ' %s\n' " ${_vanity_name:? } |${_output_dir:? } /${_output_name:? } .apk|${_installed_file_list?} " 1>> " ${TMP_PATH:? } /processed-${_dir:? } s.log" || ui_error " Failed to update processed-${_dir?} s.log"
19261974 fi
0 commit comments