pmt: reformat code, etc.
This commit is contained in:
@@ -18,13 +18,13 @@
|
|||||||
#define LIBHELPER_LIB_HPP
|
#define LIBHELPER_LIB_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <dirent.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#ifndef ONLY_HELPER_MACROS
|
#ifndef ONLY_HELPER_MACROS
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <dirent.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <dirent.h>
|
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -110,10 +110,18 @@ garbageCollector::~garbageCollector() {
|
|||||||
eraseEntry(file);
|
eraseEntry(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCollector::delAfterProgress(char *&_ptr) { _ptrs_c.push_back(_ptr); }
|
void garbageCollector::delAfterProgress(char *&_ptr) {
|
||||||
void garbageCollector::delAfterProgress(uint8_t *&_ptr) { _ptrs_u.push_back(_ptr); }
|
_ptrs_c.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(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(FILE *&_fp) { _fps.push_back(_fp); }
|
||||||
void garbageCollector::closeAfterProgress(DIR *&_dp) { _dps.push_back(_dp); }
|
void garbageCollector::closeAfterProgress(DIR *&_dp) { _dps.push_back(_dp); }
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
|
|||||||
@@ -165,8 +165,7 @@ bool eraseDirectoryRecursive(const std::string_view directory) {
|
|||||||
snprintf(fullpath, sizeof(fullpath), "%s/%s", directory.data(),
|
snprintf(fullpath, sizeof(fullpath), "%s/%s", directory.data(),
|
||||||
entry->d_name);
|
entry->d_name);
|
||||||
|
|
||||||
if (lstat(fullpath, &buf) == -1)
|
if (lstat(fullpath, &buf) == -1) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (S_ISDIR(buf.st_mode)) {
|
if (S_ISDIR(buf.st_mode)) {
|
||||||
if (!eraseDirectoryRecursive(fullpath)) return false;
|
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)
|
while (fgets(buffer, sizeof(buffer), pipe_holder.get()) != nullptr)
|
||||||
output += buffer;
|
output += buffer;
|
||||||
|
|
||||||
FILE* raw = pipe_holder.release();
|
FILE *raw = pipe_holder.release();
|
||||||
const int status = pclose(raw);
|
const int status = pclose(raw);
|
||||||
return {output, (WIFEXITED(status) ? WEXITSTATUS(status) : -1)};
|
return {output, (WIFEXITED(status) ? WEXITSTATUS(status) : -1)};
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,8 @@ FILE *openAndAddToCloseList(const std::string_view &path,
|
|||||||
return fp;
|
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());
|
DIR *dp = opendir(path.data());
|
||||||
collector.closeAfterProgress(dp);
|
collector.closeAfterProgress(dp);
|
||||||
return dp;
|
return dp;
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ int main(int argc, char **argv) {
|
|||||||
throw Helper::Error("Cannot write \"hello world\" in 'file.txt'");
|
throw Helper::Error("Cannot write \"hello world\" in 'file.txt'");
|
||||||
else std::cout << "file.txt writed." << std::endl;
|
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;
|
else std::cout << "'file.txt': " << *content << std::endl;
|
||||||
|
|
||||||
std::cout << "Making directory 'dir2': " << std::boolalpha
|
std::cout << "Making directory 'dir2': " << std::boolalpha
|
||||||
@@ -77,7 +78,8 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << "Read link of 'file2lnk.txt': "
|
std::cout << "Read link of 'file2lnk.txt': "
|
||||||
<< Helper::readSymlink(test_path("file2lnk.txt")) << std::endl;
|
<< 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;
|
else std::cout << "SHA256 of 'file2.txt': " << *sha256 << std::endl;
|
||||||
|
|
||||||
std::cout << "'file2.txt' and 'file2lnk.txt' same? (SHA256): "
|
std::cout << "'file2.txt' and 'file2lnk.txt' same? (SHA256): "
|
||||||
|
|||||||
@@ -223,6 +223,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] bool hasPartition(std::string_view name) const;
|
[[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
|
* Returns the bool type status of whether the
|
||||||
* entered partition name is marked as logical in 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);
|
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 {
|
bool basic_partition_map_builder::isLogical(const std::string_view name) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
return _current_map.is_logical(name);
|
return _current_map.is_logical(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user