aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-02-14 23:50:41 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-02-14 23:50:41 +0000
commit8c212ebe53bb2baab3575f03069016f1fb11e449 (patch)
tree56758c13a337beb7a271ab86a9b232d821e2461e
parent344e5f3db17615cc853073a02968a603efd39109 (diff)
parentd10596bd14e5abcdaa7fa5ebdb55a883a80c9406 (diff)
downloadgtest-tools_r22.tar.gz
Merge "Only use $EXTERNAL_STORAGE if it exists and is writable."tools_r22jb-mr1.1-dev-plus-aosp
-rw-r--r--src/gtest-port.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gtest-port.cc b/src/gtest-port.cc
index 01c5e1e..f914dbc 100644
--- a/src/gtest-port.cc
+++ b/src/gtest-port.cc
@@ -508,16 +508,23 @@ class CapturedStream {
// ANDROID
#elif GTEST_OS_LINUX_ANDROID
// Get $EXTERNAL_STORAGE from the environment, since this can change
- // for shell users (fallback is still /sdcard, but this probably will
- // never work properly again).
- ::std::string external_storage = "/sdcard";
+ // for shell users (fallback is /data/nativetest, for emulator users).
+ ::std::string external_storage = "/data/nativetest";
char *sdcard_path = getenv("EXTERNAL_STORAGE");
- if (sdcard_path) {
- external_storage = sdcard_path;
+ if (sdcard_path != NULL) {
+ // Check that $EXTERNAL_STORAGE exists and is writable before trying to use it.
+ struct stat sb;
+ if (stat(sdcard_path, &sb) != -1) {
+ if ((sb.st_mode & S_IWUSR) != 0) {
+ external_storage = sdcard_path;
+ }
+ }
}
external_storage += "/captured_stderr.XXXXXX";
char *name_template = strdup(external_storage.c_str());
const int captured_fd = mkstemp(name_template);
+ GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
+ << name_template;
filename_ = name_template;
free(name_template);
name_template = NULL;