As far as I can tell, this just computes the filename of the FileSpec,
which is already conveniently stored in m_filename. We can use
FileSpec::GetFilename() instead.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
@bulbazord What if the FileSpec is pointing to a directory instead of a file ? What would GetFilename return in that case compared to GetLastPathComponent ?
FileSpec chops everything up into a directory and a filename, even if it's pointing to a directory. For example:
fspec = lldb.SBFileSpec("/foo/bar/baz/") print(fspec.GetDirectory()) print(fspec.GetFilename())
This will print "/foo/bar" followed by "baz". baz is clearly a directory, but FileSpec will treat it as the filename. GetLastPathComponent uses llvm::sys::path::filename to get the last element of the path, which is the exact same mechanism we use when constructing FileSpec's internal m_directory and m_filename in the first place.
Here's some more bike-shedding: This is not related to this patch specifically, but I don't think GetFilename()should return baz since it's not a file. Similarly, GetDirectory() should /foo/bar/baz/. Then in order to get the pointed file or directory I'd use GetLastPathComponent(). And to get the parent (/foo/bar), I think we should expose a new GetParent method. TBH, I find the current behavior very confusing.