pmt: reformat code.
Some checks failed
Mirror External Repo to GitHub / mirror (push) Has been cancelled

This commit is contained in:
2025-11-24 19:10:40 +03:00
parent f30f733c73
commit caaa0a7009
29 changed files with 747 additions and 632 deletions

View File

@@ -14,24 +14,26 @@
limitations under the License.
*/
#include <fcntl.h>
#include <algorithm>
#include <array>
#include <cerrno>
#include <cstring>
#include <fcntl.h>
#include <filesystem>
#ifndef ANDROID_BUILD
#include <generated/buildInfo.hpp>
#endif
#include <iostream>
#include <libpartition_map/lib.hpp>
#include <linux/fs.h>
#include <memory>
#include <string>
#include <string_view>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
#include <libpartition_map/lib.hpp>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
static constexpr std::array<std::string_view, 3> defaultEntryList = {
@@ -60,7 +62,7 @@ Map_t basic_partition_map_builder::_build_map(std::string_view path,
std::vector<std::filesystem::directory_entry> entries{
std::filesystem::directory_iterator(path),
std::filesystem::directory_iterator()};
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) {
std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) {
return a.path().filename() < b.path().filename();
});
@@ -69,7 +71,7 @@ Map_t basic_partition_map_builder::_build_map(std::string_view path,
<< " is exists but generated vector is empty "
"(std::vector<std::filesystem::directory_entry>)."
<< std::endl;
for (const auto &entry : entries) {
for (const auto& entry : entries) {
if (entry.path().filename() != "by-uuid" &&
std::string(entry.path()).find("com.") == std::string::npos)
map.insert(entry.path().filename().string(), _get_size(entry.path()),
@@ -82,7 +84,7 @@ Map_t basic_partition_map_builder::_build_map(std::string_view path,
return map;
}
void basic_partition_map_builder::_insert_logicals(Map_t &&logicals) {
void basic_partition_map_builder::_insert_logicals(Map_t&& logicals) {
LOGN(MAP, INFO)
<< "merging created logical partition list to this object's variable."
<< std::endl;
@@ -96,7 +98,7 @@ void basic_partition_map_builder::_map_build_check() const {
if (!_map_builded) throw Error("Please build partition map before!");
}
uint64_t basic_partition_map_builder::_get_size(const std::string &path) {
uint64_t basic_partition_map_builder::_get_size(const std::string& path) {
const std::string real = std::filesystem::read_symlink(path);
Helper::garbageCollector collector;
@@ -120,7 +122,7 @@ uint64_t basic_partition_map_builder::_get_size(const std::string &path) {
basic_partition_map_builder::basic_partition_map_builder() {
LOGN(MAP, INFO) << "default constructor called. Starting build." << std::endl;
for (const auto &path : defaultEntryList) {
for (const auto& path : defaultEntryList) {
if (std::filesystem::exists(path)) {
_current_map = _build_map(path);
if (_current_map.empty()) {
@@ -149,8 +151,10 @@ basic_partition_map_builder::basic_partition_map_builder(
if (std::filesystem::exists(path)) {
if (!_is_real_block_dir(path)) return;
_current_map = _build_map(path);
if (_current_map.empty()) _any_generating_error = true;
else _workdir = path;
if (_current_map.empty())
_any_generating_error = true;
else
_workdir = path;
} else
throw Error("Cannot find directory: %s. Cannot build partition map!",
path.data());
@@ -162,7 +166,7 @@ basic_partition_map_builder::basic_partition_map_builder(
}
basic_partition_map_builder::basic_partition_map_builder(
basic_partition_map_builder &&other) noexcept {
basic_partition_map_builder&& other) noexcept {
_current_map = Map_t(std::move(other._current_map));
_workdir = std::move(other._workdir);
_any_generating_error = other._any_generating_error;
@@ -178,7 +182,7 @@ bool basic_partition_map_builder::hasPartition(
bool basic_partition_map_builder::hasLogicalPartitions() const {
_map_build_check();
for (const auto &[name, props] : _current_map)
for (const auto& [name, props] : _current_map)
if (props.isLogical) return true;
return false;
@@ -205,7 +209,8 @@ bool basic_partition_map_builder::readDirectory(const std::string_view path) {
if (_current_map.empty()) {
_any_generating_error = true;
return false;
} else _workdir = path;
} else
_workdir = path;
} else
throw Error("Cannot find directory: %s. Cannot build partition map!",
path.data());
@@ -220,7 +225,7 @@ bool basic_partition_map_builder::readDefaultDirectories() {
_map_builded = false;
LOGN(MAP, INFO) << "read default directories request." << std::endl;
for (const auto &path : defaultEntryList) {
for (const auto& path : defaultEntryList) {
if (std::filesystem::exists(path)) {
_current_map = _build_map(path);
if (_current_map.empty()) {
@@ -244,48 +249,49 @@ bool basic_partition_map_builder::readDefaultDirectories() {
}
bool basic_partition_map_builder::copyPartitionsToVector(
std::vector<std::string> &vec) const {
std::vector<std::string>& vec) const {
if (_current_map.empty()) {
LOGN(MAP, ERROR) << "Current map is empty.";
return false;
}
vec.clear();
for (const auto &[name, props] : _current_map)
vec.push_back(name);
for (const auto& [name, props] : _current_map) vec.push_back(name);
return true;
}
bool basic_partition_map_builder::copyLogicalPartitionsToVector(
std::vector<std::string> &vec) const {
std::vector<std::string>& vec) const {
if (_current_map.empty()) {
LOGN(MAP, ERROR) << "Current map is empty.";
return false;
}
std::vector<std::string> vec2;
for (const auto &[name, props] : _current_map)
for (const auto& [name, props] : _current_map)
if (props.isLogical) vec2.push_back(name);
if (vec2.empty()) {
LOGN(MAP, ERROR) << "Cannot find logical partitions in current map.";
return false;
} else vec = vec2;
} else
vec = vec2;
return true;
}
bool basic_partition_map_builder::copyPhysicalPartitionsToVector(
std::vector<std::string> &vec) const {
std::vector<std::string>& vec) const {
if (_current_map.empty()) {
LOGN(MAP, ERROR) << "Current map is empty.";
return false;
}
std::vector<std::string> vec2;
for (const auto &[name, props] : _current_map)
for (const auto& [name, props] : _current_map)
if (!props.isLogical) vec2.push_back(name);
if (vec2.empty()) {
LOGN(MAP, ERROR) << "Cannot find physical partitions in current map.";
return false;
} else vec = vec2;
} else
vec = vec2;
return true;
}
@@ -295,12 +301,12 @@ bool basic_partition_map_builder::empty() const {
}
bool basic_partition_map_builder::doForAllPartitions(
const std::function<bool(std::string, BasicInf)> &func) const {
const std::function<bool(std::string, BasicInf)>& func) const {
_map_build_check();
bool err = false;
LOGN(MAP, INFO) << "Doing input function for all partitions." << std::endl;
for (const auto &[name, props] : _current_map) {
for (const auto& [name, props] : _current_map) {
if (func(name, {props.size, props.isLogical}))
LOGN(MAP, INFO) << "Done progress for " << name << " partition."
<< std::endl;
@@ -315,13 +321,13 @@ bool basic_partition_map_builder::doForAllPartitions(
}
bool basic_partition_map_builder::doForPhysicalPartitions(
const std::function<bool(std::string, BasicInf)> &func) const {
const std::function<bool(std::string, BasicInf)>& func) const {
_map_build_check();
bool err = false;
LOGN(MAP, INFO) << "Doing input function for physical partitions."
<< std::endl;
for (const auto &[name, props] : _current_map) {
for (const auto& [name, props] : _current_map) {
if (props.isLogical) continue;
if (func(name, {props.size, props.isLogical}))
LOGN(MAP, INFO) << "Done progress for " << name << " partition."
@@ -337,13 +343,13 @@ bool basic_partition_map_builder::doForPhysicalPartitions(
}
bool basic_partition_map_builder::doForLogicalPartitions(
const std::function<bool(std::string, BasicInf)> &func) const {
const std::function<bool(std::string, BasicInf)>& func) const {
_map_build_check();
bool err = false;
LOGN(MAP, INFO) << "Doing input function for logical partitions."
<< std::endl;
for (const auto &[name, props] : _current_map) {
for (const auto& [name, props] : _current_map) {
if (!props.isLogical) continue;
if (func(name, {props.size, props.isLogical}))
LOGN(MAP, INFO) << "Done progress for " << name << " partition."
@@ -359,14 +365,14 @@ bool basic_partition_map_builder::doForLogicalPartitions(
}
bool basic_partition_map_builder::doForPartitionList(
const std::vector<std::string> &partitions,
const std::function<bool(std::string, BasicInf)> &func) const {
const std::vector<std::string>& partitions,
const std::function<bool(std::string, BasicInf)>& func) const {
_map_build_check();
bool err = false;
LOGN(MAP, INFO) << "Doing input function for input partition list."
<< std::endl;
for (const auto &partition : partitions) {
for (const auto& partition : partitions) {
if (!hasPartition(partition))
throw Error("Couldn't find partition: %s", partition.data());
if (!func(partition, _current_map[partition])) {
@@ -379,19 +385,19 @@ bool basic_partition_map_builder::doForPartitionList(
return err;
}
uint64_t
basic_partition_map_builder::sizeOf(const std::string_view name) const {
uint64_t basic_partition_map_builder::sizeOf(
const std::string_view name) const {
_map_build_check();
return _current_map.get_size(name);
}
bool operator==(const basic_partition_map_builder &lhs,
const basic_partition_map_builder &rhs) {
bool operator==(const basic_partition_map_builder& lhs,
const basic_partition_map_builder& rhs) {
return lhs._current_map == rhs._current_map;
}
bool operator!=(const basic_partition_map_builder &lhs,
const basic_partition_map_builder &rhs) {
bool operator!=(const basic_partition_map_builder& lhs,
const basic_partition_map_builder& rhs) {
return !(lhs == rhs);
}
@@ -409,9 +415,9 @@ bool basic_partition_map_builder::operator()(const std::string_view path) {
return readDirectory(path);
}
Map_t &basic_partition_map_builder::operator*() { return _current_map; }
Map_t& basic_partition_map_builder::operator*() { return _current_map; }
const Map_t &basic_partition_map_builder::operator*() const {
const Map_t& basic_partition_map_builder::operator*() const {
return _current_map;
}
@@ -419,8 +425,8 @@ Info basic_partition_map_builder::operator[](const int index) const {
return _current_map[index];
}
BasicInf
basic_partition_map_builder::operator[](const std::string_view &name) const {
BasicInf basic_partition_map_builder::operator[](
const std::string_view& name) const {
return _current_map[name];
}
@@ -435,4 +441,4 @@ basic_partition_map_builder::operator int() const {
basic_partition_map_builder::operator std::string() const { return _workdir; }
std::string getLibVersion() { MKVERSION("libpartition_map"); }
} // namespace PartitionMap
} // namespace PartitionMap