MCPcopy Create free account
hub / github.com/apache/arrow / GetPlatformTemporaryDirs

Function GetPlatformTemporaryDirs

cpp/src/arrow/util/io_util.cc:1886–1934  ·  view source on GitHub ↗

Return a list of preferred locations for temporary files

Source from the content-addressed store, hash-verified

1884
1885// Return a list of preferred locations for temporary files
1886std::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
1936std::string MakeRandomName(int num_chars) {
1937 constexpr std::string_view chars = "0123456789abcdefghijklmnopqrstuvwxyz";

Callers 1

MakeMethod · 0.85

Calls 7

GetWindowsDirectoryPathFunction · 0.85
GetEnvVarNativeFunction · 0.85
push_backMethod · 0.80
statusMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected