Handle remote files without hanging

These changes make hardhat mode work on remote files, with the caveat that symlinks are not resolved on remote file names.