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

FAQ ambiguity for IN_CLOSE_WRITE #55

Closed
ralienpp opened this issue Sep 13, 2013 · 3 comments
Closed

FAQ ambiguity for IN_CLOSE_WRITE #55

ralienpp opened this issue Sep 13, 2013 · 3 comments

Comments

@ralienpp
Copy link

There is a tricky part in the FAQ that leaves room for interpretation:

use IN_CLOSE_WRITE because if emitted the all changes on the appropriate file are safely written inside the file

Does it mean

  1. if emitted, all the changes are safely inside the file
  2. emitted before all the changes are safely inside the file

It seems to be the former, but I am experiencing a situation in which IN_CLOSE_WRITE is triggered, but when I open the file - it doesn't contain any changes yet. So I thought I would first make sure that I understand the manual correctly.

@seb-m
Copy link
Owner

seb-m commented Sep 13, 2013

Hi Alex,

Which FAQ are you referring to?, I can't find where I wrote this. Anyway, to answer your point, the inotify manpage only states:

File opened for writing was closed

I believe that this event only provides the information that the corresponding file descriptor was closed, I don't think it provides any guarantee on the integrity/completion of written data on disk, there are certainly system buffers that may or may not have been flushed at the moment the file was closed.

I hope it helps,
sébastien

@ralienpp
Copy link
Author

Thank you for the ultra-fast reaction. Here's the page where I found that:
http://inotify.aiken.cz/?section=inotify&page=faq&lang=en

Hmmm... so this is a generic behaviour side-effect of inotify and not something specific to pyinotify. In case someone else is wondering how this worked out, here's a StackOverflow discussion about it:
http://stackoverflow.com/questions/18782050/premature-in-close-write-notification-with-pyinotify

@seb-m
Copy link
Owner

seb-m commented Sep 13, 2013

As I said previously I think that the mission of inotify (and therefore as reported by Pyinotify) is to signal you when a file is closed (more precisely when it is closed by its file descriptor), but obviously the kernel uses buffers and so the file data may not be written on disk immediately. For more details see the man (2) of the close() function:

A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. It is not common for a file system to flush the buffers when the stream is closed. If you need to be sure that the data is physically stored use fsync(2). (It will depend on the disk hardware at this point.)

Bottom line you can not rely on IN_CLOSE_WRITE to be certain that your data has finished to be been written on disk.

@seb-m seb-m closed this as completed Sep 13, 2013
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