Dealing with invalid symlinks and symlink permissions

Currently the file module does not handle invalid symlinks well; it tends to crash out when it encounters them, since os.stat tries to follow them. This patch fixes those crashes, and also uses lstat and lchown in a number of strategic places to set permissions on the symlink itself, rather than the target of the symlink, which is typically what is really desired.