Extract duplicated stat and entries functions

Also avoid creating excess Pathname objects we don't need to.