24#include <forward_list>
26#include <fairlogger/Logger.h>
35 for (
const auto&
entry : std::filesystem::directory_iterator(
path)) {
36 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
40 }
catch (std::filesystem::filesystem_error
const& ex) {
41 LOGF(error,
"filesystem problem during DirectoryLoader::load: %s", ex.what());
45 [
marker](
const std::string&
a,
const std::string&
b) {
46 return a.substr(a.find_first_of(marker) + 1) < b.substr(b.find_first_of(marker) + 1);
55 std::map<std::string, std::string> fullPath;
58 for (
const auto&
entry : std::filesystem::directory_iterator(
path)) {
59 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
61 fullPath[
entry.path().filename()] =
entry.path();
64 }
catch (std::filesystem::filesystem_error
const& ex) {
65 LOGF(error,
"filesystem problem during DirectoryLoader::canCreateNextFile: %s", ex.what());
72 [
marker](
const std::string&
a,
const std::string&
b) {
73 return a.substr(a.find_first_of(marker) + 1) > b.substr(b.find_first_of(marker) + 1);
77 unsigned long accumulatedSize = 0L;
78 const std::regex delimiter{
"_"};
80 std::vector<std::string>
c(std::sregex_token_iterator(
file.begin(),
file.end(), delimiter, -1), {});
81 if (std::stoll(
c[1]) < millisec) {
85 accumulatedSize += filesystem::file_size(fullPath[
file]);
86 }
catch (std::filesystem::filesystem_error
const& ex) {
87 LOGF(info,
"problem scanning folder: %s", ex.what());
89 if (accumulatedSize > capacityAllowed) {
101 for (
const auto&
entry : std::filesystem::directory_iterator(
path)) {
102 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
107 }
catch (std::filesystem::filesystem_error
const& ex) {
108 LOGF(error,
"filesystem problem during DirectoryLoader::load: %s", ex.what());
112 [
marker](
const std::string&
a,
const std::string&
b) {
113 return a.substr(a.find_first_of(marker) + 1) < b.substr(b.find_first_of(marker) + 1);
121 std::vector<std::string> folders;
124 folders.push_back(
location.substr(0,
pos) +
"_PHYSICS");
125 folders.push_back(
location.substr(0,
pos) +
"_COSMICS");
126 folders.push_back(
location.substr(0,
pos) +
"_SYNTHETIC");
135 if (filesInFolder == -1) {
138 const auto items = files.size() - std::min(files.size(), filesInFolder);
139 for (
int i = 0;
i < items;
i++) {
140 std::remove((
path +
"/" + files[
i]).c_str());
144template <
typename TP>
147 using namespace std::chrono;
148 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
149 return system_clock::to_time_t(sctp);
152int DirectoryLoader::getNumberOfFiles(
const std::string&
path, std::vector<std::string>& ext)
156 for (
const auto&
entry :
std::filesystem::directory_iterator(
path)) {
157 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
161 }
catch (std::filesystem::filesystem_error
const& ex) {
162 LOGF(error,
"filesystem problem during DirectoryLoader::getNumberOfFiles: %s", ex.what());
166std::string DirectoryLoader::getLatestFile(
const std::string&
path, std::vector<std::string>& ext)
168 std::string oldest_file_name =
"";
169 std::time_t oldest_file_time = LONG_MAX;
170 for (
const auto&
entry :
std::filesystem::directory_iterator(
path)) {
171 if (std::find(ext.begin(), ext.end(),
entry.path().extension()) != ext.end()) {
172 const auto file_time =
entry.last_write_time();
173 if (
const std::time_t
tt =
to_time_t(file_time);
tt < oldest_file_time) {
174 oldest_file_time =
tt;
175 oldest_file_name =
entry.path().filename().string();
179 return oldest_file_name;
185 while (getNumberOfFiles(
path, ext) > remaining) {
186 LOGF(info,
"removing oldest file in folder: %s : %s",
path, getLatestFile(
path, ext));
187 filesystem::remove(
path +
"/" + getLatestFile(
path, ext));
189 }
catch (std::filesystem::filesystem_error
const& ex) {
190 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.
static DeploymentMode deploymentMode()