I know this isn't a part of your change, but could you change this from stat to either lstat or fstat so it resolves symlinks as well?  In my functional test, it doesn't run if you have symlinks there.