![]() |
|
XP is just a number | |
PerlMonks |
Re^2: Testing for readdir failureby Bob Cook (Acolyte) |
on Apr 22, 2013 at 17:03 UTC ( #1029928=note: print w/replies, xml ) | Need Help?? |
Many thanks to all of you for your thoughtful replies.
First of all, after reading some of the replies, it became clear that I missed making one point: When the readdir fails to deliver the entire contents of the directory, there is NO warning, nor any other message, issued by Perl. Thus, I don't believe that trapping warnings, nor the warnings pragma, will help. I will try $!, and testing for the value of closedir, as well as testing for a "false" value of readdir (though that wouldn't work for readdir in a scalar context) and report back what I find. I downloaded IO::Dirent and looked at its C code. I am a complete novice at C, but it looks to me like it uses C's readdir, whose documentation seems to say that it also returns the same thing for both end-of-directory and an error. (There is a different function named readdir_r which can indicate an error, but that's not what IO::Dirent uses.) It occurs to me that the question I'm really trying to answer is: Exactly what does readdir do when it encounters a problem while reading the directory, and does it do anything that the program can recognize? The suggestion to stat the directory and verify that the link count matches the number of file names returned is a good one, but I can't use it because those two don't always match in the file system I'm concerned with (called AFS). Finally, as many have pointed out, testing any of this is clearly a problem.
In Section
Seekers of Perl Wisdom
|
|