@@ -564,9 +564,9 @@ std::filesystem::path FindBasePath()
564564 progPath = basePath.data ();
565565#elif __linux__
566566 char basePath[PATH_MAX ];
567- ssize_t len = ::readlink (" /proc/self/exe" , basePath, sizeof (basePath));
568- if (len == -1 || len == sizeof (basePath))
569- len = 0 ;
567+ ssize_t len = ::readlink (" /proc/self/exe" , basePath, sizeof (basePath));
568+ if (len == -1 || len == sizeof (basePath))
569+ len = 0 ;
570570 basePath[len] = ' \0 ' ;
571571 progPath = basePath;
572572#elif __APPLE__ && __MACH__
@@ -575,34 +575,34 @@ std::filesystem::path FindBasePath()
575575 proc_pidpath (pid, basePath, sizeof (basePath));
576576 progPath = basePath;
577577#endif
578- progPath = canonical (progPath);
578+ progPath = weakly_canonical (progPath);
579579 return progPath.parent_path ();
580580}
581581
582- std::optional<std::filesystem::path> FindUserPath ()
582+ std::tuple<std:: optional<std::filesystem::path>, std::optional<std::string> > FindUserPath ()
583583{
584584#ifdef _WIN32
585- PWSTR osPath{};
586- HRESULT hr = SHGetKnownFolderPath (FOLDERID_Documents, KF_FLAG_DEFAULT , nullptr , &osPath);
585+ PWSTR osPath{};
586+ HRESULT hr = SHGetKnownFolderPath (FOLDERID_Documents, KF_FLAG_DEFAULT , nullptr , &osPath);
587587 if (FAILED (hr)) {
588588 // The path may be inaccessible due to malfunctioning cloud providers.
589589 CoTaskMemFree (osPath);
590- return {};
590+ return { {}, " Could not obtain Documents path from Windows " };
591591 }
592592 std::wstring pathStr = osPath;
593593 CoTaskMemFree (osPath);
594594 std::filesystem::path path (pathStr);
595- return canonical (path);
595+ return { weakly_canonical (path), {} } ;
596596#else
597- if (char const * data_home_path = getenv (" XDG_DATA_HOME" )) {
598- return data_home_path ;
599- }
600- if (char const * home_path = getenv (" HOME" )) {
601- return std::filesystem::path (home_path) / " .local/share" ;
602- }
603- uid_t uid = getuid ();
604- struct passwd *pw = getpwuid (uid);
605- return std::filesystem::path (pw->pw_dir ) / " .local/share" ;
597+ if (char const * data_home_path = getenv (" XDG_DATA_HOME" )) {
598+ return { data_home_path, {} } ;
599+ }
600+ if (char const * home_path = getenv (" HOME" )) {
601+ return { std::filesystem::path (home_path) / " .local/share" , {} } ;
602+ }
603+ uid_t uid = getuid ();
604+ struct passwd *pw = getpwuid (uid);
605+ return { std::filesystem::path (pw->pw_dir ) / " .local/share" , {} } ;
606606#endif
607607}
608608
@@ -628,7 +628,7 @@ sys_main_c::sys_main_c()
628628
629629 // Set the local system information
630630 basePath = FindBasePath ();
631- userPath = FindUserPath ();
631+ std::tie ( userPath, userPathReason) = FindUserPath ();
632632}
633633
634634bool sys_main_c::Run (int argc, char ** argv)
0 commit comments