Fix usage of file/folder names without suffix in Downloader (#5938)

This commit is contained in:
Jakub Kuczys 2022-12-27 00:39:17 +01:00 committed by GitHub
parent f02491a092
commit e88884edb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 9 deletions

View File

@ -529,7 +529,8 @@ class Downloader(commands.Cog):
- `[p]repo add 26-Cogs https://github.com/Twentysix26/x26-Cogs` - `[p]repo add 26-Cogs https://github.com/Twentysix26/x26-Cogs`
- `[p]repo add Laggrons-Dumb-Cogs https://github.com/retke/Laggrons-Dumb-Cogs v3` - `[p]repo add Laggrons-Dumb-Cogs https://github.com/retke/Laggrons-Dumb-Cogs v3`
Repo names can only contain characters A-z, numbers, underscores, and hyphens. Repo names can only contain characters A-z, numbers, underscores, hyphens, and dots (but they cannot start or end with a dot).
The branch will be the default branch if not specified. The branch will be the default branch if not specified.
**Arguments** **Arguments**

View File

@ -84,7 +84,7 @@ class Installable(RepoJSONMixin):
self._location = location self._location = location
self.repo = repo self.repo = repo
self.repo_name = self._location.parent.stem self.repo_name = self._location.parent.name
self.commit = commit self.commit = commit
self.end_user_data_statement: str self.end_user_data_statement: str
@ -129,7 +129,7 @@ class Installable(RepoJSONMixin):
# noinspection PyBroadException # noinspection PyBroadException
try: try:
copy_func(src=str(self._location), dst=str(target_dir / self._location.stem)) copy_func(src=str(self._location), dst=str(target_dir / self._location.name))
except: # noqa: E722 except: # noqa: E722
log.exception("Error occurred when copying path: %s", self._location) log.exception("Error occurred when copying path: %s", self._location)
return False return False

View File

@ -998,7 +998,7 @@ class Repo(RepoJSONMixin):
@classmethod @classmethod
async def from_folder(cls, folder: Path, branch: str = "") -> Repo: async def from_folder(cls, folder: Path, branch: str = "") -> Repo:
repo = cls(name=folder.stem, url="", branch=branch, commit="", folder_path=folder) repo = cls(name=folder.name, url="", branch=branch, commit="", folder_path=folder)
repo.url = await repo.current_url() repo.url = await repo.current_url()
if branch == "": if branch == "":
repo.branch = await repo.current_branch() repo.branch = await repo.current_branch()
@ -1214,14 +1214,14 @@ class RepoManager:
if not folder.is_dir(): if not folder.is_dir():
continue continue
try: try:
branch = await self.config.repos.get_raw(folder.stem, default="") branch = await self.config.repos.get_raw(folder.name, default="")
ret[folder.stem] = await Repo.from_folder(folder, branch) ret[folder.name] = await Repo.from_folder(folder, branch)
if branch == "": if branch == "":
await self.config.repos.set_raw(folder.stem, value=ret[folder.stem].branch) await self.config.repos.set_raw(folder.name, value=ret[folder.name].branch)
except errors.NoRemoteURL: except errors.NoRemoteURL:
log.warning("A remote URL does not exist for repo %s", folder.stem) log.warning("A remote URL does not exist for repo %s", folder.name)
except errors.DownloaderException as err: except errors.DownloaderException as err:
log.error("Ignoring repo %s due to error.", folder.stem, exc_info=err) log.error("Ignoring repo %s due to error.", folder.name, exc_info=err)
# Downloader should NOT remove the repo on generic errors like this one. # Downloader should NOT remove the repo on generic errors like this one.
# We were removing whole repo folder here in the past, # We were removing whole repo folder here in the past,
# but it's quite destructive for such a generic error. # but it's quite destructive for such a generic error.