diff --git a/srclib/libhelper/include/libhelper/lib.hpp b/srclib/libhelper/include/libhelper/lib.hpp index 0f79a6f..2d46958 100644 --- a/srclib/libhelper/include/libhelper/lib.hpp +++ b/srclib/libhelper/include/libhelper/lib.hpp @@ -18,13 +18,13 @@ #define LIBHELPER_LIB_HPP #include +#include #include #include #include #include #include #include -#include #ifndef ONLY_HELPER_MACROS @@ -363,7 +363,7 @@ std::string getLibVersion(); * And returns directory pointer. */ [[nodiscard]] DIR *openAndAddToCloseList(const std::string_view &path, - garbageCollector &collector); + garbageCollector &collector); } // namespace Helper @@ -437,7 +437,7 @@ std::string getLibVersion(); #define LOGF_IF(file, level, condition) \ if (condition) \ Helper::Logger(level, __func__, file, \ - Helper::LoggingProperties::NAME.data(), __FILE__, __LINE__) + Helper::LoggingProperties::NAME.data(), __FILE__, __LINE__) #define LOGN_IF(name, level, condition) \ if (condition) \ Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), \ diff --git a/srclib/libhelper/src/Classes.cpp b/srclib/libhelper/src/Classes.cpp index 4063eb8..8b9d682 100644 --- a/srclib/libhelper/src/Classes.cpp +++ b/srclib/libhelper/src/Classes.cpp @@ -19,10 +19,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -110,10 +110,18 @@ garbageCollector::~garbageCollector() { eraseEntry(file); } -void garbageCollector::delAfterProgress(char *&_ptr) { _ptrs_c.push_back(_ptr); } -void garbageCollector::delAfterProgress(uint8_t *&_ptr) { _ptrs_u.push_back(_ptr); } -void garbageCollector::delFileAfterProgress(const std::string &path) { _files.push_back(path); } -void garbageCollector::closeAfterProgress(const int _fd) { _fds.push_back(_fd); } +void garbageCollector::delAfterProgress(char *&_ptr) { + _ptrs_c.push_back(_ptr); +} +void garbageCollector::delAfterProgress(uint8_t *&_ptr) { + _ptrs_u.push_back(_ptr); +} +void garbageCollector::delFileAfterProgress(const std::string &path) { + _files.push_back(path); +} +void garbageCollector::closeAfterProgress(const int _fd) { + _fds.push_back(_fd); +} void garbageCollector::closeAfterProgress(FILE *&_fp) { _fps.push_back(_fp); } void garbageCollector::closeAfterProgress(DIR *&_dp) { _dps.push_back(_dp); } } // namespace Helper diff --git a/srclib/libhelper/src/FileUtil.cpp b/srclib/libhelper/src/FileUtil.cpp index 9995c58..294ccc9 100644 --- a/srclib/libhelper/src/FileUtil.cpp +++ b/srclib/libhelper/src/FileUtil.cpp @@ -165,8 +165,7 @@ bool eraseDirectoryRecursive(const std::string_view directory) { snprintf(fullpath, sizeof(fullpath), "%s/%s", directory.data(), entry->d_name); - if (lstat(fullpath, &buf) == -1) - return false; + if (lstat(fullpath, &buf) == -1) return false; if (S_ISDIR(buf.st_mode)) { if (!eraseDirectoryRecursive(fullpath)) return false; diff --git a/srclib/libhelper/src/Utilities.cpp b/srclib/libhelper/src/Utilities.cpp index 631cd43..ba12706 100644 --- a/srclib/libhelper/src/Utilities.cpp +++ b/srclib/libhelper/src/Utilities.cpp @@ -156,7 +156,7 @@ std::pair runCommandWithOutput(const std::string_view cmd) { while (fgets(buffer, sizeof(buffer), pipe_holder.get()) != nullptr) output += buffer; - FILE* raw = pipe_holder.release(); + FILE *raw = pipe_holder.release(); const int status = pclose(raw); return {output, (WIFEXITED(status) ? WEXITSTATUS(status) : -1)}; } @@ -207,7 +207,8 @@ FILE *openAndAddToCloseList(const std::string_view &path, return fp; } -DIR *openAndAddToCloseList(const std::string_view &path, garbageCollector &collector) { +DIR *openAndAddToCloseList(const std::string_view &path, + garbageCollector &collector) { DIR *dp = opendir(path.data()); collector.closeAfterProgress(dp); return dp; diff --git a/srclib/libhelper/tests/test.cpp b/srclib/libhelper/tests/test.cpp index 46dc1e2..8fa0f8a 100644 --- a/srclib/libhelper/tests/test.cpp +++ b/srclib/libhelper/tests/test.cpp @@ -53,7 +53,8 @@ int main(int argc, char **argv) { throw Helper::Error("Cannot write \"hello world\" in 'file.txt'"); else std::cout << "file.txt writed." << std::endl; - if (const auto content = Helper::readFile("file.txt");!content) throw Helper::Error("Cannot read 'file.txt'"); + if (const auto content = Helper::readFile("file.txt"); !content) + throw Helper::Error("Cannot read 'file.txt'"); else std::cout << "'file.txt': " << *content << std::endl; std::cout << "Making directory 'dir2': " << std::boolalpha @@ -77,7 +78,8 @@ int main(int argc, char **argv) { std::cout << "Read link of 'file2lnk.txt': " << Helper::readSymlink(test_path("file2lnk.txt")) << std::endl; - if (const auto sha256 = Helper::sha256Of(test_path("file2.txt"));!sha256) throw Helper::Error("Cannot get sha256 of 'file2.txt'"); + if (const auto sha256 = Helper::sha256Of(test_path("file2.txt")); !sha256) + throw Helper::Error("Cannot get sha256 of 'file2.txt'"); else std::cout << "SHA256 of 'file2.txt': " << *sha256 << std::endl; std::cout << "'file2.txt' and 'file2lnk.txt' same? (SHA256): " diff --git a/srclib/libpartition_map/include/libpartition_map/lib.hpp b/srclib/libpartition_map/include/libpartition_map/lib.hpp index 9bae801..dd072b0 100644 --- a/srclib/libpartition_map/include/libpartition_map/lib.hpp +++ b/srclib/libpartition_map/include/libpartition_map/lib.hpp @@ -223,6 +223,11 @@ public: */ [[nodiscard]] bool hasPartition(std::string_view name) const; + /** + * Returns true if the device has dynamic partitions, false otherwise. + */ + [[nodiscard]] bool hasLogicalPartitions() const; + /** * Returns the bool type status of whether the * entered partition name is marked as logical in the diff --git a/srclib/libpartition_map/src/PartitionMap.cpp b/srclib/libpartition_map/src/PartitionMap.cpp index 98ce3f4..f9f684b 100644 --- a/srclib/libpartition_map/src/PartitionMap.cpp +++ b/srclib/libpartition_map/src/PartitionMap.cpp @@ -177,6 +177,14 @@ bool basic_partition_map_builder::hasPartition( return _current_map.find(name); } +bool basic_partition_map_builder::hasLogicalPartitions() const { + _map_build_check(); + for (const auto &[name, props] : _current_map) + if (props.isLogical) return true; + + return false; +} + bool basic_partition_map_builder::isLogical(const std::string_view name) const { _map_build_check(); return _current_map.is_logical(name);