Skip to content

Commit

Permalink
fix clang-tidy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ege Çetin committed Dec 27, 2024
1 parent 24a00fc commit eaeb433
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 9 additions & 3 deletions include/utils/FileHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class FileMonitor {
/// Callback function
FNotifyCallback _notifyCallback;
/// Notify types
int _notifyEvents;
uint32_t _notifyEvents;
/// User pointer
const void *_userPtr = nullptr;

Expand All @@ -90,9 +90,15 @@ class FileMonitor {
* @param[in] filePath Path to the file
* @param[in] notifyEvents Events to notify
*/
explicit FileMonitor(const std::filesystem::path &filePath, int notifyEvents = IN_MODIFY);
explicit FileMonitor(std::filesystem::path filePath, int notifyEvents = IN_MODIFY);

FNotifyCallback notifyCallback() const { return _notifyCallback; }
/// @brief Copy constructor
FileMonitor(const FileMonitor & /*unused*/) = delete;

/// @brief Copy assignment operator
FileMonitor &operator=(FileMonitor /*unused*/) = delete;

[[nodiscard]] FNotifyCallback notifyCallback() const { return _notifyCallback; }
void notifyCallback(FNotifyCallback func) { _notifyCallback = std::move(func); }

/**
Expand Down
15 changes: 7 additions & 8 deletions src/utils/FileHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ void FileMonitor::threadFunc() const noexcept
while (!_shouldStop._M_i)
{
// Buffer for reading events
unsigned int nBytes;
unsigned int nBytes = 0;
if (ioctl(_fDescriptor, FIONREAD, &nBytes) < 0)
{
spdlog::error("Failed to get available events for file monitoring: {}", getErrnoString(errno));
}

auto buffer = std::make_unique<char[]>(nBytes);
auto nRead = read(_fDescriptor, buffer.get(), nBytes);
auto buffer = std::vector<char>(nBytes + 1, '\0');
auto nRead = read(_fDescriptor, buffer.data(), nBytes);
if (nRead < 0)
{
spdlog::error("Failed to read events for file monitoring: {}", getErrnoString(errno));
Expand All @@ -38,10 +38,10 @@ void FileMonitor::threadFunc() const noexcept
ssize_t idx = 0;
while (_notifyCallback && idx < nRead)
{
const auto *event = reinterpret_cast<inotify_event *>(&buffer[idx]);
const auto *event = reinterpret_cast<inotify_event *>(&buffer[static_cast<size_t>(idx)]);

// Check if file notify type matches
if (event->mask & _notifyEvents)
if ((event->mask & _notifyEvents) != 0)
{
_notifyCallback(_userPtr);
break;
Expand All @@ -54,10 +54,9 @@ void FileMonitor::threadFunc() const noexcept
}
}

FileMonitor::FileMonitor(const std::filesystem::path &filePath, int notifyEvents)
: _filePath(filePath), _notifyEvents(notifyEvents)
FileMonitor::FileMonitor(std::filesystem::path filePath, int notifyEvents)
: _fDescriptor(inotify_init()), _filePath(std::move(filePath)), _notifyEvents(notifyEvents)
{
_fDescriptor = inotify_init();
if (_fDescriptor < 0)
{
throw std::ios_base::failure("Failed to initialize inotify");
Expand Down

0 comments on commit eaeb433

Please sign in to comment.