Return a list of preferred locations for temporary files
| 1884 | |
| 1885 | // Return a list of preferred locations for temporary files |
| 1886 | std::vector<NativePathString> GetPlatformTemporaryDirs() { |
| 1887 | struct TempDirSelector { |
| 1888 | std::string env_var; |
| 1889 | NativePathString path_append; |
| 1890 | }; |
| 1891 | |
| 1892 | std::vector<TempDirSelector> selectors; |
| 1893 | NativePathString fallback_tmp; |
| 1894 | |
| 1895 | #if _WIN32 |
| 1896 | selectors = { |
| 1897 | {"TMP", L""}, {"TEMP", L""}, {"LOCALAPPDATA", L"Temp"}, {"USERPROFILE", L"Temp"}}; |
| 1898 | fallback_tmp = GetWindowsDirectoryPath(); |
| 1899 | |
| 1900 | #else |
| 1901 | selectors = {{"TMPDIR", ""}, {"TMP", ""}, {"TEMP", ""}, {"TEMPDIR", ""}}; |
| 1902 | # ifdef __ANDROID__ |
| 1903 | fallback_tmp = "/data/local/tmp"; |
| 1904 | # else |
| 1905 | fallback_tmp = "/tmp"; |
| 1906 | # endif |
| 1907 | #endif |
| 1908 | |
| 1909 | std::vector<NativePathString> temp_dirs; |
| 1910 | for (const auto& sel : selectors) { |
| 1911 | auto result = GetEnvVarNative(sel.env_var); |
| 1912 | if (result.status().IsKeyError()) { |
| 1913 | // Environment variable absent, skip |
| 1914 | continue; |
| 1915 | } |
| 1916 | if (!result.ok()) { |
| 1917 | ARROW_LOG(WARNING) << "Failed getting env var '" << sel.env_var |
| 1918 | << "': " << result.status().ToString(); |
| 1919 | continue; |
| 1920 | } |
| 1921 | NativePathString p = *std::move(result); |
| 1922 | if (p.empty()) { |
| 1923 | // Environment variable set to empty string, skip |
| 1924 | continue; |
| 1925 | } |
| 1926 | if (sel.path_append.empty()) { |
| 1927 | temp_dirs.push_back(p); |
| 1928 | } else { |
| 1929 | temp_dirs.push_back(p + kNativeSep + sel.path_append); |
| 1930 | } |
| 1931 | } |
| 1932 | temp_dirs.push_back(fallback_tmp); |
| 1933 | return temp_dirs; |
| 1934 | } |
| 1935 | |
| 1936 | std::string MakeRandomName(int num_chars) { |
| 1937 | constexpr std::string_view chars = "0123456789abcdefghijklmnopqrstuvwxyz"; |
no test coverage detected