alfem/telegram-download-daemon

Problem downloading files with same filename

Closed this issue · 2 comments

Hi,

I just realize that there maybe a bug when downloading more than one files with the same filename. Here's what I observed:

I'm running the latest code with docker-compose. Everything works as expected when there's a single task (Let's call it file1). Then if I send another file with the same filename (file2), the tdd file regenerates and grows from 0KB, while the progress of file1 in telegram channel keeps going on. The downloading of file1 finishes when the size of tdd reaches that of file1. However, the obtained file1 is broken. I did not wait for the finish of file2, but I think file2 will be broken, too.

Another problem is that if I send file2 after file1 finshed, file2 will overwrite file1 when finishes.

Could you please fix that? I think adding a suffix or timestamp for new files with the same name should be a good choice. Also, a check of file size (or sha1? I don't know whether it is possible) could be done before downloading to avoid duplication of tasks. Thanks.

alfem commented

Do you mean you are downloading two files with the same filename simultaneously?

Either simultaneously or successively, they both cause unexpected behaviours. The former results in breaking of two files, while the latter results in overwriting of file1. I found this accidentally because some channel owners prefer to send all photos or videos in the same filename for the purpose of advertising.

As a workaround, I have to rename file1 before starting to download file2. But I think it could be solved by adding something to the filename in this case.