in reply to Re^3: Scoping question - will file handle be closed?
in thread Scoping question - will file handle be closed?
Warn the user that there's something wrong.
Okay. But "Something's wrong!" isn't very useful to the user.
According to POSIX, close can fail with one of 3 errors:
Hopefully, if this can occur in the application, it'll be detected/sorted before the user gets his hands in it.
Ditto. If this is a possibility, a signal handler will have been installed to handle it.
And we're back to "Something's wrong!".
And then, the man page says:"A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes.", so even a successful close doesn't guarantee good data.
So we've told the user, "Something's wrong!, but not what. And even if we haven't told him, something could still be wrong. So where does that leave him?
He could decide to re-run the process to recreate the file; but what if it (whatever "it" is) happens again?
And, it could be he does so unnecessarily, because it was only the close that failed and not the preceding writes.
And what can he do about the failures that happen after we've closed the file; due to caching?
In the end, the only arbiter of whether the file is good is whether the next use of that file is successful.
So, the only sure way to detect the types of problems that might be indicated by close failing, is to ensure that the next process in the chain; even if that is a human being reading the file, can adequately detect that the file is incomplete or otherwise corrupted. Perhaps a sentinel record ("The end") or an known file size.
And whatever mechanism is put in place for the next process to detect the error; negates any purpose in detecting and warning that "Something's wrong!";
Did I miss a possibility?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Scoping question - will file handle be closed? (close errors)
by tye (Sage) on Jul 14, 2015 at 23:35 UTC | |
by BrowserUk (Patriarch) on Jul 15, 2015 at 14:53 UTC | |
by tye (Sage) on Jul 15, 2015 at 18:33 UTC | |
|
Re^5: Scoping question - will file handle be closed?
by Monk::Thomas (Friar) on Jul 14, 2015 at 20:55 UTC | |
by BrowserUk (Patriarch) on Jul 14, 2015 at 21:07 UTC | |
by Monk::Thomas (Friar) on Jul 14, 2015 at 21:15 UTC | |
by BrowserUk (Patriarch) on Jul 14, 2015 at 21:34 UTC | |
by Monk::Thomas (Friar) on Jul 14, 2015 at 21:48 UTC | |
|