Added collector
This commit is contained in:
parent
c88ea6a9a0
commit
1e534a6c67
2 changed files with 81 additions and 1 deletions
56
collector.hpp
Normal file
56
collector.hpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* @file collector.hpp
|
||||
* Collects file events and acts upon them
|
||||
*
|
||||
* @author Tobias Schmidl
|
||||
* @copyright Copyright © 2022, Tobias Schmidl
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "monitor.hpp"
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
|
||||
// for system()
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
constexpr const char* FILTER = "^Core\\.[^.][^.]*\\..*\\.lz4";
|
||||
|
||||
namespace collector::collector {
|
||||
|
||||
class Collector
|
||||
{
|
||||
monitor::Monitor _monitor;
|
||||
std::filesystem::path _target_file;
|
||||
|
||||
public:
|
||||
Collector(boost::asio::io_service& service,
|
||||
std::filesystem::path&& root_path,
|
||||
std::filesystem::path&& target_file)
|
||||
: _monitor(service, std::move(root_path))
|
||||
, _target_file(std::move(target_file))
|
||||
{
|
||||
}
|
||||
Collector(boost::asio::io_service& service,
|
||||
const std::filesystem::path& root_path,
|
||||
const std::filesystem::path& target_file)
|
||||
: _monitor(service, root_path)
|
||||
, _target_file(target_file)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
const auto& fs_event =
|
||||
_monitor.watch(std::regex(FILTER),
|
||||
boost::asio::dir_monitor_event::event_type::added);
|
||||
// big fugly hack
|
||||
std::string call_command =
|
||||
std::string("/usr/bin/tar cvf ") + _target_file.generic_string() +
|
||||
std::string(" ") + _monitor.get_root_path().generic_string();
|
||||
return system(call_command.c_str()) == 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue