14 if (!std::filesystem::exists(p) || !std::filesystem::is_directory(p))
20 std::string cmd =
"du -sb " + p.string() +
" | cut -f1 2>&1";
23 FILE* stream = popen(cmd.c_str(),
"r");
26 const int max_size = 256;
27 char readbuf[max_size];
28 if (fgets(readbuf, max_size, stream) != NULL)
30 return atoll(readbuf);
42 return std::filesystem::exists(p) and std::filesystem::is_directory(p);
48 if (!std::filesystem::exists(p))
50 if (createIfNotExistent)
52 std::filesystem::create_directories(p);
55 if (!std::filesystem::is_directory(p))
64 return std::filesystem::exists(p) and std::filesystem::is_regular_file(p);
70 if (!std::filesystem::exists(p) || !std::filesystem::is_regular_file(p))
79 const std::vector<unsigned char>&
data)
81 std::ofstream dataofs;
85 throw error::ArMemError(
"Could not write data to filesystem file '" + p.string() +
86 "'. Skipping this file.");
88 dataofs.write(
reinterpret_cast<const char*
>(
data.data()),
data.size());
92 std::vector<unsigned char>
95 std::ifstream dataifs(path);
96 std::vector<unsigned char> datafilecontent((std::istreambuf_iterator<char>(dataifs)),
97 (std::istreambuf_iterator<char>()));
98 return datafilecontent;
101 std::vector<std::string>
104 std::vector<std::string> ret;
105 for (
const auto& subdir : std::filesystem::directory_iterator(path))
107 std::filesystem::path subdirPath = subdir.path();
108 if (std::filesystem::is_directory(subdirPath))
110 ret.push_back(subdirPath.filename());
113 std::sort(ret.begin(), ret.end());
117 std::vector<std::string>
120 std::vector<std::string> ret;
121 for (
const auto& subdir : std::filesystem::directory_iterator(path))
123 std::filesystem::path subdirPath = subdir.path();
124 if (std::filesystem::is_regular_file(subdirPath))
126 ret.push_back(subdirPath.filename());
129 std::sort(ret.begin(), ret.end());
Base class for all exceptions thrown by the armem library.
void ensureFolderInFilesystemExists(const std::filesystem::path &p, bool createIfNotExistent)
std::vector< std::string > getAllFilesystemDirectories(const std::filesystem::path path)
std::vector< std::string > getAllFilesystemFiles(const std::filesystem::path path)
void ensureFileInFilesystemExists(const std::filesystem::path &p)
std::vector< unsigned char > readDataFromFilesystemFile(const std::filesystem::path path)
bool checkIfFileInFilesystemExists(const std::filesystem::path &p)
void writeDataInFilesystemFile(const std::filesystem::path &p, const std::vector< unsigned char > &data)
bool checkIfFolderInFilesystemExists(const std::filesystem::path &p)
size_t getSizeOfDirectory(const std::filesystem::path &p)