Use SAFE_STAT instead of stat to avoid unnecessary failure