22#include <forward_list>
24#include <fairlogger/Logger.h>
33 for (
const auto&
entry : std::filesystem::directory_iterator(
path)) {
34 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
38 }
catch (std::filesystem::filesystem_error
const& ex) {
39 LOGF(error,
"filesystem problem during DirectoryLoader::load: %s", ex.what());
44 [
marker](
const std::string&
a,
const std::string&
b) {
45 return a.substr(a.find_first_of(marker) + 1) < b.substr(b.find_first_of(marker) + 1);
54 std::map<std::string, std::string> fullPath;
57 for (
const auto&
entry : std::filesystem::directory_iterator(
path)) {
58 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
60 fullPath[
entry.path().filename()] =
entry.path();
63 }
catch (std::filesystem::filesystem_error
const& ex) {
64 LOGF(error,
"filesystem problem during DirectoryLoader::canCreateNextFile: %s", ex.what());
71 [
marker](
const std::string&
a,
const std::string&
b) {
72 return a.substr(a.find_first_of(marker) + 1) > b.substr(b.find_first_of(marker) + 1);
74 unsigned long accumulatedSize = 0L;
75 const std::regex delimiter{
"_"};
77 std::vector<std::string>
c(std::sregex_token_iterator(
file.begin(),
file.end(), delimiter, -1), {});
78 if (std::stoll(
c[1]) < millisec) {
82 accumulatedSize += filesystem::file_size(fullPath[
file]);
83 }
catch (std::filesystem::filesystem_error
const& ex) {
84 LOGF(info,
"problem scanning folder: %s", ex.what());
86 if (accumulatedSize > capacityAllowed) {
98 for (
const auto&
entry : std::filesystem::directory_iterator(
path)) {
99 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
104 }
catch (std::filesystem::filesystem_error
const& ex) {
105 LOGF(error,
"filesystem problem during DirectoryLoader::load: %s", ex.what());
110 [
marker](
const std::string&
a,
const std::string&
b) {
111 return a.substr(a.find_first_of(marker) + 1) < b.substr(b.find_first_of(marker) + 1);
120 std::vector<std::string> folders;
121 folders.push_back(
location.substr(0,
pos) +
"_PHYSICS");
122 folders.push_back(
location.substr(0,
pos) +
"_COSMICS");
123 folders.push_back(
location.substr(0,
pos) +
"_SYNTHETIC");
129 if (filesInFolder == -1) {
132 const auto items = files.size() - std::min(files.size(), filesInFolder);
133 for (
int i = 0;
i < items;
i++) {
134 std::remove((
path +
"/" + files[
i]).c_str());
138template <
typename TP>
141 using namespace std::chrono;
142 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
143 return system_clock::to_time_t(sctp);
146int DirectoryLoader::getNumberOfFiles(
const std::string&
path, std::vector<std::string>& ext)
150 for (
const auto&
entry :
std::filesystem::directory_iterator(
path)) {
151 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
155 }
catch (std::filesystem::filesystem_error
const& ex) {
156 LOGF(error,
"filesystem problem during DirectoryLoader::getNumberOfFiles: %s", ex.what());
160std::string DirectoryLoader::getLatestFile(
const std::string&
path, std::vector<std::string>& ext)
162 std::string oldest_file_name =
"";
163 std::time_t oldest_file_time = LONG_MAX;
164 for (
const auto&
entry :
std::filesystem::directory_iterator(
path)) {
165 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
166 const auto file_time =
entry.last_write_time();
167 if (
const std::time_t
tt =
to_time_t(file_time);
tt < oldest_file_time) {
168 oldest_file_time =
tt;
169 oldest_file_name =
entry.path().filename().string();
173 return oldest_file_name;
179 while (getNumberOfFiles(
path, ext) > remaining) {
180 LOGF(info,
"removing oldest file in folder: %s : %s",
path, getLatestFile(
path, ext));
181 filesystem::remove(
path +
"/" + getLatestFile(
path, ext));
183 }
catch (std::filesystem::filesystem_error
const& ex) {
184 LOGF(error,
"filesystem problem during DirectoryLoader::removeOldestFiles: %s", ex.what());
std::time_t to_time_t(TP tp)
Loading content of the Folder and returning sorted.
static void removeOldestFiles(const std::string &path, std::vector< std::string > &ext, int remaining)
static bool canCreateNextFile(const std::vector< std::string > &paths, const std::string &marker, const std::vector< std::string > &ext, long long millisec, long capacityAllowed)
static void reduceNumberOfFiles(const std::string &path, const std::deque< std::string > &files, std::size_t filesInFolder)
static std::vector< std::string > allFolders(const std::string &location)
static std::deque< std::string > load(const std::string &path, const std::string &marker, const std::vector< std::string > &ext)
GLboolean GLboolean GLboolean b
GLsizei const GLuint * paths
GLsizei const GLchar *const * path
GLboolean GLboolean GLboolean GLboolean a
Defining DataPointCompositeObject explicitly as copiable.