🚧 utils: fix rootfs of partition scheme from predefined config

This commit is contained in:
Vladislav Nepogodin 2024-07-27 03:50:34 +04:00
parent c322aba3ff
commit c6dfd57f66
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9

View File

@ -1777,6 +1777,15 @@ bool parse_config() noexcept {
return false; return false;
} }
if (doc.HasMember("fs_name")) {
assert(doc["fs_name"].IsString());
config_data["FILESYSTEM_NAME"] = std::string{doc["fs_name"].GetString()};
} else if (headless_mode) {
fmt::print(stderr, "'fs_name' field is required in HEADLESS mode!\n");
return false;
}
auto& root_fstype = std::get<std::string>(config_data["FILESYSTEM_NAME"]);
if (doc.HasMember("partitions")) { if (doc.HasMember("partitions")) {
assert(doc["partitions"].IsArray()); assert(doc["partitions"].IsArray());
@ -1799,12 +1808,12 @@ bool parse_config() noexcept {
fmt::print(stderr, "partition type '{}' is invalid! Valid types: {}.\n", part_type, valid_types); fmt::print(stderr, "partition type '{}' is invalid! Valid types: {}.\n", part_type, valid_types);
return false; return false;
} }
if (!partition_map.HasMember("fs_name") && part_type == "additional"sv) { if (!partition_map.HasMember("fs_name") && (part_type != "root"sv || (root_fstype.empty() && part_type == "root"sv))) {
fmt::print(stderr, "required field 'fs_name' is missing for partition type '{}'!\n", part_type); fmt::print(stderr, "required field 'fs_name' is missing for partition type '{}'!\n", part_type);
return false; return false;
} }
std::string part_fs_name{"-"}; std::string part_fs_name{root_fstype};
if (partition_map.HasMember("fs_name")) { if (partition_map.HasMember("fs_name")) {
assert(partition_map["fs_name"].IsString()); assert(partition_map["fs_name"].IsString());
part_fs_name = partition_map["fs_name"].GetString(); part_fs_name = partition_map["fs_name"].GetString();
@ -1821,14 +1830,6 @@ bool parse_config() noexcept {
return false; return false;
} }
if (doc.HasMember("fs_name")) {
assert(doc["fs_name"].IsString());
config_data["FILESYSTEM_NAME"] = std::string{doc["fs_name"].GetString()};
} else if (headless_mode) {
fmt::print(stderr, "'fs_name' field is required in HEADLESS mode!\n");
return false;
}
if (doc.HasMember("mount_opts")) { if (doc.HasMember("mount_opts")) {
assert(doc["mount_opts"].IsString()); assert(doc["mount_opts"].IsString());
config_data["MOUNT_OPTS"] = std::string{doc["mount_opts"].GetString()}; config_data["MOUNT_OPTS"] = std::string{doc["mount_opts"].GetString()};