This revision was automatically updated to reflect the committed changes. Closed by commit rL250502: Fix temporary directory computation on linux (pr25147) (authored by labath).
Changed prior to commit: http://reviews.llvm.org/D13772?vs=37485&id=37565#toc Repository: rL LLVM http://reviews.llvm.org/D13772 Files: lldb/trunk/source/Host/android/HostInfoAndroid.cpp lldb/trunk/source/Host/common/HostInfoBase.cpp Index: lldb/trunk/source/Host/android/HostInfoAndroid.cpp =================================================================== --- lldb/trunk/source/Host/android/HostInfoAndroid.cpp +++ lldb/trunk/source/Host/android/HostInfoAndroid.cpp @@ -91,11 +91,14 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec) { - if (HostInfoLinux::ComputeTempFileBaseDirectory(file_spec)) - return true; + bool success = HostInfoLinux::ComputeTempFileBaseDirectory(file_spec); - // If the default mechanism for computing the temp directory failed then - // fall back to /data/local/tmp - file_spec = FileSpec("/data/local/tmp", false); - return true; + // On Android, there is no path which is guaranteed to be writable. If the user has not + // provided a path via an environment variable, the generic algorithm will deduce /tmp, which + // is plain wrong. In that case we have an invalid directory, we substitute the path with + // /data/local/tmp, which is correct at least in some cases (i.e., when running as shell user). + if (!success || !file_spec.Exists()) + file_spec = FileSpec("/data/local/tmp", false); + + return file_spec.Exists(); } Index: lldb/trunk/source/Host/common/HostInfoBase.cpp =================================================================== --- lldb/trunk/source/Host/common/HostInfoBase.cpp +++ lldb/trunk/source/Host/common/HostInfoBase.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Host.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <thread> @@ -344,19 +345,9 @@ bool HostInfoBase::ComputeTempFileBaseDirectory(FileSpec &file_spec) { - file_spec.Clear(); - - const char *tmpdir_cstr = getenv("TMPDIR"); - if (tmpdir_cstr == nullptr) - { - tmpdir_cstr = getenv("TMP"); - if (tmpdir_cstr == nullptr) - tmpdir_cstr = getenv("TEMP"); - } - if (!tmpdir_cstr) - return false; - - file_spec = FileSpec(tmpdir_cstr, false); + llvm::SmallVector<char, 16> tmpdir; + llvm::sys::path::system_temp_directory(/*ErasedOnReboot*/ true, tmpdir); + file_spec = FileSpec(std::string(tmpdir.data(), tmpdir.size()), true); return true; }
Index: lldb/trunk/source/Host/android/HostInfoAndroid.cpp =================================================================== --- lldb/trunk/source/Host/android/HostInfoAndroid.cpp +++ lldb/trunk/source/Host/android/HostInfoAndroid.cpp @@ -91,11 +91,14 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec) { - if (HostInfoLinux::ComputeTempFileBaseDirectory(file_spec)) - return true; + bool success = HostInfoLinux::ComputeTempFileBaseDirectory(file_spec); - // If the default mechanism for computing the temp directory failed then - // fall back to /data/local/tmp - file_spec = FileSpec("/data/local/tmp", false); - return true; + // On Android, there is no path which is guaranteed to be writable. If the user has not + // provided a path via an environment variable, the generic algorithm will deduce /tmp, which + // is plain wrong. In that case we have an invalid directory, we substitute the path with + // /data/local/tmp, which is correct at least in some cases (i.e., when running as shell user). + if (!success || !file_spec.Exists()) + file_spec = FileSpec("/data/local/tmp", false); + + return file_spec.Exists(); } Index: lldb/trunk/source/Host/common/HostInfoBase.cpp =================================================================== --- lldb/trunk/source/Host/common/HostInfoBase.cpp +++ lldb/trunk/source/Host/common/HostInfoBase.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Host.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <thread> @@ -344,19 +345,9 @@ bool HostInfoBase::ComputeTempFileBaseDirectory(FileSpec &file_spec) { - file_spec.Clear(); - - const char *tmpdir_cstr = getenv("TMPDIR"); - if (tmpdir_cstr == nullptr) - { - tmpdir_cstr = getenv("TMP"); - if (tmpdir_cstr == nullptr) - tmpdir_cstr = getenv("TEMP"); - } - if (!tmpdir_cstr) - return false; - - file_spec = FileSpec(tmpdir_cstr, false); + llvm::SmallVector<char, 16> tmpdir; + llvm::sys::path::system_temp_directory(/*ErasedOnReboot*/ true, tmpdir); + file_spec = FileSpec(std::string(tmpdir.data(), tmpdir.size()), true); return true; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits