Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gitfs "__env__" and improve cache cleaning (bsc#1193948) #608

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/65002.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix __env__ and improve cache cleaning see more info at pull #65017.
1 change: 1 addition & 0 deletions changelog/65086.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Moved gitfs locks to salt working dir to avoid lock wipes
32 changes: 32 additions & 0 deletions salt/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os
import re
import shutil
import time

import salt.config
Expand All @@ -15,6 +16,8 @@
import salt.utils.dictupdate
import salt.utils.files
import salt.utils.msgpack
import salt.utils.path
import salt.version
from salt.utils.zeromq import zmq

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -345,3 +348,32 @@ def context_cache_wrap(*args, **kwargs):
return func(*args, **kwargs)

return context_cache_wrap


def verify_cache_version(cache_path):
"""
Check that the cached version matches the Salt version.
If the cached version does not match the Salt version, wipe the cache.

:return: ``True`` if cache version matches, otherwise ``False``
"""
if not os.path.isdir(cache_path):
os.makedirs(cache_path)
with salt.utils.files.fopen(
salt.utils.path.join(cache_path, "cache_version"), "a+"
) as file:
file.seek(0)
data = "\n".join(file.readlines())
if data != salt.version.__version__:
log.warning(f"Cache version mismatch clearing: {repr(cache_path)}")
file.truncate(0)
file.write(salt.version.__version__)
for item in os.listdir(cache_path):
if item != "cache_version":
item_path = salt.utils.path.join(cache_path, item)
if os.path.isfile(item_path):
os.remove(item_path)
else:
shutil.rmtree(item_path)
return False
return True
Loading
Loading