pmt: reformat code, etc.
This commit is contained in:
@@ -18,13 +18,13 @@
|
||||
#define LIBHELPER_LIB_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <dirent.h>
|
||||
#include <exception>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <dirent.h>
|
||||
|
||||
#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(), \
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <exception>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <dirent.h>
|
||||
#include <libhelper/lib.hpp>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -156,7 +156,7 @@ std::pair<std::string, int> 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;
|
||||
|
||||
@@ -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): "
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user