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

ZeroDivisionError when hashing small files #53

Closed
youk opened this issue Sep 12, 2023 · 3 comments
Closed

ZeroDivisionError when hashing small files #53

youk opened this issue Sep 12, 2023 · 3 comments

Comments

@youk
Copy link

youk commented Sep 12, 2023

I am getting ZeroDivisionError when checking hash of a small file (~700KB) on Windows. I suppose hashing_secs = time.time() - hashing_secs yields zero in my case.

lstor -c 'directory\datafile' 'directory\metafile':

100.0% [============================================================================>] 707.3 KiB/707 ETA [00:00]
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Program Files\Python311\Scripts\lstor.exe\__main__.py", line 7, in <module>
  File "C:\Program Files\Python311\Lib\site-packages\pyrosimple\scripts\lstor.py", line 179, in run
    MetafileLister().run()
  File "C:\Program Files\Python311\Lib\site-packages\pyrosimple\scripts\base.py", line 178, in run
    self.mainloop()
  File "C:\Program Files\Python311\Lib\site-packages\pyrosimple\scripts\lstor.py", line 106, in mainloop
    data_correct = torrent.hash_check(
                   ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pyrosimple\util\metafile.py", line 668, in hash_check
    datameta, _ = self._make_info(
                  ^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pyrosimple\util\metafile.py", line 366, in _make_info
    fmt.human_size(totalhashed / hashing_secs).strip(),
                   ~~~~~~~~~~~~^~~~~~~~~~~~~~
ZeroDivisionError: float division by zero

Weirdly enough, the error is gone when double backslash is used in pathnames. My only guess is that path handling takes more time in this case.

Python 3.11.5
pyrosimple 2.11
PowerShell 7.3.6

@youk youk changed the title Path handling on Windows is inconsistent in lstor ZeroDivisionError when hashing small files Sep 12, 2023
@youk
Copy link
Author

youk commented Sep 12, 2023

A general note: having expressions calculated for debug logging when debug is not enabled seems suboptimal.

@kannibalox
Copy link
Owner

I don't have a good way to reproduce this, but the fix should be straightforward enough.

A general note: having expressions calculated for debug logging when debug is not enabled seems suboptimal.

I agree in principal, and I've avoided it in other places, but it would require an unnecessarily complex setup in order to avoid a little math and string formatting in this case.

@youk
Copy link
Author

youk commented Sep 12, 2023

The fix works. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants