[entropy.client] complete implementation of older entropy downloaded packages cleanup

This commit is contained in:
Fabio Erculiani
2010-07-20 18:24:06 +02:00
parent 899e514659
commit 3ab1d8db4b
3 changed files with 92 additions and 87 deletions

View File

@@ -244,98 +244,23 @@ class UpdatesDaemon(dbus.service.Object):
def cleanup_entropy_cache(self):
with self.__is_working_mutex:
entropy = Entropy()
acquired = self.__acquire_entropy_locks(entropy)
if not acquired:
entropy.shutdown()
return True # respawn later
entropy = None
try:
sys_set = SysSet()
sys_set_plg_id = \
etpConst['system_settings_plugins_ids']['client_plugin']
client_settings = sys_set[sys_set_plg_id]
misc_settings = client_settings['misc']
autoprune_days = misc_settings.get('autoprune_days', None)
if autoprune_days is None:
# sorry, feature disabled or not available
# (upgrade entropy?)
return False
def filter_expired_pkg(pkg_path):
pkg_path = os.path.abspath(pkg_path)
# security check
if not pkg_path.startswith(etpConst['entropyworkdir']):
return False
if not pkg_path.endswith(etpConst['packagesext']):
return False
if not os.path.isfile(pkg_path):
return False
if not os.access(pkg_path, os.R_OK | os.W_OK):
return False
try:
mtime = os.path.getmtime(pkg_path)
except (OSError, IOError):
return False
if (mtime + (autoprune_days*24*3600)) > time.time():
return False
return True
# only check against available repositories
# skip disabled and corrupted
for repo_id in sys_set['repositories']['available']:
try:
repo_db = entropy.open_repository(repo_id)
except RepositoryError as err:
write_output(
"cleanup_entropy_cache: open_repository() error: %s" % (err,))
continue
except Exception as err:
write_output(
"cleanup_entropy_cache: open_repository() general error: %s" % (err,))
continue
repo_pkgs = set(repo_db.listAllDownloads(do_sort = False,
full_path = True))
repo_pkgs = [os.path.join(etpConst['entropyworkdir'], x) \
for x in repo_pkgs]
repo_pkgs = sorted(filter(filter_expired_pkg, repo_pkgs))
if not repo_pkgs:
if DAEMON_DEBUG:
write_output(
"cleanup_entropy_cache: removing from %s: nothing" % (
repo_id,))
continue
if DAEMON_DEBUG:
write_output(
"cleanup_entropy_cache: removing from %s: %s" % (
repo_id, ', '.join(repo_pkgs),))
for repo_pkg in repo_pkgs:
try:
os.remove(repo_pkg)
except OSError:
pass
try:
os.remove(repo_pkg + etpConst['packagesmd5fileext'])
except OSError:
pass
try:
os.remove(repo_pkg + \
etpConst['packagemtimefileext'])
except (OSError, KeyError,):
# KeyError is for backward compatibility
continue
entropy = Entropy()
acquired = self.__acquire_entropy_locks(entropy)
if not acquired:
return True # respawn later
if hasattr(entropy, 'clean_downloaded_packages'):
entropy.clean_downloaded_packages()
return False
finally:
self.__release_entropy_locks(entropy)
entropy.shutdown()
if entropy is not None:
self.__release_entropy_locks(entropy)
entropy.shutdown()
def check_system_changes(self):
if self.__trigger_oncall_updater: