refactor
This commit is contained in:
		| @@ -135,8 +135,8 @@ auto get_free_drive_space(std::string_view path) | ||||
| #endif // defined(_WIN32) | ||||
|  | ||||
| #if defined(__linux__) | ||||
|     struct statfs64 st{}; | ||||
|     if (statfs64(std::string{path}.c_str(), &st) != 0) { | ||||
|     struct statfs64 u_stat{}; | ||||
|     if (statfs64(std::string{path}.c_str(), &u_stat) != 0) { | ||||
|       throw utils::error::create_exception( | ||||
|           function_name, { | ||||
|                              "failed to get free disk space", | ||||
| @@ -145,12 +145,12 @@ auto get_free_drive_space(std::string_view path) | ||||
|                          }); | ||||
|     } | ||||
|  | ||||
|     return st.f_bfree * static_cast<std::uint64_t>(st.f_bsize); | ||||
|     return u_stat.f_bfree * static_cast<std::uint64_t>(u_stat.f_bsize); | ||||
| #endif // defined(__linux__) | ||||
|  | ||||
| #if defined(__APPLE__) | ||||
|     struct statvfs st{}; | ||||
|     if (statvfs(std::string{path}.c_str(), &st) != 0) { | ||||
|     struct statvfs u_stat{}; | ||||
|     if (statvfs(std::string{path}.c_str(), &u_stat) != 0) { | ||||
|       throw utils::error::create_exception( | ||||
|           function_name, { | ||||
|                              "failed to get free disk space", | ||||
| @@ -159,7 +159,7 @@ auto get_free_drive_space(std::string_view path) | ||||
|                          }); | ||||
|     } | ||||
|  | ||||
|     return st.f_bfree * static_cast<std::uint64_t>(st.f_frsize); | ||||
|     return u_stat.f_bfree * static_cast<std::uint64_t>(u_stat.f_frsize); | ||||
| #endif // defined(__APPLE__) | ||||
|   } catch (const std::exception &e) { | ||||
|     utils::error::handle_exception(function_name, e); | ||||
| @@ -217,8 +217,8 @@ auto get_times(std::string_view path) -> std::optional<file_times> { | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     struct _stat64 st{}; | ||||
|     if (_stat64(std::string{path}.c_str(), &st) != 0) { | ||||
|     struct _stat64 u_stat{}; | ||||
|     if (_stat64(std::string{path}.c_str(), &u_stat) != 0) { | ||||
|       throw utils::error::create_exception( | ||||
|           function_name, { | ||||
|                              "failed to get file times", | ||||
| @@ -227,13 +227,13 @@ auto get_times(std::string_view path) -> std::optional<file_times> { | ||||
|                          }); | ||||
|     } | ||||
|  | ||||
|     ret.accessed = utils::time::windows_time_t_to_unix_time(st.st_atime); | ||||
|     ret.created = utils::time::windows_time_t_to_unix_time(st.st_ctime); | ||||
|     ret.modified = utils::time::windows_time_t_to_unix_time(st.st_mtime); | ||||
|     ret.written = utils::time::windows_time_t_to_unix_time(st.st_mtime); | ||||
|     ret.accessed = utils::time::windows_time_t_to_unix_time(u_stat.st_atime); | ||||
|     ret.created = utils::time::windows_time_t_to_unix_time(u_stat.st_ctime); | ||||
|     ret.modified = utils::time::windows_time_t_to_unix_time(u_stat.st_mtime); | ||||
|     ret.written = utils::time::windows_time_t_to_unix_time(u_stat.st_mtime); | ||||
| #else // !defined(_WIN32) | ||||
|     struct stat64 st{}; | ||||
|     if (stat64(std::string{path}.c_str(), &st) != 0) { | ||||
|     struct stat64 u_stat{}; | ||||
|     if (stat64(std::string{path}.c_str(), &u_stat) != 0) { | ||||
|       throw utils::error::create_exception( | ||||
|           function_name, { | ||||
|                              "failed to get file times", | ||||
| @@ -243,30 +243,30 @@ auto get_times(std::string_view path) -> std::optional<file_times> { | ||||
|     } | ||||
|  | ||||
| #if defined(__APPLE__) | ||||
|     ret.accessed = static_cast<std::uint64_t>(st.st_atimespec.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(st.st_atimespec.tv_sec) * | ||||
|     ret.accessed = static_cast<std::uint64_t>(u_stat.st_atimespec.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(u_stat.st_atimespec.tv_sec) * | ||||
|                        utils::time::NANOS_PER_SECOND; | ||||
|     ret.created = static_cast<std::uint64_t>(st.st_ctimespec.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(st.st_ctimespec.tv_sec) * | ||||
|     ret.created = static_cast<std::uint64_t>(u_stat.st_ctimespec.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(u_stat.st_ctimespec.tv_sec) * | ||||
|                       utils::time::NANOS_PER_SECOND; | ||||
|     ret.modified = static_cast<std::uint64_t>(st.st_mtimespec.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(st.st_mtimespec.tv_sec) * | ||||
|     ret.modified = static_cast<std::uint64_t>(u_stat.st_mtimespec.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(u_stat.st_mtimespec.tv_sec) * | ||||
|                        utils::time::NANOS_PER_SECOND; | ||||
|     ret.written = static_cast<std::uint64_t>(st.st_mtimespec.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(st.st_mtimespec.tv_sec) * | ||||
|     ret.written = static_cast<std::uint64_t>(u_stat.st_mtimespec.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(u_stat.st_mtimespec.tv_sec) * | ||||
|                       utils::time::NANOS_PER_SECOND; | ||||
| #else  // !defined(__APPLE__) | ||||
|     ret.accessed = static_cast<std::uint64_t>(st.st_atim.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(st.st_atim.tv_sec) * | ||||
|     ret.accessed = static_cast<std::uint64_t>(u_stat.st_atim.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(u_stat.st_atim.tv_sec) * | ||||
|                        utils::time::NANOS_PER_SECOND; | ||||
|     ret.created = static_cast<std::uint64_t>(st.st_ctim.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(st.st_ctim.tv_sec) * | ||||
|     ret.created = static_cast<std::uint64_t>(u_stat.st_ctim.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(u_stat.st_ctim.tv_sec) * | ||||
|                       utils::time::NANOS_PER_SECOND; | ||||
|     ret.modified = static_cast<std::uint64_t>(st.st_mtim.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(st.st_mtim.tv_sec) * | ||||
|     ret.modified = static_cast<std::uint64_t>(u_stat.st_mtim.tv_nsec) + | ||||
|                    static_cast<std::uint64_t>(u_stat.st_mtim.tv_sec) * | ||||
|                        utils::time::NANOS_PER_SECOND; | ||||
|     ret.written = static_cast<std::uint64_t>(st.st_mtim.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(st.st_mtim.tv_sec) * | ||||
|     ret.written = static_cast<std::uint64_t>(u_stat.st_mtim.tv_nsec) + | ||||
|                   static_cast<std::uint64_t>(u_stat.st_mtim.tv_sec) * | ||||
|                       utils::time::NANOS_PER_SECOND; | ||||
| #endif // defined(__APPLE__) | ||||
| #endif // defined(_WIN32) | ||||
| @@ -306,8 +306,8 @@ auto get_total_drive_space(std::string_view path) | ||||
| #endif // defined(_WIN32) | ||||
|  | ||||
| #if defined(__linux__) | ||||
|     struct statfs64 st{}; | ||||
|     if (statfs64(std::string{path}.c_str(), &st) != 0) { | ||||
|     struct statfs64 u_stat{}; | ||||
|     if (statfs64(std::string{path}.c_str(), &u_stat) != 0) { | ||||
|       throw utils::error::create_exception( | ||||
|           function_name, { | ||||
|                              "failed to get total disk space", | ||||
| @@ -316,12 +316,12 @@ auto get_total_drive_space(std::string_view path) | ||||
|                          }); | ||||
|     } | ||||
|  | ||||
|     return st.f_blocks * static_cast<std::uint64_t>(st.f_bsize); | ||||
|     return u_stat.f_blocks * static_cast<std::uint64_t>(u_stat.f_bsize); | ||||
| #endif // defined(__linux__) | ||||
|  | ||||
| #if defined(__APPLE__) | ||||
|     struct statvfs st{}; | ||||
|     if (statvfs(std::string{path}.c_str(), &st) != 0) { | ||||
|     struct statvfs u_stat{}; | ||||
|     if (statvfs(std::string{path}.c_str(), &u_stat) != 0) { | ||||
|       throw utils::error::create_exception( | ||||
|           function_name, { | ||||
|                              "failed to get total disk space", | ||||
| @@ -330,7 +330,7 @@ auto get_total_drive_space(std::string_view path) | ||||
|                          }); | ||||
|     } | ||||
|  | ||||
|     return st.f_blocks * static_cast<std::uint64_t>(st.f_frsize); | ||||
|     return u_stat.f_blocks * static_cast<std::uint64_t>(u_stat.f_frsize); | ||||
| #endif // defined(__APPLE__) | ||||
|   } catch (const std::exception &e) { | ||||
|     utils::error::handle_exception(function_name, e); | ||||
|   | ||||
| @@ -215,8 +215,8 @@ auto directory::exists() const -> bool { | ||||
| #if defined(_WIN32) | ||||
|   return ::PathIsDirectoryA(path_.c_str()) != 0; | ||||
| #else  // !defined(_WIN32) | ||||
|   struct stat64 st{}; | ||||
|   return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode)); | ||||
|   struct stat64 u_stat{}; | ||||
|   return (stat64(path_.c_str(), &u_stat) == 0 && S_ISDIR(u_stat.st_mode)); | ||||
| #endif // defined(_WIN32) | ||||
|  | ||||
|   return false; | ||||
|   | ||||
| @@ -33,13 +33,13 @@ namespace { | ||||
|   file_size = 0U; | ||||
|  | ||||
| #if defined(_WIN32) | ||||
|   struct _stat64 st{}; | ||||
|   auto res = _stat64(std::string{path}.c_str(), &st); | ||||
|   struct _stat64 u_stat{}; | ||||
|   auto res = _stat64(std::string{path}.c_str(), &u_stat); | ||||
|   if (res != 0) { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   file_size = static_cast<std::uint64_t>(st.st_size); | ||||
|   file_size = static_cast<std::uint64_t>(u_stat.st_size); | ||||
|   return true; | ||||
| #else  // !defined(_WIN32) | ||||
|   std::error_code ec{}; | ||||
| @@ -55,8 +55,9 @@ namespace { | ||||
|   return ((::PathFileExistsA(abs_path.c_str()) != 0) && | ||||
|           (::PathIsDirectoryA(abs_path.c_str()) == 0)); | ||||
| #else  // !defined(_WIN32) | ||||
|   struct stat64 st{}; | ||||
|   return (stat64(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode)); | ||||
|   struct stat64 u_stat{}; | ||||
|   return (stat64(abs_path.c_str(), &u_stat) == 0 && | ||||
|           not S_ISDIR(u_stat.st_mode)); | ||||
| #endif // defined(_WIN32) | ||||
| } | ||||
| } // namespace | ||||
|   | ||||
		Reference in New Issue
	
	Block a user