We can't always rely on the initial URL's path(), so use either the user-specified argument or the URL path for determining the realpath, depending on whether we got a file:// URL argument. Fixes #4950.