From 9518e1a98e642175a2de74a8d6e54126b9399210 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 25 Jan 2010 07:54:37 -0500 Subject: Rework fix for #bea/8fc# : be crashes on outdated id-cache Now we re-run CachedPathID.init in an 'append' mode, rather than starting over from scratch. This avoids problems like ====================================================================== ERROR: Should not be able to add children to non-directories. ---------------------------------------------------------------------- Traceback (most recent call last): File ".../be.wtk/libbe/storage/base.py", line 680, in test_add_invalid_directory self.s.add('child', 'parent', directory=False) File ".../be.wtk/libbe/storage/base.py", line 248, in add self._add(id, *args, **kwargs) File ".../be.wtk/libbe/storage/vcs/base.py", line 737, in _add path = self._cached_path_id.add_id(id, parent) File ".../be.wtk/libbe/storage/vcs/base.py", line 267, in add_id parent_path = self.path(parent, relpath=True) File ".../be.wtk/libbe/storage/vcs/base.py", line 246, in path raise InvalidID(uuid) InvalidID: parent in revision None and similar. --- libbe/storage/vcs/base.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'libbe/storage') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 2269424..8335cfa 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -182,13 +182,16 @@ class CachedPathID (object): self._cache_path = os.path.join( self._root, self._spacer_dirs[0], 'id-cache') - def init(self, verbose=True): + def init(self, verbose=True, cache=None): """ Create cache file for an existing .be directory. File if multiple lines of the form: UUID\tPATH """ - self._cache = {} + if cache == None: + self._cache = {} + else: + self._cache = cache spaced_root = os.path.join(self._root, self._spacer_dirs[0]) for dirpath, dirnames, filenames in os.walk(spaced_root): if dirpath == spaced_root: @@ -202,8 +205,10 @@ class CachedPathID (object): self._cache[id] = relpath except InvalidPath: pass - self._changed = True - self.disconnect() + if self._cache != cache: + self._changed = True + if cache == None: + self.disconnect() def destroy(self): if os.path.exists(self._cache_path): @@ -239,9 +244,7 @@ class CachedPathID (object): else: extra = fields[1:] if uuid not in self._cache: - self.disconnect() - self.init(verbose=False) - self.connect() + self.init(verbose=False, cache=self._cache) if uuid not in self._cache: raise InvalidID(uuid) if relpath == True: -- cgit