fix
This commit is contained in:
		| @@ -55,7 +55,7 @@ public: | ||||
|   get_provider_name(const provider_type &prov) -> std::string; | ||||
|  | ||||
| public: | ||||
|   app_config(const provider_type &prov, const std::string &data_directory = ""); | ||||
|   app_config(const provider_type &prov, std::string_view data_directory = ""); | ||||
|  | ||||
|   ~app_config() { save(); } | ||||
|  | ||||
|   | ||||
| @@ -54,7 +54,7 @@ constexpr const auto retry_save_count = 5U; | ||||
|  | ||||
| namespace repertory { | ||||
| app_config::app_config(const provider_type &prov, | ||||
|                        const std::string &data_directory) | ||||
|                        std::string_view data_directory) | ||||
|     : prov_(prov), | ||||
|       api_auth_(utils::generate_random_string(default_api_auth_size)), | ||||
|       api_port_(default_rpc_port(prov)), | ||||
| @@ -151,19 +151,28 @@ auto app_config::default_api_port(const provider_type &prov) -> std::uint16_t { | ||||
| auto app_config::default_data_directory(const provider_type &prov) | ||||
|     -> std::string { | ||||
| #if defined(_WIN32) | ||||
|   auto data_directory = utils::path::combine( | ||||
|       utils::get_local_app_data_directory(), | ||||
|       {std::string{REPERTORY_DATA_NAME}, app_config::get_provider_name(prov)}); | ||||
|   auto data_directory = | ||||
|       utils::path::combine(utils::get_local_app_data_directory(), | ||||
|                            { | ||||
|                                REPERTORY_DATA_NAME, | ||||
|                                app_config::get_provider_name(prov), | ||||
|                            }); | ||||
| #else | ||||
| #if defined(__APPLE__) | ||||
|   auto data_directory = | ||||
|       utils::path::resolve(std::string{"~/Library/Application Support/"} + | ||||
|                            std::string{REPERTORY_DATA_NAME} + '/' + | ||||
|                            app_config::get_provider_name(prov)); | ||||
|   auto data_directory = utils::path::resolve( | ||||
|       utils::path::combine("~", { | ||||
|                                     "Library", | ||||
|                                     "Application Support", | ||||
|                                     REPERTORY_DATA_NAME, | ||||
|                                     app_config::get_provider_name(prov), | ||||
|                                 })); | ||||
| #else | ||||
|   auto data_directory = utils::path::resolve( | ||||
|       std::string{"~/.local/"} + std::string{REPERTORY_DATA_NAME} + '/' + | ||||
|       app_config::get_provider_name(prov)); | ||||
|       utils::path::combine("~", { | ||||
|                                     ".local", | ||||
|                                     REPERTORY_DATA_NAME, | ||||
|                                     app_config::get_provider_name(prov), | ||||
|                                 })); | ||||
| #endif | ||||
| #endif | ||||
|   return data_directory; | ||||
| @@ -528,6 +537,7 @@ auto app_config::load() -> bool { | ||||
|   auto ret = false; | ||||
|  | ||||
|   const auto config_file_path = get_config_file_path(); | ||||
|   std::cout << config_file_path << std::endl; | ||||
|   recur_mutex_lock lock(read_write_mutex_); | ||||
|   if (utils::file::is_file(config_file_path)) { | ||||
|     try { | ||||
|   | ||||
| @@ -91,6 +91,7 @@ mount(std::vector<const char *> args, std::string data_directory, | ||||
| #endif | ||||
|       const auto drive_args = | ||||
|           utils::cli::parse_drive_options(args, prov, data_directory); | ||||
|       std::cout << data_directory << std::endl; | ||||
|       app_config config(prov, data_directory); | ||||
| #if defined(_WIN32) | ||||
|       if (config.get_enable_mount_manager() && | ||||
|   | ||||
							
								
								
									
										12
									
								
								support/3rd_party/include/utils/path.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								support/3rd_party/include/utils/path.hpp
									
									
									
									
										vendored
									
									
								
							| @@ -141,9 +141,9 @@ get_not_directory_seperator<wchar_t>() -> std::basic_string_view<wchar_t> { | ||||
|   return not_directory_seperator_w; | ||||
| } | ||||
|  | ||||
| [[nodiscard]] inline auto absolute(std::string_view path) -> std::string; | ||||
| [[nodiscard]] auto absolute(std::string_view path) -> std::string; | ||||
|  | ||||
| [[nodiscard]] inline auto absolute(std::wstring_view path) -> std::wstring; | ||||
| [[nodiscard]] auto absolute(std::wstring_view path) -> std::wstring; | ||||
|  | ||||
| [[nodiscard]] inline auto | ||||
| combine(std::string path, | ||||
| @@ -226,14 +226,6 @@ get_parent_api_path(std::wstring_view path) -> std::wstring; | ||||
|  | ||||
| [[nodiscard]] auto unmake_file_uri(std::wstring_view uri) -> std::wstring; | ||||
|  | ||||
| inline auto absolute(std::string_view path) -> std::string { | ||||
|   return std::filesystem::absolute(finalize(path)).lexically_normal().string(); | ||||
| } | ||||
|  | ||||
| inline auto absolute(std::wstring_view path) -> std::wstring { | ||||
|   return std::filesystem::absolute(finalize(path)).lexically_normal().wstring(); | ||||
| } | ||||
|  | ||||
| template <typename string_t> | ||||
| [[nodiscard]] inline auto combine_t( | ||||
|     string_t path, | ||||
|   | ||||
							
								
								
									
										34
									
								
								support/3rd_party/src/utils/path.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										34
									
								
								support/3rd_party/src/utils/path.cpp
									
									
									
									
										vendored
									
									
								
							| @@ -36,6 +36,40 @@ static const std::wstring directory_seperator_str_w{ | ||||
| } // namespace | ||||
|  | ||||
| namespace repertory::utils::path { | ||||
| inline auto absolute(std::string_view path) -> std::string { | ||||
|   std::string abs_path{path}; | ||||
| #ifdef _WIN32 | ||||
|   if (not abs_path.empty() && ::PathIsRelative(abs_path.c_str())) { | ||||
|     std::string temp; | ||||
|     temp.resize(MAX_PATH + 1); | ||||
|     abs_path = _fullpath(temp.c_str(), abs_path.data(), MAX_PATH); | ||||
|   } | ||||
| #else | ||||
|   if (not abs_path.empty() && (abs_path.at(0U) != '/')) { | ||||
|     auto found{false}; | ||||
|     std::string tmp{abs_path}; | ||||
|     do { | ||||
|       auto *res = realpath(tmp.c_str(), nullptr); | ||||
|       if (res) { | ||||
|         abs_path = combine(res, {abs_path.substr(tmp.size())}); | ||||
|         free(res); | ||||
|         found = true; | ||||
|       } else if (tmp == ".") { | ||||
|         found = true; | ||||
|       } else { | ||||
|         tmp = dirname(tmp.c_str()); | ||||
|       } | ||||
|     } while (not found); | ||||
|   } | ||||
| #endif | ||||
|  | ||||
|   return finalize(abs_path); | ||||
| } | ||||
|  | ||||
| inline auto absolute(std::wstring_view path) -> std::wstring { | ||||
|   return utils::string::from_utf8(absolute(utils::string::to_utf8(path))); | ||||
| } | ||||
|  | ||||
| auto find_program_in_path(const std::string &name_without_extension) | ||||
|     -> std::string { | ||||
|   static std::mutex mtx{}; | ||||
|   | ||||
							
								
								
									
										50
									
								
								support/3rd_party/test/src/utils/path_test.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										50
									
								
								support/3rd_party/test/src/utils/path_test.cpp
									
									
									
									
										vendored
									
									
								
							| @@ -120,43 +120,43 @@ TEST(utils_path, combine) { | ||||
| } | ||||
|  | ||||
| TEST(utils_path, format_path) { | ||||
|   std::string path{"\\"}; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   std::string path{"./"}; | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ(".", path.c_str()); | ||||
|  | ||||
|   path = "~/.test"; | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("~/.test", path.c_str()); | ||||
|  | ||||
|   path = "\\"; | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|  | ||||
|   path = "\\\\"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|  | ||||
|   path = "\\\\\\"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|  | ||||
|   path = "\\\\\\\\"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|  | ||||
|   path = "/"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|   path = "//"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|  | ||||
|   path = "///"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
|  | ||||
|   path = "////"; | ||||
|   utils::path::format_path(path, utils::path::directory_seperator, | ||||
|                            utils::path::not_directory_seperator); | ||||
|   utils::path::format_path(path, utils::path::slash, utils::path::backslash); | ||||
|   EXPECT_STREQ("/", path.c_str()); | ||||
| } | ||||
|  | ||||
| @@ -245,4 +245,20 @@ TEST(utils_path, finalize) { | ||||
|   EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str()); | ||||
| #endif | ||||
| } | ||||
|  | ||||
| #if !defined(_WIN32) | ||||
| TEST(utils_path, resolve) { | ||||
|   std::cout << utils::path::resolve("~") << std::endl; | ||||
|   std::cout << utils::path::combine("~", | ||||
|                                     { | ||||
|                                         ".local", | ||||
|                                     }) | ||||
|             << std::endl; | ||||
|   std::cout << utils::path::resolve(utils::path::combine("~", | ||||
|                                                          { | ||||
|                                                              ".local", | ||||
|                                                          })) | ||||
|             << std::endl; | ||||
| } | ||||
| #endif // !defined(_WIN32) | ||||
| } // namespace repertory | ||||
|   | ||||
		Reference in New Issue
	
	Block a user