| 228 | #endif |
| 229 | |
| 230 | void PosixEnv::GetLocalTempDirectories(std::vector<string>* list) { |
| 231 | list->clear(); |
| 232 | // Directories, in order of preference. If we find a dir that |
| 233 | // exists, we stop adding other less-preferred dirs |
| 234 | const char* candidates[] = { |
| 235 | // Non-null only during unittest/regtest |
| 236 | getenv("TEST_TMPDIR"), |
| 237 | |
| 238 | // Explicitly-supplied temp dirs |
| 239 | getenv("TMPDIR"), |
| 240 | getenv("TMP"), |
| 241 | |
| 242 | #if defined(__ANDROID__) |
| 243 | "/data/local/tmp", |
| 244 | #endif |
| 245 | |
| 246 | // If all else fails |
| 247 | "/tmp", |
| 248 | }; |
| 249 | |
| 250 | for (const char* d : candidates) { |
| 251 | if (!d || d[0] == '\0') continue; // Empty env var |
| 252 | |
| 253 | // Make sure we don't surprise anyone who's expecting a '/' |
| 254 | string dstr = d; |
| 255 | if (dstr[dstr.size() - 1] != '/') { |
| 256 | dstr += "/"; |
| 257 | } |
| 258 | |
| 259 | struct stat statbuf; |
| 260 | if (!stat(d, &statbuf) && S_ISDIR(statbuf.st_mode) && |
| 261 | !access(dstr.c_str(), 0)) { |
| 262 | // We found a dir that exists and is accessible - we're done. |
| 263 | list->push_back(dstr); |
| 264 | return; |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | } // namespace tensorflow |
no test coverage detected