comparison src/core/filesystem.cc @ 158:80d6b28eb29f

dep/animia: fix most X11 stuff it looks like _NET_WM_PID isn't supported by MOST clients, or my code is wrong... core/filesystem: fix Linux config path handling on *nix
author Paper <mrpapersonic@gmail.com>
date Fri, 17 Nov 2023 02:07:33 -0500
parents 28842a8d0c6b
children 121c2d5b321f
comparison
equal deleted inserted replaced
157:18c8eb5d1edc 158:80d6b28eb29f
25 namespace Filesystem { 25 namespace Filesystem {
26 26
27 /* this runs fs::create_directories() on the 27 /* this runs fs::create_directories() on the
28 PARENT directory. */ 28 PARENT directory. */
29 void CreateDirectories(const std::filesystem::path& path) { 29 void CreateDirectories(const std::filesystem::path& path) {
30 std::filesystem::create_directories(path.parent_path()); 30 if (path.empty())
31 return;
32
33 const auto& parent = path.parent_path();
34 if (!std::filesystem::exists(parent))
35 std::filesystem::create_directories(parent);
31 } 36 }
32 37
33 std::filesystem::path GetDotPath() { 38 std::filesystem::path GetDotPath() {
34 #ifdef WIN32 39 #ifdef WIN32
35 std::filesystem::path path; 40 std::filesystem::path path;
47 const char* home = getenv("HOME"); 52 const char* home = getenv("HOME");
48 # ifdef __linux__ 53 # ifdef __linux__
49 if (!home) 54 if (!home)
50 home = getpwuid(getuid())->pw_dir; 55 home = getpwuid(getuid())->pw_dir;
51 # endif // __linux__ 56 # endif // __linux__
52 if (!home) 57 if (home)
53 return std::filesystem::path(home) / ".config"; 58 return std::filesystem::path(home) / ".config" / CONFIG_DIR;
54 else 59 else
55 return std::filesystem::path(); 60 return std::filesystem::path();
56 #endif // !WIN32 && !MACOSX 61 #endif // !WIN32 && !MACOSX
57 } 62 }
58 63