diff --git a/lib/tool_shed/managers/tools.py b/lib/tool_shed/managers/tools.py index f569935d51ee..3c627fb753ed 100644 --- a/lib/tool_shed/managers/tools.py +++ b/lib/tool_shed/managers/tools.py @@ -149,7 +149,7 @@ def _shed_tool_source_for( cloned_ok, error_message = clone_repository(repository_clone_url, work_dir, str(ctx.rev())) if error_message: raise InternalServerError("Failed to materialize target repository revision") - repo_files_dir = repository_metadata.repository.repo_path(trans.app) + repo_files_dir = repository_metadata.repository.hg_repository_path(trans.app.config.file_path) if not repo_files_dir: raise InconsistentApplicationState(f"Failed to resolve repository path from hgweb_config_manager for [{trs_tool_id}], inconsistent repository state or application configuration") repo_rel_tool_path = relpath(tool_config, repo_files_dir) diff --git a/lib/tool_shed/util/repository_util.py b/lib/tool_shed/util/repository_util.py index 9c9545c2e7f1..32829078f661 100644 --- a/lib/tool_shed/util/repository_util.py +++ b/lib/tool_shed/util/repository_util.py @@ -231,12 +231,7 @@ def create_repository( session = sa_session() with transaction(session): session.commit() - dir = os.path.join(app.config.file_path, *util.directory_hash_id(repository.id)) - # Define repo name inside hashed directory. - final_repository_path = os.path.join(dir, "repo_%d" % repository.id) - # Create final repository directory. - if not os.path.exists(final_repository_path): - os.makedirs(final_repository_path) + final_repository_path = repository.ensure_hg_repository_path(app.config.file_path) os.rename(repository_path, final_repository_path) app.hgweb_config_manager.add_entry(lhs, final_repository_path) # Update the repository registry. diff --git a/lib/tool_shed/webapp/model/__init__.py b/lib/tool_shed/webapp/model/__init__.py index a31ab4861f4a..a73a6e6ae2bc 100644 --- a/lib/tool_shed/webapp/model/__init__.py +++ b/lib/tool_shed/webapp/model/__init__.py @@ -524,6 +524,19 @@ def repo_path(self, app=None): os.path.join(hgweb_config_manager.hgweb_repo_prefix, self.user.username, self.name) ) + def hg_repository_path(repositories_directory: str) -> str: + if self.id is None: + raise Exception("Attempting to call hg_repository_path before id has been set on repository object") + dir = os.path.join(repositories_directory, *util.directory_hash_id(repository.id)) + final_repository_path = os.path.join(dir, "repo_%d" % repository.id) + return final_repository_path + + def ensure_hg_repository_path(repositories_directory: str) -> str: + final_repository_path = self.hg_repository_path(repositories_directory) + if not os.path.exists(final_repository_path): + os.makedirs(final_repository_path) + return final_repository_path + def revision(self): repo = self.hg_repo tip_ctx = repo[repo.changelog.tip()]