Use safe_hasattr in dir2

Add test cases

Move safe_hasattr to utils/dir2