fix default meta handling

This commit is contained in:
2025-09-25 19:58:14 -05:00
parent 1fe61f2d5e
commit 99800ec34e
6 changed files with 59 additions and 38 deletions

View File

@@ -119,7 +119,7 @@ void remote_server::populate_file_info(const std::string &api_path,
utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) * utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT; WINFSP_ALLOCATION_UNIT;
r_info.ChangeTime = utils::time::unix_time_to_windows_time( r_info.ChangeTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_MODIFIED]))); utils::string::to_uint64(empty_as_zero(meta[META_CHANGED])));
r_info.CreationTime = utils::time::unix_time_to_windows_time( r_info.CreationTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_CREATION]))); utils::string::to_uint64(empty_as_zero(meta[META_CREATION])));
r_info.EaSize = 0; r_info.EaSize = 0;
@@ -1720,26 +1720,26 @@ auto remote_server::update_to_windows_format(const std::string &root_api_path,
item[JSON_META] = meta; item[JSON_META] = meta;
} }
item[JSON_META][META_ACCESSED] = std::to_string(
utils::string::to_uint64(empty_as_zero(item[JSON_META][META_ACCESSED])));
item[JSON_META][META_CREATION] = std::to_string(
utils::string::to_uint64(empty_as_zero(item[JSON_META][META_CREATION])));
item[JSON_META][META_MODIFIED] = std::to_string(
utils::string::to_uint64(empty_as_zero(item[JSON_META][META_MODIFIED])));
auto update_meta{false}; auto update_meta{false};
if (item[JSON_META][META_WRITTEN].empty() || auto default_value = std::to_string(utils::time::get_time_now());
(item[JSON_META][META_WRITTEN].get<std::string>() == "0") || const auto ensure_set = [&item, &update_meta](
(item[JSON_META][META_WRITTEN].get<std::string>() == const std::string &name,
std::to_string(utils::time::WIN32_TIME_CONVERSION))) { const std::string &default_value, bool as_time) {
item[JSON_META][META_WRITTEN] = if (not item[JSON_META].contains(name) || item[JSON_META][name].empty() ||
item[JSON_META][META_MODIFIED].get<std::string>(); (as_time && (item[JSON_META][name].template get<std::string>() == "0" ||
update_meta = true; item[JSON_META][name].template get<std::string>() ==
} std::to_string(utils::time::WIN32_TIME_CONVERSION)))) {
item[JSON_META][name] = default_value;
update_meta = true;
}
};
if (item[JSON_META][META_ATTRIBUTES].empty()) { ensure_set(META_ACCESSED, default_value, true);
item[JSON_META][META_ATTRIBUTES] = "0"; ensure_set(META_CREATION, default_value, true);
} ensure_set(META_MODIFIED, default_value, true);
ensure_set(META_CHANGED, item[JSON_META][META_MODIFIED], true);
ensure_set(META_WRITTEN, item[JSON_META][META_MODIFIED], true);
ensure_set(META_ATTRIBUTES, "0", false);
auto attributes = utils::string::to_uint32( auto attributes = utils::string::to_uint32(
item[JSON_META][META_ATTRIBUTES].get<std::string>()); item[JSON_META][META_ATTRIBUTES].get<std::string>());

View File

@@ -216,14 +216,13 @@ auto create_meta_attributes(std::uint64_t accessed_date,
std::uint32_t osx_flags, std::uint64_t size, std::uint32_t osx_flags, std::uint64_t size,
const std::string &source_path, std::uint32_t uid, const std::string &source_path, std::uint32_t uid,
std::uint64_t written_date) -> api_meta_map { std::uint64_t written_date) -> api_meta_map {
return { api_meta_map meta{
{META_ACCESSED, std::to_string(accessed_date)}, {META_ACCESSED, std::to_string(accessed_date)},
{META_ATTRIBUTES, std::to_string(attributes)}, {META_ATTRIBUTES, std::to_string(attributes)},
{META_CHANGED, std::to_string(changed_date)}, {META_CHANGED, std::to_string(changed_date)},
{META_CREATION, std::to_string(creation_date)}, {META_CREATION, std::to_string(creation_date)},
{META_DIRECTORY, utils::string::from_bool(directory)}, {META_DIRECTORY, utils::string::from_bool(directory)},
{META_GID, std::to_string(gid)}, {META_GID, std::to_string(gid)},
{META_KDF, ""},
{META_KEY, key}, {META_KEY, key},
{META_MODE, std::to_string(mode)}, {META_MODE, std::to_string(mode)},
{META_MODIFIED, std::to_string(modified_date)}, {META_MODIFIED, std::to_string(modified_date)},
@@ -234,6 +233,14 @@ auto create_meta_attributes(std::uint64_t accessed_date,
{META_UID, std::to_string(uid)}, {META_UID, std::to_string(uid)},
{META_WRITTEN, std::to_string(written_date)}, {META_WRITTEN, std::to_string(written_date)},
}; };
for (const auto &name : META_USED_NAMES) {
if (not meta.contains(name)) {
meta[name] = "";
}
}
return meta;
} }
auto provider_meta_creator(bool directory, const api_file &file) auto provider_meta_creator(bool directory, const api_file &file)

View File

@@ -198,14 +198,13 @@ auto create_meta_attributes(std::uint64_t accessed_date,
std::uint32_t osx_flags, std::uint64_t size, std::uint32_t osx_flags, std::uint64_t size,
const std::string &source_path, std::uint32_t uid, const std::string &source_path, std::uint32_t uid,
std::uint64_t written_date) -> api_meta_map { std::uint64_t written_date) -> api_meta_map {
return { api_meta_map meta{
{META_ACCESSED, std::to_string(accessed_date)}, {META_ACCESSED, std::to_string(accessed_date)},
{META_ATTRIBUTES, std::to_string(attributes)}, {META_ATTRIBUTES, std::to_string(attributes)},
{META_CHANGED, std::to_string(changed_date)}, {META_CHANGED, std::to_string(changed_date)},
{META_CREATION, std::to_string(creation_date)}, {META_CREATION, std::to_string(creation_date)},
{META_DIRECTORY, utils::string::from_bool(directory)}, {META_DIRECTORY, utils::string::from_bool(directory)},
{META_GID, std::to_string(gid)}, {META_GID, std::to_string(gid)},
{META_KDF, ""},
{META_KEY, key}, {META_KEY, key},
{META_MODE, std::to_string(mode)}, {META_MODE, std::to_string(mode)},
{META_MODIFIED, std::to_string(modified_date)}, {META_MODIFIED, std::to_string(modified_date)},
@@ -216,6 +215,14 @@ auto create_meta_attributes(std::uint64_t accessed_date,
{META_UID, std::to_string(uid)}, {META_UID, std::to_string(uid)},
{META_WRITTEN, std::to_string(written_date)}, {META_WRITTEN, std::to_string(written_date)},
}; };
for (const auto &name : META_USED_NAMES) {
if (not meta.contains(name)) {
meta[name] = "";
}
}
return meta;
} }
auto provider_meta_creator(bool directory, const api_file &file) auto provider_meta_creator(bool directory, const api_file &file)

View File

@@ -95,15 +95,19 @@ auto base_provider::create_api_file(std::string path, std::uint64_t size,
current_size = size; current_size = size;
} }
api_file file{}; auto api_path = utils::path::create_api_path(path);
file.api_path = utils::path::create_api_path(path); api_file file{
file.api_parent = utils::path::get_parent_api_path(file.api_path); .api_path = api_path,
file.accessed_date = utils::string::to_uint64(meta[META_ACCESSED]); .api_parent = utils::path::get_parent_api_path(api_path),
file.changed_date = utils::string::to_uint64(meta[META_CHANGED]); .accessed_date = utils::string::to_uint64(meta[META_ACCESSED]),
file.creation_date = utils::string::to_uint64(meta[META_CREATION]); .changed_date = utils::string::to_uint64(meta[META_CHANGED]),
file.file_size = current_size; .creation_date = utils::string::to_uint64(meta[META_CREATION]),
file.modified_date = utils::string::to_uint64(meta[META_MODIFIED]); .file_size = current_size,
file.written_date = utils::string::to_uint64(meta[META_WRITTEN]); .key = "",
.modified_date = utils::string::to_uint64(meta[META_MODIFIED]),
.source_path = "",
.written_date = utils::string::to_uint64(meta[META_WRITTEN]),
};
return file; return file;
} }

View File

@@ -93,6 +93,11 @@ auto get_accessed_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
utils::string::to_uint64(meta.at(META_ACCESSED))); utils::string::to_uint64(meta.at(META_ACCESSED)));
} }
auto get_creation_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_CREATION)));
}
auto get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::time::unix_time_to_windows_time( return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_CHANGED))); utils::string::to_uint64(meta.at(META_CHANGED)));

View File

@@ -221,7 +221,7 @@ protected:
static void create_directory(const std::string &api_path) { static void create_directory(const std::string &api_path) {
auto date = utils::time::get_time_now(); auto date = utils::time::get_time_now();
auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, true, auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, true,
getgid(), "", 0700, date + 3U, 2U, 3U, getgid(), "", 0700, date + 3U, 2U, 0U,
api_path + "_src", getuid(), date + 4U); api_path + "_src", getuid(), date + 4U);
EXPECT_EQ(api_error::success, provider->create_directory(api_path, meta)); EXPECT_EQ(api_error::success, provider->create_directory(api_path, meta));
@@ -241,8 +241,7 @@ protected:
static_cast<gid_t>(utils::string::to_uint32(meta2[META_GID]))); static_cast<gid_t>(utils::string::to_uint32(meta2[META_GID])));
EXPECT_EQ(std::uint32_t(0700), utils::string::to_uint32(meta2[META_MODE])); EXPECT_EQ(std::uint32_t(0700), utils::string::to_uint32(meta2[META_MODE]));
EXPECT_EQ(date + 3U, utils::string::to_uint64(meta2[META_MODIFIED])); EXPECT_EQ(date + 3U, utils::string::to_uint64(meta2[META_MODIFIED]));
EXPECT_EQ(2U, utils::string::to_uint64(meta2[META_BACKUP])); EXPECT_EQ(2U, utils::string::to_uint64(meta2[META_OSXFLAGS]));
EXPECT_EQ(3U, utils::string::to_uint64(meta2[META_OSXFLAGS]));
EXPECT_FALSE(utils::string::to_bool(meta2[META_PINNED])); EXPECT_FALSE(utils::string::to_bool(meta2[META_PINNED]));
EXPECT_EQ(std::uint64_t(0U), utils::string::to_uint64(meta2[META_SIZE])); EXPECT_EQ(std::uint64_t(0U), utils::string::to_uint64(meta2[META_SIZE]));
EXPECT_EQ(getuid(), EXPECT_EQ(getuid(),
@@ -255,7 +254,7 @@ protected:
auto date = utils::time::get_time_now(); auto date = utils::time::get_time_now();
auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, false, auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, false,
getgid(), "", 0700, date + 3U, 2U, 3U, getgid(), "", 0700, date + 3U, 2U, 0U,
source_path, getuid(), date + 4U); source_path, getuid(), date + 4U);
EXPECT_EQ(api_error::success, provider->create_file(api_path, meta)); EXPECT_EQ(api_error::success, provider->create_file(api_path, meta));
@@ -277,8 +276,7 @@ protected:
static_cast<gid_t>(utils::string::to_uint32(meta2[META_GID]))); static_cast<gid_t>(utils::string::to_uint32(meta2[META_GID])));
EXPECT_EQ(std::uint32_t(0700), utils::string::to_uint32(meta2[META_MODE])); EXPECT_EQ(std::uint32_t(0700), utils::string::to_uint32(meta2[META_MODE]));
EXPECT_EQ(date + 3U, utils::string::to_uint64(meta2[META_MODIFIED])); EXPECT_EQ(date + 3U, utils::string::to_uint64(meta2[META_MODIFIED]));
EXPECT_EQ(2U, utils::string::to_uint64(meta2[META_BACKUP])); EXPECT_EQ(2U, utils::string::to_uint64(meta2[META_OSXFLAGS]));
EXPECT_EQ(3U, utils::string::to_uint64(meta2[META_OSXFLAGS]));
EXPECT_FALSE(utils::string::to_bool(meta2[META_PINNED])); EXPECT_FALSE(utils::string::to_bool(meta2[META_PINNED]));
EXPECT_EQ(std::uint64_t(0U), utils::string::to_uint64(meta2[META_SIZE])); EXPECT_EQ(std::uint64_t(0U), utils::string::to_uint64(meta2[META_SIZE]));
EXPECT_STREQ(source_path.c_str(), meta2[META_SOURCE].c_str()); EXPECT_STREQ(source_path.c_str(), meta2[META_SOURCE].c_str());