From 14d05f4708c97d1efc0db917dd32ef2f2013686a Mon Sep 17 00:00:00 2001 From: Tanzinul Islam Date: Fri, 18 Aug 2023 19:44:48 +0100 Subject: [PATCH 1/2] Prefer $TMPDIR to /data/local/tmp on Android Newer devices can have the latter location read-only. (I observed this with Termux on a non-rooted Pixel 6.) --- googletest/src/gtest-port.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 2aaf2bcc..589ace5e 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1064,7 +1064,13 @@ class CapturedStream { // The location /data/local/tmp is directly accessible from native code. // '/sdcard' and other variants cannot be relied on, as they are not // guaranteed to be mounted, or may have a delay in mounting. - name_template = "/data/local/tmp/"; + // + // However, prefer using the TMPDIR environment variable if set, as newer + // devices may have /data/local/tmp read-only. + if (auto tmpdir = ::getenv("TMPDIR")) + name_template.assign(tmpdir) += '/'; + else + name_template = "/data/local/tmp/"; #elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1]; From edf9b4964d28f0f18552ff39c8f182b7903e19e3 Mon Sep 17 00:00:00 2001 From: Tanzinul Islam Date: Sat, 26 Aug 2023 08:53:45 +0100 Subject: [PATCH 2/2] Reuse TempDir() function --- googletest/src/gtest-port.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 589ace5e..628ab3db 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1067,10 +1067,7 @@ class CapturedStream { // // However, prefer using the TMPDIR environment variable if set, as newer // devices may have /data/local/tmp read-only. - if (auto tmpdir = ::getenv("TMPDIR")) - name_template.assign(tmpdir) += '/'; - else - name_template = "/data/local/tmp/"; + name_template = TempDir(); #elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1];