Skip to content
Snippets Groups Projects
Commit 0cabb309 authored by Jonathan Maw's avatar Jonathan Maw
Browse files

WIP: Fix cache miss when calling WorkspaceProjectCache.get() on different...

WIP: Fix cache miss when calling WorkspaceProjectCache.get() on different directories in the same workspace
parent 832ce803
No related branches found
No related tags found
Loading
Pipeline #37586624 failed
......@@ -165,24 +165,29 @@ class WorkspaceProjectCache():
# get()
#
# Returns a WorkspaceProject for a given directory, loading one from disk if present
# and caching it.
# Returns a WorkspaceProject for a given directory, retrieving from the cache if
# present, and searching the filesystem for the file and loading it if not.
#
# Args:
# directory (str): The directory to search for a WorkspaceProject.
#
# Returns:
# (WorkspaceProject): The WorkspaceProject that was found for that directory.
# or (NoneType): None, if no WorkspaceProject can be found.
#
def get(self, directory):
# NOTE: Later, this will load any WorkspaceProject found from directory
try:
workspace_project = self._projects[directory]
except KeyError:
workspace_project = WorkspaceProject.load(directory)
if not workspace_project:
workspace_project = WorkspaceProject(directory)
self._projects[directory] = workspace_project
found_dir = WorkspaceProject.search_for_dir(directory)
if found_dir:
try:
workspace_project = self._projects[found_dir]
except KeyError:
workspace_project = WorkspaceProject.load(found_dir)
self._projects[found_dir] = workspace_project
else:
workspace_project = None
return workspace_project
......@@ -201,6 +206,9 @@ class WorkspaceProjectCache():
#
def add(self, directory, project_path='', element_name=''):
workspace_project = self.get(directory)
if not workspace_project:
workspace_project = WorkspaceProject(directory)
self._projects[directory] = workspace_project
if project_path:
workspace_project._add_project(project_path, element_name)
return workspace_project
......@@ -223,6 +231,9 @@ class WorkspaceProjectCache():
# NOTE: project_path and element_name will only be used when I implement
# multiple owners of a workspace
workspace_project = self.get(directory)
if not workspace_project:
raise LoadError(LoadErrorReason.MISSING_FILE,
"Failed to find a {} file to remove".format(WORKSPACE_PROJECT_FILE))
path = workspace_project._get_filename()
try:
os.unlink(path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment