MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
MockFlowFiles Struct Reference

Public Member Functions

 MockFlowFiles (fs::path domain, uuids::uuid const &id)
void touch ()
 ~MockFlowFiles ()

Public Attributes

int _accessFileFd
int _dataFileFd
fs::path _domain
uuids::uuid _id

Detailed Description

Definition at line 34 of file test_domainwatcher.cpp.

Constructor & Destructor Documentation

◆ MockFlowFiles()

MockFlowFiles::MockFlowFiles ( fs::path domain,
uuids::uuid const & id )
inline

Definition at line 36 of file test_domainwatcher.cpp.

37 : _domain{std::move(domain)}
38 , _id{id}
39 , _accessFileFd{-1}
40 {
41 auto flowDir = makeFlowDirectoryName(_domain, uuids::to_string(_id));
42 std::filesystem::create_directories(flowDir);
43 auto accessFilePath = makeFlowAccessFilePath(flowDir);
44 auto dataFilePath = makeFlowDataFilePath(flowDir);
45
46 _accessFileFd = ::open(accessFilePath.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0644);
47 if (_accessFileFd < 0)
48 {
49 auto const error = errno;
50 throw std::system_error{error, std::system_category(), "Failed to open access file"};
51 }
52
53 _dataFileFd = ::open(dataFilePath.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0644);
54
55 if (::ftruncate(_accessFileFd, sizeof(Grain)) < 0)
56 {
57 auto const error = errno;
58 throw std::system_error{error, std::system_category(), "Failed truncate access file"};
59 }
60
61 if (::ftruncate(_dataFileFd, sizeof(Flow)) < 0)
62 {
63 auto const error = errno;
64 throw std::system_error{error, std::system_category(), "Failed truncate access file"};
65 }
66 }
std::filesystem::path makeFlowAccessFilePath(std::filesystem::path const &flowDirectory)
Definition PathUtils.cpp:29
std::filesystem::path makeFlowDataFilePath(std::filesystem::path const &flowDirectory)
Definition PathUtils.cpp:17
std::filesystem::path makeFlowDirectoryName(std::filesystem::path const &domain, std::string const &uuid)
Definition PathUtils.cpp:11

◆ ~MockFlowFiles()

MockFlowFiles::~MockFlowFiles ( )
inline

Definition at line 68 of file test_domainwatcher.cpp.

69 {
70 if (_accessFileFd > -1)
71 {
72 (void)::close(_accessFileFd);
73 }
74 if (_dataFileFd > -1)
75 {
76 (void)::close(_dataFileFd);
77 }
78
79 auto flowDir = makeFlowDirectoryName(_domain, uuids::to_string(_id));
80 fs::remove(makeFlowAccessFilePath(flowDir));
81 fs::remove(makeFlowDataFilePath(flowDir));
82 }

Member Function Documentation

◆ touch()

void MockFlowFiles::touch ( )
inline

Definition at line 84 of file test_domainwatcher.cpp.

85 {
86 auto times = std::array<::timespec, 2>{
87 timespec{.tv_sec = 0, .tv_nsec = UTIME_NOW },
88 timespec{.tv_sec = 0, .tv_nsec = UTIME_OMIT}
89 };
90 if (auto ret = ::futimens(_accessFileFd, times.data()); ret < 0)
91 {
92 auto const error = errno;
93 throw std::system_error(error, std::system_category(), "Failed to update flow access time");
94 }
95 }

Member Data Documentation

◆ _accessFileFd

int MockFlowFiles::_accessFileFd

Definition at line 99 of file test_domainwatcher.cpp.

◆ _dataFileFd

int MockFlowFiles::_dataFileFd

Definition at line 100 of file test_domainwatcher.cpp.

◆ _domain

fs::path MockFlowFiles::_domain

Definition at line 97 of file test_domainwatcher.cpp.

◆ _id

uuids::uuid MockFlowFiles::_id

Definition at line 98 of file test_domainwatcher.cpp.


The documentation for this struct was generated from the following file: