ar- / incron

cron-like daemon which handles filesystem events
Other
229 stars 51 forks source link

Filename with extension .part #46

Open janvanl opened 6 years ago

janvanl commented 6 years ago

Hi, I have used incrontab to check wether a new file is created in a directory, after checking with several parameter only IN_MOVE_TO gave me the correct Filename myfilename.jpg IN_CREATE gives myfilename.jpg.part Most of the output with ALL_EVENTS gives me myfilename.jpg.part

Have I done something wrong?

Ubuntu 16.04 LTE

Regards, Jan

Daudre-Vignier-Charles commented 6 years ago

This is not a bug: you are monitoring a folder that contains downloaded files. When an internet browser downloads files, it is not done instantly. As long as the file is not completely downloaded, it has the extension .crdownload with Chrome / Chromium or .part with Firefox.

When the file .part or .crdownload is created, an event of type IN_CREATE occurs while the file is not completely downloaded. Your script will work on an incomplete file, this will generate errors.

To solve the problem, in the script it is necessary to test the extension of the file and leave the script if it is .part / .crdownload and to change the type of event with using IN_CLOSE_WRITE or IN_MOVE_TO.

gist exemple

one of the first test in my python script is :

if extension == "crdownload" :
    exit()

You can do the same in shell/python/other with ".part".

Daudre-Vignier-Charles commented 6 years ago

look at : if I download an random image from internet (ee35815c.png):

$ cat /var/log/syslog|grep incrond
Mar 10 15:28:35 styx incrond[565]: (touck) CMD (sh /home/touck/.scripts/incron/download_sorter.sh ee35815c.png.crdownload /home/touck/Téléchargements/ IN_CLOSE_WRITE)
Mar 10 15:28:35 styx incrond[565]: (touck) CMD (sh /home/touck/.scripts/incron/download_sorter.sh ee35815c.png /home/touck/Téléchargements/ IN_CLOSE_WRITE)

As you can see, downloading the image triggers two events IN_CLOSE_WRITE. The first concerns the file "ee35815c.png.crdownload" (I have Chromium) and the second concerns the file "ee35815c.png".

The script should ignore the first event when the file end with .crdownload (.part for you) and run for the second event when the file does not end with .crdownload (.part).

janvanl commented 6 years ago

Thanks for the answer, I used IN_MOVE_TO and the script works splendidly, thanks for the work. I do not need now to filter out the .part-file.

I resize (mogrify) uploaded files for a webgallery with it , that is much faster as with a PHP-solution.

I cannot find how to close this issue.

Kind regards, Jan