Best practice for putting stuff into such monitored directories is to put the file into the directory with a known-temporary name (using a convention such as appending ".tmp" to the file name) and then to rename the file (to remove the ".tmp" suffix) next. Renaming a file via rename is an atomic file-system operation so if you see a file w/o a *.tmp name, there is no race condition involved if you then try to open it and read it (the file has already been completely written).

But, yes, using IN_CLOSE_WRITE and IN_MOVED_TO make a lot more sense. I didn't find the description of IN_CLOSE_WRITE clear in the module documentation but "(a watched file or) a file within a watched directory was closed, after being opened in writeable mode (this does not necessarily imply the file was written to)" seems clear and what you want.

- tye        


In reply to Re: Race condition in Linux::Inotify2 between dir and new file? (cp then mv) by tye
in thread Race condition in Linux::Inotify2 between dir and new file? by Your Mother

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.