provision: Fix buggy management of apt_dependencies_hash.

Apparently, we were incorrectly appending each new hash onto the end
of the file, basically resulting in every run of provision being
treated as a miss for this cache.

Fixing this saves about 4s (over 1/3) of the no-op provision time.
This commit is contained in:
Tim Abbott
2018-05-20 14:21:32 -07:00
parent 235002a549
commit 4f8e09d5af

View File

@@ -226,11 +226,10 @@ def main(options):
last_apt_dependencies_hash = None last_apt_dependencies_hash = None
apt_hash_file_path = os.path.join(UUID_VAR_PATH, "apt_dependencies_hash") apt_hash_file_path = os.path.join(UUID_VAR_PATH, "apt_dependencies_hash")
try: try:
hash_file = open(apt_hash_file_path, 'r+') hash_file = open(apt_hash_file_path, 'r')
last_apt_dependencies_hash = hash_file.read() last_apt_dependencies_hash = hash_file.read()
except IOError: except IOError:
run(['touch', apt_hash_file_path]) run(['touch', apt_hash_file_path])
hash_file = open(apt_hash_file_path, 'r+')
if (new_apt_dependencies_hash != last_apt_dependencies_hash): if (new_apt_dependencies_hash != last_apt_dependencies_hash):
try: try:
@@ -245,6 +244,7 @@ def main(options):
# recover automatically. # recover automatically.
run(['sudo', 'apt-get', 'update']) run(['sudo', 'apt-get', 'update'])
install_apt_deps() install_apt_deps()
hash_file = open(apt_hash_file_path, 'w')
hash_file.write(new_apt_dependencies_hash) hash_file.write(new_apt_dependencies_hash)
else: else:
print("No changes to apt dependencies, so skipping apt operations.") print("No changes to apt dependencies, so skipping apt operations.")