Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local files with matching filenames #123

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goosebit/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

async def init():
await Tortoise.init(config=TORTOISE_CONF)
await Tortoise.generate_schemas()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be necessary. As written in the README.md : "Create or upgrade database: poetry run aerich upgrade"

My working assumption is, that DB manipulations are best left to the Dev / Ops person. Don't automate it within the app.



async def close():
Expand Down
20 changes: 5 additions & 15 deletions goosebit/updates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import shutil
from pathlib import Path
from urllib.parse import unquote, urlparse
Expand All @@ -10,6 +12,7 @@
from goosebit.db.models import Hardware, Software
from goosebit.updater.manager import UpdateManager

from ..settings import config
from . import swdesc


Expand Down Expand Up @@ -42,7 +45,8 @@ async def create_software_update(uri: str, temp_file: Path | None) -> Software:

# for local file: rename temp file to final name
if parsed_uri.scheme == "file":
path = _unique_path(parsed_uri)
filename = Path(url2pathname(unquote(parsed_uri.path))).name
path = config.artifacts_dir.joinpath(update_info["hash"], filename)
path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(temp_file, path)
uri = path.absolute().as_uri()
Expand Down Expand Up @@ -85,20 +89,6 @@ async def _is_software_colliding(update_info):
return is_colliding


def _unique_path(uri):
path = Path(url2pathname(unquote(uri.path)))
if not path.exists():
return path

counter = 1
new_path = path.with_name(f"{path.stem}-{counter}{path.suffix}")
while new_path.exists():
counter += 1
new_path = path.with_name(f"{path.stem}-{counter}{path.suffix}")

return new_path


async def generate_chunk(request: Request, updater: UpdateManager) -> list:
_, software = await updater.get_update()
if software is None:
Expand Down