Can you move this to FileSystem.h?  I don't think we should be adding more
things that hit the file system to FileSpec.  That's exactly the reason
FileSystem.h exists, because many of the operations will be implemented
differently across platforms, so we should be using the Host layer.

On Fri, Sep 18, 2015 at 2:38 PM Sean Callanan via lldb-commits <
lldb-commits@lists.llvm.org> wrote:

> spyffe updated this revision to Diff 35138.
> spyffe added a comment.
>
> Updated to reflect Greg's comments.
>
>
> http://reviews.llvm.org/D12984
>
> Files:
>   include/lldb/Host/FileSpec.h
>   source/Host/common/FileSpec.cpp
>   source/Host/common/HostInfoBase.cpp
>
> Index: source/Host/common/HostInfoBase.cpp
> ===================================================================
> --- source/Host/common/HostInfoBase.cpp
> +++ source/Host/common/HostInfoBase.cpp
> @@ -306,7 +306,10 @@
>
>      FileSpec lldb_file_spec(
>          Host::GetModuleFileSpecForHostAddress(reinterpret_cast<void
> *>(reinterpret_cast<intptr_t>(HostInfoBase::GetLLDBPath))));
> -
> +
> +    // This is necessary because when running the testsuite the shlib
> might be a symbolic link inside the Python resource dir.
> +    lldb_file_spec = lldb_file_spec.ResolveSymbolicLink();
> +
>      // Remove the filename so that this FileSpec only represents the
> directory.
>      file_spec.GetDirectory() = lldb_file_spec.GetDirectory();
>
> Index: source/Host/common/FileSpec.cpp
> ===================================================================
> --- source/Host/common/FileSpec.cpp
> +++ source/Host/common/FileSpec.cpp
> @@ -811,6 +811,32 @@
>  #endif
>  }
>
> +FileSpec
> +FileSpec::ResolveSymbolicLink () const {
> +    if (!IsSymbolicLink())
> +    {
> +        return *this;
> +    }
> +
> +    char resolved_path[PATH_MAX];
> +    if (!GetPath (resolved_path, sizeof (resolved_path)))
> +    {
> +        return *this;
> +    }
> +
> +#ifdef _WIN32
> +    return *this; // TODO make this work on win32
> +#else
> +    char real_path[PATH_MAX + 1];
> +    if (realpath(resolved_path, real_path) == nullptr)
> +    {
> +        return *this;
> +    }
> +
> +    return FileSpec(real_path, false);
> +#endif
> +}
> +
>  uint32_t
>  FileSpec::GetPermissions () const
>  {
> Index: include/lldb/Host/FileSpec.h
> ===================================================================
> --- include/lldb/Host/FileSpec.h
> +++ include/lldb/Host/FileSpec.h
> @@ -73,7 +73,7 @@
>      ///     The full or partial path to a file.
>      ///
>      /// @param[in] resolve_path
> -    ///     If \b true, then we resolve the path with realpath,
> +    ///     If \b true, then we resolve the path, removing stray ../..
> and so forth,
>      ///     if \b false we trust the path is in canonical form already.
>      ///
>      /// @see FileSpec::SetFile (const char *path, bool resolve)
> @@ -511,6 +511,9 @@
>
>      bool
>      IsSymbolicLink () const;
> +
> +    FileSpec
> +    ResolveSymbolicLink () const;
>
>      //------------------------------------------------------------------
>      /// Get the memory cost of this object.
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to