Skip to content

refactor: extract DownloadService file I/O into adapter #243

@danielcopper

Description

@danielcopper

Problem

DownloadService (py_modules/services/downloads.py) performs direct file I/O operations that belong in the adapter layer:

  • ZIP extraction (zipfile.ZipFile, extractall())
  • File cleanup (os.remove(), shutil.rmtree())
  • Disk space checks (shutil.disk_usage())
  • M3U file generation (open(), write)
  • File replacement (os.replace(), os.makedirs())
  • Temp file handling

This violates the architecture rule that services should not do I/O directly — I/O belongs in the adapter layer.

Proposed solution

Create a RomFileAdapter (or similar) that handles local ROM file operations:

  • extract_zip(archive_path, dest_dir) -> list[str]
  • disk_free(path) -> int
  • write_m3u(path, entries: list[str])
  • remove_file(path) / remove_dir(path)
  • replace_file(src, dest)

Define a Protocol in services/protocols.py. Inject via bootstrap.py.

Priority

Low — architecture hygiene. No functional bugs.

Discovered during

Architecture validation audit during #197 Block 1 (slot deletion).

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions