diff options
author | Marius Mauch <genone@gentoo.org> | 2008-04-13 07:49:38 +0000 |
---|---|---|
committer | Marius Mauch <genone@gentoo.org> | 2008-04-13 07:49:38 +0000 |
commit | 8707f7fd523b65efb7b6709909e3f27f4905fe00 (patch) | |
tree | 7d45c944e98a2391df0abc2b9b513c9c91843d22 | |
parent | fa0cecfa3a21fd4f6e9613daf2f48500d62ab518 (diff) | |
download | portage-8707f7fd523b65efb7b6709909e3f27f4905fe00.tar.gz portage-8707f7fd523b65efb7b6709909e3f27f4905fe00.tar.bz2 portage-8707f7fd523b65efb7b6709909e3f27f4905fe00.zip |
store sets in a different physical location than normal packages for 'world' (makes ferringb a bit happier, and might have other advantages in the future)
svn path=/main/trunk/; revision=9866
-rw-r--r-- | pym/portage/sets/files.py | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index 95b298eae..3abb3f88b 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -156,18 +156,75 @@ class ConfigFileSet(PackageSet): return rValue multiBuilder = classmethod(multiBuilder) -class WorldSet(StaticFileSet): +class WorldSet(EditablePackageSet): description = "Set of packages that were directly installed by the user" def __init__(self, root): - super(WorldSet, self).__init__(os.path.join(os.sep, root, PRIVATE_PATH.lstrip(os.sep), "world")) + super(WorldSet, self).__init__() + # most attributes exist twice as atoms and non-atoms are stored in + # separate files self._lock = None - + self._filename = os.path.join(os.sep, root, PRIVATE_PATH.lstrip(os.sep), "world") + self.loader = ItemFileLoader(self._filename, self._validate) + self._mtime = None + + self._filename2 = os.path.join(os.sep, root, PRIVATE_PATH.lstrip(os.sep), "world_sets") + self.loader2 = ItemFileLoader(self._filename2, self._validate2) + self._mtime2 = None + def _validate(self, atom): - if atom.startswith(SETPREFIX): - return True return ValidAtomValidator(atom) + def _validate2(self, setname): + return setname.startswith(SETPREFIX) + + def write(self): + write_atomic(self._filename, "\n".join(sorted(self._atoms))+"\n") + write_atomic(self._filename2, "\n".join(sorted(self._nonatoms))+"\n") + + def load(self): + atoms = [] + nonatoms = [] + # load atoms and non-atoms from different files so the worldfile is + # backwards-compatible with older versions and other PMs, even though + # it's supposed to be private state data :/ + try: + mtime = os.stat(self._filename).st_mtime + except (OSError, IOError): + mtime = None + if (not self._loaded or self._mtime != mtime): + try: + data, errors = self.loader.load() + for fname in errors: + for e in errors[fname]: + self.errors.append(fname+": "+e) + except EnvironmentError, e: + if e.errno != errno.ENOENT: + raise + del e + data = {} + atoms = data.keys() + self._mtime = mtime + try: + mtime = os.stat(self._filename2).st_mtime + except (OSError, IOError): + mtime = None + if (not self._loaded or self._mtime2 != mtime): + try: + data, errors = self.loader2.load() + for fname in errors: + for e in errors[fname]: + self.errors.append(fname+": "+e) + except EnvironmentError, e: + if e.errno != errno.ENOENT: + raise + del e + data = {} + nonatoms = data.keys() + self._mtime2 = mtime + if self._atoms != atoms or self._nonatoms != nonatoms: + self._setAtoms(atoms+nonatoms) + def _ensure_dirs(self): ensure_dirs(os.path.dirname(self._filename), gid=portage_gid, mode=02750, mask=02) |