handle_user_provided_file leaves an empty temp file

Open Beginner friendly
#414 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
tooling

Research direction

Start from the definition of handle_user_provided_file() in python-scraperlib and trace the nocopy=True early return and the local-path existence check that run before the temporary file is created. Move the NamedTemporaryFile(delete=False) creation into only the download and copy branches. Add tests asserting in_dir stays empty for the nocopy local-path case and for the missing local path, and confirm those tests fail before the change and pass after it.

Written by the indexing model from the issue text.

Description

When dest is not given, handle_user_provided_file() creates a NamedTemporaryFile(delete=False) before it knows whether it needs one. Two paths never use it, so an empty file is left behind:

  • nocopy=True with a local path returns source, and the temp file stays in in_dir (or the system temp directory).
  • A local path that does not exist raises OSError, and the temp file stays too.

nautilus (collection file) and kolibri2zim (custom about page and CSS, with in_dir=self.build_dir) call it with nocopy=True, so each of those runs given a local path leaves an empty tmp* file.

Proposed fix: create the temporary dest only in the download and copy branches, after the nocopy return and the existence check, and add tests that in_dir stays empty in both cases.

Dominant language
Python
Stars
33
Forks
34
Avg merge
1d 8h
Merged PRs (30d)
24

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openzim/python-scraperlib

All issues in openzim/python-scraperlib

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.