Skip to content

Commit

Permalink
Forgot to stage 🤦
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Nov 18, 2024
1 parent d3f395d commit 12d2843
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
12 changes: 10 additions & 2 deletions include/efsw/efsw.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ enum efsw_option
/// For Windows, per default all events are captured but we might only be interested
/// in a subset; the value of the option should be set to a bitwise or'ed set of
/// FILE_NOTIFY_CHANGE_* flags.
EFSW_OPT_WIN_NOTIFY_FILTER = 2
EFSW_OPT_WIN_NOTIFY_FILTER = 2,
/// For macOS (FSEvents backend), per default all modified event types are capture but we might
// only be interested in a subset; the value of the option should be set to a set of bitwise
// from:
// kFSEventStreamEventFlagItemFinderInfoMod
// kFSEventStreamEventFlagItemModified
// kFSEventStreamEventFlagItemInodeMetaMod
// Default configuration will set the 3 flags
EFSW_OPT_MAC_MODIFIED_FILTER = 3,
};

/// Basic interface for listening for file events.
Expand Down Expand Up @@ -131,7 +139,7 @@ EFSW_API void efsw_clearlasterror();

/// Add a directory watch
/// On error returns WatchID with Error type.
efsw_watchid EFSW_API efsw_addwatch(efsw_watcher watcher, const char* directory,
efsw_watchid EFSW_API efsw_addwatch(efsw_watcher watcher, const char* directory,
efsw_pfn_fileaction_callback callback_fn, int recursive, void* param);

/// Add a directory watch, specifying options
Expand Down
12 changes: 10 additions & 2 deletions include/efsw/efsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ enum Option {
/// For Windows, per default all events are captured but we might only be interested
/// in a subset; the value of the option should be set to a bitwise or'ed set of
/// FILE_NOTIFY_CHANGE_* flags.
WinNotifyFilter = 2
WinNotifyFilter = 2,
/// For macOS (FSEvents backend), per default all modified event types are capture but we might
// only be interested in a subset; the value of the option should be set to a set of bitwise
// from:
// kFSEventStreamEventFlagItemFinderInfoMod
// kFSEventStreamEventFlagItemModified
// kFSEventStreamEventFlagItemInodeMetaMod
// Default configuration will set the 3 flags
MacModifiedFilter = 3,
};
}
typedef Options::Option Option;
Expand Down Expand Up @@ -168,7 +176,7 @@ class EFSW_API FileWatcher {
/// @param recursive Set this to true to include subdirectories
/// @param options Allows customization of a watcher
/// @return Returns the watch id for the directory or, on error, a WatchID with Error type.
WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive,
WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive,
const std::vector<WatcherOption> &options );

/// Remove a directory watch. This is a brute force search O(nlogn).
Expand Down
10 changes: 6 additions & 4 deletions src/efsw/FileWatcherFSEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static std::string convertCFStringToStdString( CFStringRef cfString ) {
}
}

void FileWatcherFSEvents::FSEventCallback( ConstFSEventStreamRef streamRef, void* userData,
void FileWatcherFSEvents::FSEventCallback( ConstFSEventStreamRef /*streamRef*/, void* userData,
size_t numEvents, void* eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[] ) {
Expand Down Expand Up @@ -126,7 +126,7 @@ FileWatcherFSEvents::~FileWatcherFSEvents() {
}

WatchID FileWatcherFSEvents::addWatch( const std::string& directory, FileWatchListener* watcher,
bool recursive, const std::vector<WatcherOption> &options ) {
bool recursive, const std::vector<WatcherOption>& options ) {
std::string dir( FileSystem::getRealPath( directory ) );

FileInfo fi( dir );
Expand Down Expand Up @@ -167,6 +167,8 @@ WatchID FileWatcherFSEvents::addWatch( const std::string& directory, FileWatchLi
pWatch->Directory = dir;
pWatch->Recursive = recursive;
pWatch->FWatcher = this;
pWatch->ModifiedFlags =
getOptionValue( options, Option::MacModifiedFilter, efswFSEventsModified );

pWatch->init();

Expand Down Expand Up @@ -211,8 +213,8 @@ void FileWatcherFSEvents::removeWatch( WatchID watchid ) {

void FileWatcherFSEvents::watch() {}

void FileWatcherFSEvents::handleAction( Watcher* watch, const std::string& filename,
unsigned long action, std::string oldFilename ) {
void FileWatcherFSEvents::handleAction( Watcher* /*watch*/, const std::string& /*filename*/,
unsigned long /*action*/, std::string /*oldFilename*/ ) {
/// Not used
}

Expand Down
6 changes: 3 additions & 3 deletions src/efsw/WatcherFSEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void WatcherFSEvents::handleAddModDel( const Uint32& flags, const std::string& p
}
}

if ( flags & efswFSEventsModified ) {
if ( flags & ModifiedFlags ) {
sendFileAction( ID, dirPath, filePath, Actions::Modified );
}

Expand Down Expand Up @@ -154,7 +154,7 @@ void WatcherFSEvents::handleActions( std::vector<FSEvent>& events ) {
sendFileAction( ID, dirPath, filePath, Actions::Delete );
sendFileAction( ID, newDir, newFilepath, Actions::Add );

if ( nEvent.Flags & efswFSEventsModified ) {
if ( nEvent.Flags & ModifiedFlags ) {
sendFileAction( ID, newDir, newFilepath, Actions::Modified );
}
}
Expand All @@ -175,7 +175,7 @@ void WatcherFSEvents::handleActions( std::vector<FSEvent>& events ) {
} else if ( FileInfo::exists( event.Path ) ) {
sendFileAction( ID, dirPath, filePath, Actions::Add );

if ( event.Flags & efswFSEventsModified ) {
if ( event.Flags & ModifiedFlags ) {
sendFileAction( ID, dirPath, filePath, Actions::Modified );
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions src/efsw/WatcherFSEvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@

namespace efsw {

/* OSX < 10.7 has no file events */
/* So i declare the events constants */
enum FSEventEvents {
efswFSEventStreamCreateFlagUseCFTypes = 0x00000001,
efswFSEventStreamCreateFlagNoDefer = 0x00000002,
efswFSEventStreamCreateFlagFileEvents = 0x00000010,
efswFSEventStreamCreateFlagUseExtendedData = 0x00000040,
efswFSEventStreamEventFlagItemCreated = 0x00000100,
efswFSEventStreamEventFlagItemRemoved = 0x00000200,
efswFSEventStreamEventFlagItemInodeMetaMod = 0x00000400,
efswFSEventStreamEventFlagItemRenamed = 0x00000800,
efswFSEventStreamEventFlagItemModified = 0x00001000,
efswFSEventStreamEventFlagItemFinderInfoMod = 0x00002000,
efswFSEventStreamEventFlagItemChangeOwner = 0x00004000,
efswFSEventStreamEventFlagItemXattrMod = 0x00008000,
efswFSEventStreamEventFlagItemIsFile = 0x00010000,
efswFSEventStreamEventFlagItemIsDir = 0x00020000,
efswFSEventStreamEventFlagItemIsSymlink = 0x00040000,
efswFSEventsModified = efswFSEventStreamEventFlagItemFinderInfoMod |
efswFSEventStreamEventFlagItemModified |
efswFSEventStreamEventFlagItemInodeMetaMod
};

class FileWatcherFSEvents;

class FSEvent {
Expand Down Expand Up @@ -44,6 +67,7 @@ class WatcherFSEvents : public Watcher {

Atomic<FileWatcherFSEvents*> FWatcher;
FSEventStreamRef FSStream;
Uint64 ModifiedFlags{ efswFSEventsModified };

protected:
void handleAddModDel( const Uint32& flags, const std::string& path, std::string& dirPath,
Expand Down
1 change: 0 additions & 1 deletion src/efsw/platform/posix/ThreadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <cassert>
#include <efsw/Debug.hpp>
#include <iostream>

namespace efsw { namespace Platform {

Expand Down

0 comments on commit 12d2843

Please sign in to comment.