This commit is contained in:
2024-08-23 17:35:34 -05:00
parent fc7a7063c2
commit 8d12ef22b9
4 changed files with 47 additions and 57 deletions

View File

@ -1155,8 +1155,8 @@ auto fuse_drive::setbkuptime_impl(
std::string api_path, const struct timespec *bkuptime) -> api_error {
return check_and_perform(
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
const auto nanos =
bkuptime->tv_nsec + (bkuptime->tv_nsec * NANOS_PER_SECOND);
const auto nanos = bkuptime->tv_nsec +
(bkuptime->tv_nsec * utils::time::NANOS_PER_SECOND);
return provider_.set_item_meta(api_path, META_BACKUP,
std::to_string(nanos));
});
@ -1166,8 +1166,8 @@ auto fuse_drive::setchgtime_impl(std::string api_path,
const struct timespec *chgtime) -> api_error {
return check_and_perform(
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
const auto nanos =
chgtime->tv_nsec + (chgtime->tv_nsec * NANOS_PER_SECOND);
const auto nanos = chgtime->tv_nsec +
(chgtime->tv_nsec * utils::time::NANOS_PER_SECOND);
return provider_.set_item_meta(api_path, META_CHANGED,
std::to_string(nanos));
});
@ -1178,7 +1178,7 @@ auto fuse_drive::setcrtime_impl(std::string api_path,
return check_and_perform(
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
const auto nanos =
crtime->tv_nsec + (crtime->tv_nsec * NANOS_PER_SECOND);
crtime->tv_nsec + (crtime->tv_nsec * utils::time::NANOS_PER_SECOND);
return provider_.set_item_meta(api_path, META_CREATION,
std::to_string(nanos));
});
@ -1310,19 +1310,20 @@ auto fuse_drive::utimens_impl(std::string api_path,
}
meta.clear();
if ((tv == nullptr) || (tv[0U].tv_nsec == UTIME_NOW)) {
meta[META_ACCESSED] = std::to_string(utils::time::get_time_now());
} else if (tv[0U].tv_nsec != UTIME_OMIT) {
const auto val = tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND);
meta[META_ACCESSED] = std::to_string(val);
const auto process_timespec = [&meta](auto *tv, const auto &val,
std::string attr) {
if ((tv == nullptr) || (val.tv_nsec == UTIME_NOW)) {
meta[attr] = std::to_string(utils::time::get_time_now());
} else if (val.tv_nsec != UTIME_OMIT) {
meta[attr] = std::to_string(
val.tv_nsec +
(val.tv_sec * static_cast<std::decay_t<decltype(val.tv_sec)>>(
utils::time::NANOS_PER_SECOND)));
}
};
if ((tv == nullptr) || (tv[1U].tv_nsec == UTIME_NOW)) {
meta[META_MODIFIED] = std::to_string(utils::time::get_time_now());
} else if (tv[1U].tv_nsec != UTIME_OMIT) {
const auto val = tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND);
meta[META_MODIFIED] = std::to_string(val);
}
process_timespec(tv, tv[0U], META_ACCESSED);
process_timespec(tv, tv[1U], META_MODIFIED);
if (not meta.empty()) {
return provider_.set_item_meta(api_path, meta);
@ -1369,8 +1370,7 @@ void fuse_drive::update_accessed_time(const std::string &api_path) {
if (atime_enabled_) {
auto res = provider_.set_item_meta(
api_path, META_ACCESSED,
std::to_string(utils::time::get_time_now()));
api_path, META_ACCESSED, std::to_string(utils::time::get_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to set accessed time");

View File

@ -570,6 +570,7 @@ auto remote_fuse_drive::utimens_impl(std::string api_path,
if (tv != nullptr) {
rtv[0U] = static_cast<remote::file_time>(
tv[0U].tv_nsec + (tv[0U].tv_sec * utils::time::NANOS_PER_SECOND));
rtv[1U] = static_cast<remote::file_time>(
tv[1U].tv_nsec + (tv[1U].tv_sec * utils::time::NANOS_PER_SECOND));
}

View File

@ -1006,25 +1006,18 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
const auto file_path = construct_path(path);
struct timespec tv2[2] = {{0, 0}};
if ((op0 == UTIME_NOW) || (op0 == UTIME_OMIT)) {
tv2[0U].tv_nsec = static_cast<time_t>(op0);
tv2[0U].tv_sec = 0;
const auto process_timespec = [](auto op, const auto &src, auto &dst) {
if ((op == UTIME_NOW) || (op == UTIME_OMIT)) {
dst.tv_nsec = static_cast<time_t>(op);
dst.tv_sec = 0;
} else {
tv2[0U].tv_nsec =
static_cast<time_t>(tv[0U] % utils::time::NANOS_PER_SECOND);
tv2[0U].tv_sec =
static_cast<time_t>(tv[0U] / utils::time::NANOS_PER_SECOND);
dst.tv_nsec = static_cast<time_t>(src % utils::time::NANOS_PER_SECOND);
dst.tv_sec = static_cast<time_t>(src / utils::time::NANOS_PER_SECOND);
}
};
if ((op1 == UTIME_NOW) || (op1 == UTIME_OMIT)) {
tv2[1U].tv_nsec = static_cast<time_t>(op1);
tv2[1U].tv_sec = 0;
} else {
tv2[1U].tv_nsec =
static_cast<time_t>(tv[1U] % utils::time::NANOS_PER_SECOND);
tv2[1U].tv_sec =
static_cast<time_t>(tv[1U] / utils::time::NANOS_PER_SECOND);
}
process_timespec(op0, tv[0U], tv2[0U]);
process_timespec(op1, tv[1U], tv2[1U]);
const auto res =
utimensat(0, file_path.c_str(), &tv2[0U], AT_SYMLINK_NOFOLLOW);

View File

@ -864,26 +864,21 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
FILETIME *access_time_ptr = nullptr;
FILETIME *write_time_ptr = nullptr;
if ((tv[0U] == 0U) || (op0 == UTIME_NOW)) {
const auto now = utils::time::get_time_now();
access_time.dwHighDateTime =
static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
access_time.dwLowDateTime = now & 0xFFFFFFFF;
access_time_ptr = &access_time;
} else if (op0 != UTIME_OMIT) {
access_time = utils::time::unix_time_to_filetime(tv[0U]);
access_time_ptr = &access_time;
}
if ((tv[1U] == 0U) || (op1 == UTIME_NOW)) {
const auto now = utils::time::get_time_now();
write_time.dwHighDateTime = static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
write_time.dwLowDateTime = now & 0xFFFFFFFF;
write_time_ptr = &write_time;
} else if (op1 != UTIME_OMIT) {
write_time = utils::time::unix_time_to_filetime(tv[1U]);
write_time_ptr = &write_time;
const auto proccess_timespec = [](auto op, const auto &src, auto &dst,
auto *&dst_ptr) {
if ((src == 0U) || (op == UTIME_NOW)) {
auto now =
utils::time::unix_error_to_windows(utils::time::get_time_now());
dest.dwHighDateTime = static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
dest.dwLowDateTime = now & 0xFFFFFFFF;
dst_ptr = &dest;
} else if (op != UTIME_OMIT) {
dest = utils::time::unix_time_to_filetime(src);
dst_ptr = &dest;
}
};
proccess_timespec(op0, tv[0U], access_time, access_time_ptr);
proccess_timespec(op1, tv[1U], write_time, write_time_ptr);
errno = EFAULT;
if (::SetFileTime(os_handle, nullptr, access_time_ptr, write_time_ptr) !=
@ -891,6 +886,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
res = 0;
errno = 0;
}
::CloseHandle(os_handle);
}