[Kimchi-devel] [PATCH] fix lock for apt package manager
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Mar 26 06:28:18 UTC 2014
Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>
On 03/26/2014 02:44 AM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Tested with:
> 1.Model test update/add/remove repositories.
> 2.UI test.
> Global lock is acquired for kimchi to update/add/remove
> and list package informations.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
> src/kimchi/repositories.py | 50 ++++++++++++++++++++++++++++------------------
> 1 file changed, 31 insertions(+), 19 deletions(-)
>
> diff --git a/src/kimchi/repositories.py b/src/kimchi/repositories.py
> index 1c74f04..98fc3de 100644
> --- a/src/kimchi/repositories.py
> +++ b/src/kimchi/repositories.py
> @@ -310,6 +310,7 @@ class AptRepo(object):
> getattr(__import__('apt_pkg'), 'init_config')()
> getattr(__import__('apt_pkg'), 'init_system')()
> config = getattr(__import__('apt_pkg'), 'config')
> + self.pkg_lock = getattr(__import__('apt_pkg'), 'SystemLock')
> module = __import__('aptsources.sourceslist', globals(), locals(),
> ['SourcesList'], -1)
>
> @@ -322,6 +323,16 @@ class AptRepo(object):
> fd.write("# This file is managed by Kimchi and it must not "
> "be modified manually\n")
>
> + def _get_repos(self):
> + try:
> + with self.pkg_lock():
> + repos = self._sourceslist()
> + repos.refresh()
> + except Exception, e:
> + raise OperationFailed('KCHREPOS0025E', {'err': e.message})
> +
> + return repos
> +
> def _get_repo_id(self, repo):
> data = urlparse.urlparse(repo.uri)
> name = data.hostname or data.path
> @@ -329,8 +340,7 @@ class AptRepo(object):
>
> def _get_source_entry(self, repo_id):
> kimchiLock.acquire()
> - repos = self._sourceslist()
> - repos.refresh()
> + repos = self._get_repos()
> kimchiLock.release()
>
> for r in repos:
> @@ -354,8 +364,7 @@ class AptRepo(object):
> _get_repo_id()
> """
> kimchiLock.acquire()
> - repos = self._sourceslist()
> - repos.refresh()
> + repos = self._get_repos()
> kimchiLock.release()
>
> res = []
> @@ -400,12 +409,15 @@ class AptRepo(object):
> dist = config['dist']
> comps = config.get('comps', [])
>
> - kimchiLock.acquire()
> - repos = self._sourceslist()
> - repos.refresh()
> - source_entry = repos.add('deb', uri, dist, comps, file=self.filename)
> - repos.save()
> - kimchiLock.release()
> + with kimchiLock:
> + try:
> + repos = self._get_repos()
> + source_entry = repos.add('deb', uri, dist, comps, file=self.filename)
> + with self.pkg_lock():
> + repos.save()
> + except Exception as e:
> + raise OperationFailed("KCHREPOS0026E", {'err': e.message})
> +
>
> return self._get_repo_id(source_entry)
>
> @@ -430,11 +442,11 @@ class AptRepo(object):
>
> kimchiLock.acquire()
> try:
> - repos = self._sourceslist()
> - repos.refresh()
> - repos.remove(r)
> - repos.add(line, r.uri, r.dist, r.comps, file=self.filename)
> - repos.save()
> + repos = self._get_repos()
> + with self.pkg_lock():
> + repos.remove(r)
> + repos.add(line, r.uri, r.dist, r.comps, file=self.filename)
> + repos.save()
> except:
> if enable:
> raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})
> @@ -476,10 +488,10 @@ class AptRepo(object):
>
> kimchiLock.acquire()
> try:
> - repos = self._sourceslist()
> - repos.refresh()
> - repos.remove(r)
> - repos.save()
> + repos = self._get_repos()
> + with self.pkg_lock():
> + repos.remove(r)
> + repos.save()
> except:
> raise OperationFailed("KCHREPOS0017E", {'repo_id': repo_id})
> finally:
More information about the Kimchi-devel
mailing list