soachishti / moss.py

Python client for Moss: A System for Detecting Software Similarity
MIT License
381 stars 75 forks source link

Exception on empty file #21

Closed niklas88 closed 5 years ago

niklas88 commented 5 years ago

When there is an empty file in the directory being added e.g. an empty __init__.py. ` mosspy crashes with the following error:

 File "similar_code_detector_main.py", line 160, in <module>
    moss_ignorelimit=args.moss_ignorelimit
  File "projects/similar-code-detector/similar_code_detector.py", line 53, in detect_similar_code
    m.addFile(f)
  File "projects/similar-code-detector/venv/lib/python3.7/site-packages/mosspy/moss.py", line 82, in addFile
    raise Exception("addFile({}) => File Not Found".format(file_path))
Exception: addFile(/redacted/path/__init__.py) => File Not Found

Changing the getsize() check in moss.py:79 to >= 0 lets everything run through fine.

soachishti commented 5 years ago

Hi, We had a pull-request #13 where moss don't respond when file-size is zero. I will confirm this again and update here accordingly.

niklas88 commented 5 years ago

I installed via pip, maybe version was just too old?

soachishti commented 5 years ago

I am seeing same issue as indicated in #13, Moss starts failing or sometime gets hangs on empty file. However, I have updated error message to "File not found or is empty." in commit d62c5ed.

Silently ignoring such error can cause script to send zero files (worst case). It would be better that such files are handled beforehand.

Closing this issue.