10 namespace filesystem::util
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");
25 const int max_size = 256;
26 char readbuf[max_size];
27 if (fgets(readbuf, max_size, stream) != NULL)
29 return atoll(readbuf);
40 return std::filesystem::exists(p) and std::filesystem::is_directory(p);
45 if (!std::filesystem::exists(p))
47 if (createIfNotExistent)
49 std::filesystem::create_directories(p);
52 if (!std::filesystem::is_directory(p))
60 return std::filesystem::exists(p) and std::filesystem::is_regular_file(p);
65 if (!std::filesystem::exists(p) || !std::filesystem::is_regular_file(p))
74 std::ofstream dataofs;
78 throw error::ArMemError(
"Could not write data to filesystem file '" + p.string() +
"'. Skipping this file.");
80 dataofs.write(
reinterpret_cast<const char*
>(
data.data()),
data.size());
86 std::ifstream dataifs(path);
87 std::vector<unsigned char> datafilecontent((std::istreambuf_iterator<char>(dataifs)), (std::istreambuf_iterator<char>()));
88 return datafilecontent;
93 std::vector<std::string>
ret;
94 for (
const auto& subdir : std::filesystem::directory_iterator(path))
96 std::filesystem::path subdirPath = subdir.path();
97 if (std::filesystem::is_directory(subdirPath))
99 ret.push_back(subdirPath.filename());
102 std::sort(
ret.begin(),
ret.end());
108 std::vector<std::string>
ret;
109 for (
const auto& subdir : std::filesystem::directory_iterator(path))
111 std::filesystem::path subdirPath = subdir.path();
112 if (std::filesystem::is_regular_file(subdirPath))
114 ret.push_back(subdirPath.filename());
117 std::sort(
ret.begin(),
ret.end());