allow creation of repos from a specified event
This commit is contained in:
parent
fbcc9def02
commit
d412fc54d7
3 changed files with 55 additions and 18 deletions
27
util/kojira
27
util/kojira
|
|
@ -119,8 +119,10 @@ class ManagedRepo(object):
|
|||
|
||||
def tryDelete(self):
|
||||
"""Remove the repo from disk, if possible"""
|
||||
#we check just the event age first since it is faster
|
||||
age = time.time() - self.event_ts
|
||||
if age < options.deleted_repo_lifetime:
|
||||
#XXX should really be called expired_repo_lifetime
|
||||
return False
|
||||
self.logger.debug("Attempting to delete repo %s.." % self.repo_id)
|
||||
if self.state != koji.REPO_EXPIRED:
|
||||
|
|
@ -138,6 +140,16 @@ class ManagedRepo(object):
|
|||
return False
|
||||
tag_name = tag_info['name']
|
||||
path = pathinfo.repo(self.repo_id, tag_name)
|
||||
#also check dir age. We do this because a repo can be created from an older event
|
||||
#and should not be removed based solely on that event's timestamp.
|
||||
try:
|
||||
age = time.time() - os.stat(path).st_mtime
|
||||
except OSError:
|
||||
self.logger.error("Can't stat repo directory: %s" % path)
|
||||
return True
|
||||
if age < options.deleted_repo_lifetime:
|
||||
#XXX should really be called expired_repo_lifetime
|
||||
return False
|
||||
safe_rmtree(path, strict=False)
|
||||
return True
|
||||
|
||||
|
|
@ -227,13 +239,14 @@ class RepoManager(object):
|
|||
if self.repos.has_key(repo_id):
|
||||
#we're already managing it, no need to deal with it here
|
||||
continue
|
||||
try:
|
||||
dir_ts = os.stat(repodir).st_mtime
|
||||
except OSError:
|
||||
#just in case something deletes the repo out from under us
|
||||
continue
|
||||
rinfo = session.repoInfo(repo_id)
|
||||
if rinfo is None:
|
||||
try:
|
||||
age = time.time() - os.stat(repodir).st_mtime
|
||||
except OSError:
|
||||
#just in case something deletes the repo out from under us
|
||||
continue
|
||||
age = time.time() - dir_ts
|
||||
if age > 36000:
|
||||
if not options.ignore_stray_repos:
|
||||
self.logger.warn("Unexpected directory (no such repo): %s" % repodir)
|
||||
|
|
@ -242,8 +255,9 @@ class RepoManager(object):
|
|||
self.logger.warn("Tag name mismatch: %s" % repodir)
|
||||
continue
|
||||
if rinfo['state'] in (koji.REPO_DELETED, koji.REPO_PROBLEM):
|
||||
age = time.time() - rinfo['create_ts']
|
||||
age = time.time() - max(rinfo['create_ts'], dir_ts)
|
||||
if age > options.deleted_repo_lifetime:
|
||||
#XXX should really be called expired_repo_lifetime
|
||||
count += 1
|
||||
logger.info("Removing stray repo (state=%s): %s" % (koji.REPO_STATES[rinfo['state']], repodir))
|
||||
safe_rmtree(repodir, strict=False)
|
||||
|
|
@ -432,6 +446,7 @@ def get_options():
|
|||
'delete_batch_size': 3,
|
||||
'max_repo_tasks' : 10,
|
||||
'deleted_repo_lifetime': 7*24*3600,
|
||||
#XXX should really be called expired_repo_lifetime
|
||||
'cert': '/etc/kojira/client.crt',
|
||||
'ca': '/etc/kojira/clientca.crt',
|
||||
'serverca': '/etc/kojira/serverca.crt'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue