Replace usages of android::base::Realpath#2446
Replace usages of android::base::Realpath#2446jemoreira wants to merge 5 commits intogoogle:mainfrom
Conversation
| LOG(WARNING) << "Tilde expansion in path " << path <<" is not supported"; | ||
| return {}; | ||
| if (path == "~" || absl::StartsWith(path, "~/")) { | ||
| auto home = SystemWideUserHome(); |
There was a problem hiding this comment.
This is not how ~ expansion works in the shell. For comparison, look at
HOME=$PWD bash -c 'echo ~'
This will print $PWD. So really ~ expansion should look at HOME. This also breaks the circular dependency, and SystemWideUserHome can still use AbsolutePath.
There was a problem hiding this comment.
I mentioned it in the commit message, but forgot to copy to the PR description. I didn't want to use the HOME var because we frequently modify that value. We'd only get ~ in a path given by the user, the user is not expecting cvd to replace that with the group home instead of their home. I can drop this commit, since neither the variable or the system wide home are correct and it worked fine without it before. It just bothered me that it was returning and empty string, but that wasn't fixed by this either.
SystemWideHome doesn't need AbsolutePath. It's getting the value from getpwuid, which should be absolute or that user is going to have a different home directory every time they cd.
There was a problem hiding this comment.
Removed the special handling of ~. This should be handled by the shell only, commands should allow it in paths since it's a valid file name.
The tilde character (~) is valid in path names. A file or directory named just "~" is permitted in Linux/Unix, so AbsolutePath should allow it instead of returning empty string. Tilde expansion is performed by the shell and not typically expected from commands.
and move variable declaration closer to where it's used
Calling realpath on the value obtained from getpwuid will cause it to resolve symbolic links (that value should already be an absolute path). That symbolic link resolution may cause problems when the returned value is later compared with the HOME environment variable or when used in cuttlefish::EmulateAbsolutePath with follow_symlinks set to false.
With our own implementation that calls C's realpath(). Bug: b/505481472
Bug: b/505481472
Assisted-by: Gemini:Next