updates
This commit is contained in:
@ -65,10 +65,11 @@ auto traverse_directory(
|
||||
std::to_string(repertory::utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
struct dirent *de{};
|
||||
struct dirent *de{nullptr};
|
||||
while (res && (de = readdir(root))) {
|
||||
if (de->d_type == DT_DIR) {
|
||||
if ((strcmp(de->d_name, ".") != 0) && (strcmp(de->d_name, "..") != 0)) {
|
||||
if ((std::string_view(de->d_name) != ".") &&
|
||||
(std::string_view(de->d_name) != "..")) {
|
||||
res = directory_action(repertory::utils::file::directory(
|
||||
repertory::utils::path::combine(path, {de->d_name})));
|
||||
}
|
||||
|
@ -179,13 +179,7 @@ auto file::open_or_create_file(std::string_view path,
|
||||
return open_file(abs_path, read_only);
|
||||
}
|
||||
|
||||
void file::close() {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
file_.reset();
|
||||
}
|
||||
void file::close() { file_.reset(); }
|
||||
|
||||
auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
@ -216,29 +210,15 @@ auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file::exists() const -> bool {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
return is_file(path_);
|
||||
}
|
||||
auto file::exists() const -> bool { return is_file(path_); }
|
||||
|
||||
void file::flush() const {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (file_) {
|
||||
fflush(file_.get());
|
||||
}
|
||||
}
|
||||
|
||||
auto file::get_handle() const -> native_handle {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (file_) {
|
||||
#if defined(_WIN32)
|
||||
return reinterpret_cast<native_handle>(
|
||||
@ -251,14 +231,6 @@ auto file::get_handle() const -> native_handle {
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
auto file::get_time(time_types type) const -> std::uint64_t {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
return i_fs_item::get_time(type);
|
||||
}
|
||||
|
||||
auto file::is_symlink() const -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
@ -280,10 +252,6 @@ auto file::move_to(std::string_view path) -> bool {
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
|
||||
auto reopen{false};
|
||||
@ -326,10 +294,6 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (total_read != nullptr) {
|
||||
(*total_read) = 0U;
|
||||
}
|
||||
@ -441,10 +405,6 @@ auto file::sha256() -> std::optional<std::string> {
|
||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
||||
|
||||
auto file::remove() -> bool {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (not exists()) {
|
||||
return true;
|
||||
}
|
||||
@ -466,10 +426,6 @@ auto file::truncate(std::size_t size) -> bool {
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto reopen{false};
|
||||
if (file_) {
|
||||
reopen = true;
|
||||
@ -502,10 +458,6 @@ auto file::write(const unsigned char *data, std::size_t to_write,
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (total_written != nullptr) {
|
||||
(*total_written) = 0U;
|
||||
}
|
||||
@ -556,10 +508,6 @@ auto file::size() const -> std::optional<std::uint64_t> {
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
try {
|
||||
if (file_) {
|
||||
if (fseeko(file_.get(), 0, SEEK_END) == -1) {
|
||||
|
@ -22,18 +22,6 @@
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory::utils::time {
|
||||
#if defined(_WIN32)
|
||||
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
|
||||
auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t {
|
||||
LARGE_INTEGER date{};
|
||||
date.HighPart = static_cast<LONG>(file_time.dwHighDateTime);
|
||||
date.LowPart = file_time.dwLowDateTime;
|
||||
date.QuadPart -= WIN32_TIME_CONVERSION;
|
||||
|
||||
return static_cast<std::uint64_t>(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK;
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
void get_local_time_now(struct tm &local_time) {
|
||||
std::memset(&local_time, 0, sizeof(local_time));
|
||||
|
||||
@ -66,14 +54,10 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char * {
|
||||
return reinterpret_cast<const char *>(s + input.tellg());
|
||||
}
|
||||
|
||||
auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t {
|
||||
return static_cast<std::uint64_t>(time * NANOS_PER_SECOND);
|
||||
}
|
||||
|
||||
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
|
||||
auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
|
||||
auto win_time =
|
||||
(unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
|
||||
auto win_time = unix_time_to_windows_time(unix_time);
|
||||
|
||||
FILETIME file_time{};
|
||||
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
|
||||
file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
|
||||
@ -86,6 +70,6 @@ auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t {
|
||||
}
|
||||
|
||||
auto windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t {
|
||||
return (win_time - WIN32_TIME_CONVERSION) * WIN32_TIME_NANOS_PER_TICK;
|
||||
return (win_time * WIN32_TIME_NANOS_PER_TICK) - WIN32_TIME_CONVERSION;
|
||||
}
|
||||
} // namespace repertory::utils::time
|
||||
|
Reference in New Issue
Block a user