diff options
| author | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-05-24 16:17:18 +0100 |
|---|---|---|
| committer | Jim MacArthur <jim@mode7.co.uk> | 2018-05-28 11:31:59 +0100 |
| commit | e31751a42aa9fc62db0b4ca18fe723205877051e (patch) | |
| tree | f2a59094d130ae9d88f42a50e41a783ed3c71745 | |
| parent | 4f358829b5e89db39e633723fae01bba7e1827a2 (diff) | |
| download | buildstream-e31751a42aa9fc62db0b4ca18fe723205877051e.tar.gz | |
Call _populate_index only in the constructor
| -rw-r--r-- | buildstream/storage/_casbaseddirectory.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/buildstream/storage/_casbaseddirectory.py b/buildstream/storage/_casbaseddirectory.py index f4b6673b7..aed1542bf 100644 --- a/buildstream/storage/_casbaseddirectory.py +++ b/buildstream/storage/_casbaseddirectory.py @@ -73,6 +73,7 @@ class CasBasedDirectory(Directory): self.index = OrderedDict() self.parent = parent self._directory_read = False + self._populate_index() # Functions taken from googlecas.py @@ -119,16 +120,15 @@ class CasBasedDirectory(Directory): return digest # End of functions from googlecas.py - + def _populate_index(self) -> None: if self._directory_read: + raise VirtualDirectoryError("_populate_index called twice") return # Replace with tree read for entry in self.directory.directories: - print("Creating new CasBasedDirectory '{}' during index population".format(entry.name)) - if entry.name not in self.index: - self.index[entry.name] = CasBasedDirectory(self.context, ref=entry.digest,parent=self,name=entry.name) + self.index[entry.name] = CasBasedDirectory(self.context, ref=entry.digest,parent=self,name=entry.name) for entry in self.directory.files: self.index[entry.name] = _FileObject(self, entry) @@ -156,6 +156,7 @@ class CasBasedDirectory(Directory): filenode = self.directory.files.add() filenode.name = filename self._hash_object(digest=filenode.digest, path=os.path.join(basename, filename)) + self.index[filename] = _FileObject(basename, filename) self.recalculate_hash() print(" Added file {} which now has hash {}".format(filename, filenode.digest.hash[0:7])) @@ -183,7 +184,6 @@ class CasBasedDirectory(Directory): return self.descend(subdirectory_spec[1:], create) print("Descending from {} into '{}'".format(self, subdirectory_spec)) - self._populate_index() if subdirectory_spec[0] in self.index: entry = self.index[subdirectory_spec[0]] if isinstance(entry, CasBasedDirectory): @@ -217,7 +217,6 @@ class CasBasedDirectory(Directory): if os.path.isfile(pathname): print("Attempting to import FILE {} from {}".format(name, source_directory)) self._add_new_file(source_directory, name) - self._populate_index() def save(self, name): """Saves this directory into the content cache.""" @@ -320,7 +319,6 @@ class CasBasedDirectory(Directory): def is_empty(self) -> bool: """ Return true if this directory has no files, subdirectories or links in it. """ - self._populate_index() return len(self.index) == 0 def mark_unmodified(self) -> None: |
