[Lldb-commits] [PATCH] D149663: [lldb] Remove FileSpec::GetLastPathComponent

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue May 2 11:58:58 PDT 2023


mib added a comment.

In D149663#4313123 <https://reviews.llvm.org/D149663#4313123>, @bulbazord wrote:

> In D149663#4313112 <https://reviews.llvm.org/D149663#4313112>, @mib wrote:
>
>> @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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149663/new/

https://reviews.llvm.org/D149663



More information about the lldb-commits mailing list