Skip to content

Commit f181315

Browse files
committed
Dep/efsw: Update to SpartanJ/efsw@f94a661
(cherry picked from commit 8fcec269170f209f79590b3a22f2c85f551cf17b)
1 parent 8583456 commit f181315

39 files changed

+625
-752
lines changed

dep/PackageList.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bzip2 (a freely available, patent free, high-quality data compressor)
1414

1515
efsw (Entropia File System Watcher - crossplatform file system watcher)
1616
https://github.com/SpartanJ/efsw
17-
Version: 1.3.1+ 36c1c7004a34b6f40719f0830bcfb10325415451
17+
Version: 1.5.0+ f94a6616aba85fc9375fdff7ee69609d223a0672
1818

1919
fmt (a small, safe and fast formatting library)
2020
https://github.com/fmtlib/fmt

dep/efsw/CMakeLists.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ set(EFSW_CPP_SOURCE
2121
src/efsw/FileWatcherImpl.hpp
2222
src/efsw/Lock.hpp
2323
src/efsw/Log.cpp
24-
src/efsw/Mutex.cpp
2524
src/efsw/Mutex.hpp
2625
src/efsw/sophist.h
2726
src/efsw/String.cpp
2827
src/efsw/String.hpp
2928
src/efsw/System.cpp
3029
src/efsw/System.hpp
31-
src/efsw/Thread.cpp
3230
src/efsw/Thread.hpp
3331
src/efsw/Utf.hpp
3432
src/efsw/Watcher.cpp
@@ -42,22 +40,14 @@ if (WIN32)
4240
list (APPEND EFSW_CPP_SOURCE
4341
src/efsw/platform/win/FileSystemImpl.cpp
4442
src/efsw/platform/win/FileSystemImpl.hpp
45-
src/efsw/platform/win/MutexImpl.cpp
46-
src/efsw/platform/win/MutexImpl.hpp
4743
src/efsw/platform/win/SystemImpl.cpp
48-
src/efsw/platform/win/SystemImpl.hpp
49-
src/efsw/platform/win/ThreadImpl.cpp
50-
src/efsw/platform/win/ThreadImpl.hpp)
44+
src/efsw/platform/win/SystemImpl.hpp)
5145
else ()
5246
list (APPEND EFSW_CPP_SOURCE
5347
src/efsw/platform/posix/FileSystemImpl.cpp
5448
src/efsw/platform/posix/FileSystemImpl.hpp
55-
src/efsw/platform/posix/MutexImpl.cpp
56-
src/efsw/platform/posix/MutexImpl.hpp
5749
src/efsw/platform/posix/SystemImpl.cpp
58-
src/efsw/platform/posix/SystemImpl.hpp
59-
src/efsw/platform/posix/ThreadImpl.cpp
60-
src/efsw/platform/posix/ThreadImpl.hpp)
50+
src/efsw/platform/posix/SystemImpl.hpp)
6151
endif()
6252

6353
if (APPLE)

dep/efsw/include/efsw/efsw.h

Lines changed: 87 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
@author Sepul Sepehr Taghdisian
33
4-
Copyright (c) 2013 Martin Lucas Golini
4+
Copyright (c) 2024 Martín Lucas Golini
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -32,31 +32,31 @@
3232
extern "C" {
3333
#endif
3434

35-
#if defined(_WIN32)
36-
#ifdef EFSW_DYNAMIC
37-
// Windows platforms
38-
#ifdef EFSW_EXPORTS
39-
// From DLL side, we must export
40-
#define EFSW_API __declspec(dllexport)
41-
#else
42-
// From client application side, we must import
43-
#define EFSW_API __declspec(dllimport)
44-
#endif
45-
#else
46-
// No specific directive needed for static build
47-
#ifndef EFSW_API
48-
#define EFSW_API
49-
#endif
50-
#endif
35+
#if defined( _WIN32 )
36+
#ifdef EFSW_DYNAMIC
37+
// Windows platforms
38+
#ifdef EFSW_EXPORTS
39+
// From DLL side, we must export
40+
#define EFSW_API __declspec( dllexport )
5141
#else
52-
#if ( __GNUC__ >= 4 ) && defined( EFSW_EXPORTS )
53-
#define EFSW_API __attribute__ ((visibility("default")))
54-
#endif
55-
56-
// Other platforms don't need to define anything
57-
#ifndef EFSW_API
58-
#define EFSW_API
59-
#endif
42+
// From client application side, we must import
43+
#define EFSW_API __declspec( dllimport )
44+
#endif
45+
#else
46+
// No specific directive needed for static build
47+
#ifndef EFSW_API
48+
#define EFSW_API
49+
#endif
50+
#endif
51+
#else
52+
#if ( __GNUC__ >= 4 ) && defined( EFSW_EXPORTS )
53+
#define EFSW_API __attribute__( ( visibility( "default" ) ) )
54+
#endif
55+
56+
// Other platforms don't need to define anything
57+
#ifndef EFSW_API
58+
#define EFSW_API
59+
#endif
6060
#endif
6161

6262
/// Type for a watch id
@@ -65,27 +65,24 @@ typedef long efsw_watchid;
6565
/// Type for watcher
6666
typedef void* efsw_watcher;
6767

68-
enum efsw_action
69-
{
70-
EFSW_ADD = 1, /// Sent when a file is created or renamed
71-
EFSW_DELETE = 2, /// Sent when a file is deleted or renamed
72-
EFSW_MODIFIED = 3, /// Sent when a file is modified
73-
EFSW_MOVED = 4 /// Sent when a file is moved
68+
enum efsw_action {
69+
EFSW_ADD = 1, /// Sent when a file is created or renamed
70+
EFSW_DELETE = 2, /// Sent when a file is deleted or renamed
71+
EFSW_MODIFIED = 3, /// Sent when a file is modified
72+
EFSW_MOVED = 4 /// Sent when a file is moved
7473
};
7574

76-
enum efsw_error
77-
{
78-
EFSW_NOTFOUND = -1,
79-
EFSW_REPEATED = -2,
80-
EFSW_OUTOFSCOPE = -3,
81-
EFSW_NOTREADABLE = -4,
82-
EFSW_REMOTE = -5,
83-
EFSW_WATCHER_FAILED = -6,
84-
EFSW_UNSPECIFIED = -7
75+
enum efsw_error {
76+
EFSW_NOTFOUND = -1,
77+
EFSW_REPEATED = -2,
78+
EFSW_OUTOFSCOPE = -3,
79+
EFSW_NOTREADABLE = -4,
80+
EFSW_REMOTE = -5,
81+
EFSW_WATCHER_FAILED = -6,
82+
EFSW_UNSPECIFIED = -7
8583
};
8684

87-
enum efsw_option
88-
{
85+
enum efsw_option {
8986
/// For Windows, the default buffer size of 63*1024 bytes sometimes is not enough and
9087
/// file system events may be dropped. For that, using a different (bigger) buffer size
9188
/// can be defined here, but note that this does not work for network drives,
@@ -95,19 +92,37 @@ enum efsw_option
9592
/// For Windows, per default all events are captured but we might only be interested
9693
/// in a subset; the value of the option should be set to a bitwise or'ed set of
9794
/// FILE_NOTIFY_CHANGE_* flags.
98-
EFSW_OPT_WIN_NOTIFY_FILTER = 2
95+
EFSW_OPT_WIN_NOTIFY_FILTER = 2,
96+
/// For macOS (FSEvents backend), per default all modified event types are capture but we might
97+
// only be interested in a subset; the value of the option should be set to a set of bitwise
98+
// from:
99+
// kFSEventStreamEventFlagItemFinderInfoMod
100+
// kFSEventStreamEventFlagItemModified
101+
// kFSEventStreamEventFlagItemInodeMetaMod
102+
// Default configuration will set the 3 flags
103+
EFSW_OPT_MAC_MODIFIED_FILTER = 3,
104+
/// macOS sometimes informs incorrect or old file states that may confuse the consumer
105+
/// The events sanitizer will try to sanitize incorrectly reported events in favor of reducing
106+
/// the number of events reported. This will have an small performance and memory impact as a
107+
/// consequence.
108+
EFSW_OPT_MAC_SANITIZE_EVENTS = 4,
109+
/// Linux does not support natively recursive watchers. This means that when using recursive
110+
/// watches efsw registers new watchers for each directory. If new file are created between
111+
/// the time efsw takes to register the new directory those events might be missed. To avoid
112+
/// missing new file notifications efsw will trigger synthetic new file events for existing
113+
/// files in the new directroy watched. This might have the unintended consequence of sending
114+
/// duplicated created events due to the system also emitting this event.
115+
LINUX_PRODUCE_SYNTHETIC_EVENTS = 5,
99116
};
100117

101118
/// Basic interface for listening for file events.
102-
typedef void (*efsw_pfn_fileaction_callback) (
103-
efsw_watcher watcher,
104-
efsw_watchid watchid,
105-
const char* dir,
106-
const char* filename,
107-
enum efsw_action action,
108-
const char* old_filename,
109-
void* param
110-
);
119+
typedef void ( *efsw_pfn_fileaction_callback )( efsw_watcher watcher, efsw_watchid watchid,
120+
const char* dir, const char* filename,
121+
enum efsw_action action, const char* old_filename,
122+
void* param );
123+
124+
typedef void ( *efsw_pfn_handle_missed_fileactions )( efsw_watcher watcher, efsw_watchid watchid,
125+
const char* dir );
111126

112127
typedef struct {
113128
enum efsw_option option;
@@ -118,10 +133,10 @@ typedef struct {
118133
* Creates a new file-watcher
119134
* @param generic_mode Force the use of the Generic file watcher
120135
*/
121-
efsw_watcher EFSW_API efsw_create(int generic_mode);
136+
efsw_watcher EFSW_API efsw_create( int generic_mode );
122137

123138
/// Release the file-watcher and unwatch any directories
124-
void EFSW_API efsw_release(efsw_watcher watcher);
139+
void EFSW_API efsw_release( efsw_watcher watcher );
125140

126141
/// Retrieve last error occured by file-watcher
127142
EFSW_API const char* efsw_getlasterror();
@@ -131,47 +146,49 @@ EFSW_API void efsw_clearlasterror();
131146

132147
/// Add a directory watch
133148
/// On error returns WatchID with Error type.
134-
efsw_watchid EFSW_API efsw_addwatch(efsw_watcher watcher, const char* directory,
135-
efsw_pfn_fileaction_callback callback_fn, int recursive, void* param);
149+
efsw_watchid EFSW_API efsw_addwatch( efsw_watcher watcher, const char* directory,
150+
efsw_pfn_fileaction_callback callback_fn, int recursive,
151+
void* param );
136152

137153
/// Add a directory watch, specifying options
138154
/// @param options Pointer to an array of watcher options
139155
/// @param nr_options Number of options referenced by \p options
140-
efsw_watchid EFSW_API efsw_addwatch_withoptions(efsw_watcher watcher, const char* directory,
141-
efsw_pfn_fileaction_callback callback_fn, int recursive, efsw_watcher_option *options,
142-
int options_number, void* param);
156+
efsw_watchid EFSW_API efsw_addwatch_withoptions(
157+
efsw_watcher watcher, const char* directory, efsw_pfn_fileaction_callback callback_fn,
158+
int recursive, efsw_watcher_option* options, int options_number, void* param,
159+
efsw_pfn_handle_missed_fileactions callback_fn_missed_file_actions );
143160

144161
/// Remove a directory watch. This is a brute force search O(nlogn).
145-
void EFSW_API efsw_removewatch(efsw_watcher watcher, const char* directory);
162+
void EFSW_API efsw_removewatch( efsw_watcher watcher, const char* directory );
146163

147164
/// Remove a directory watch. This is a map lookup O(logn).
148-
void EFSW_API efsw_removewatch_byid(efsw_watcher watcher, efsw_watchid watchid);
165+
void EFSW_API efsw_removewatch_byid( efsw_watcher watcher, efsw_watchid watchid );
149166

150167
/// Starts watching ( in other thread )
151-
void EFSW_API efsw_watch(efsw_watcher watcher);
168+
void EFSW_API efsw_watch( efsw_watcher watcher );
152169

153170
/**
154171
* Allow recursive watchers to follow symbolic links to other directories
155172
* followSymlinks is disabled by default
156173
*/
157-
void EFSW_API efsw_follow_symlinks(efsw_watcher watcher, int enable);
174+
void EFSW_API efsw_follow_symlinks( efsw_watcher watcher, int enable );
158175

159176
/** @return If can follow symbolic links to directorioes */
160-
int EFSW_API efsw_follow_symlinks_isenabled(efsw_watcher watcher);
177+
int EFSW_API efsw_follow_symlinks_isenabled( efsw_watcher watcher );
161178

162179
/**
163180
* When enable this it will allow symlinks to watch recursively out of the pointed directory.
164181
* follorSymlinks must be enabled to this work.
165-
* For example, added symlink to /home/folder, and the symlink points to /, this by default is not allowed,
166-
* it's only allowed to symlink anything from /home/ and deeper. This is to avoid great levels of recursion.
167-
* Enabling this could lead in infinite recursion, and crash the watcher ( it will try not to avoid this ).
168-
* Buy enabling out of scope links, it will allow this behavior.
182+
* For example, added symlink to /home/folder, and the symlink points to /, this by default is not
183+
* allowed, it's only allowed to symlink anything from /home/ and deeper. This is to avoid great
184+
* levels of recursion. Enabling this could lead in infinite recursion, and crash the watcher ( it
185+
* will try not to avoid this ). Buy enabling out of scope links, it will allow this behavior.
169186
* allowOutOfScopeLinks are disabled by default.
170187
*/
171-
void EFSW_API efsw_allow_outofscopelinks(efsw_watcher watcher, int allow);
188+
void EFSW_API efsw_allow_outofscopelinks( efsw_watcher watcher, int allow );
172189

173190
/// @return Returns if out of scope links are allowed
174-
int EFSW_API efsw_outofscopelinks_isallowed(efsw_watcher watcher);
191+
int EFSW_API efsw_outofscopelinks_isallowed( efsw_watcher watcher );
175192

176193
#ifdef __cplusplus
177194
}

dep/efsw/include/efsw/efsw.hpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
@author Martín Lucas Golini
33
4-
Copyright (c) 2013 Martín Lucas Golini
4+
Copyright (c) 2024 Martín Lucas Golini
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,6 @@
2828
#ifndef ESFW_HPP
2929
#define ESFW_HPP
3030

31-
#include <vector>
3231
#include <string>
3332
#include <vector>
3433

@@ -135,7 +134,27 @@ enum Option {
135134
/// For Windows, per default all events are captured but we might only be interested
136135
/// in a subset; the value of the option should be set to a bitwise or'ed set of
137136
/// FILE_NOTIFY_CHANGE_* flags.
138-
WinNotifyFilter = 2
137+
WinNotifyFilter = 2,
138+
/// For macOS (FSEvents backend), per default all modified event types are capture but we might
139+
/// only be interested in a subset; the value of the option should be set to a set of bitwise
140+
/// from:
141+
/// kFSEventStreamEventFlagItemFinderInfoMod
142+
/// kFSEventStreamEventFlagItemModified
143+
/// kFSEventStreamEventFlagItemInodeMetaMod
144+
/// Default configuration will set the 3 flags
145+
MacModifiedFilter = 3,
146+
/// macOS sometimes informs incorrect or old file states that may confuse the consumer
147+
/// The events sanitizer will try to sanitize incorrectly reported events in favor of reducing
148+
/// the number of events reported. This will have an small performance and memory impact as a
149+
/// consequence.
150+
MacSanitizeEvents = 4,
151+
/// Linux does not support natively recursive watchers. This means that when using recursive
152+
/// watches efsw registers new watchers for each directory. If new file are created between
153+
/// the time efsw takes to register the new directory those events might be missed. To avoid
154+
/// missing new file notifications efsw will trigger synthetic created file events for existing
155+
/// files in the new directroy watched. This might have the unintended consequence of sending
156+
/// duplicated created events due to the system also emitting this event.
157+
LinuxProduceSyntheticEvents = 5,
139158
};
140159
}
141160
typedef Options::Option Option;
@@ -168,8 +187,8 @@ class EFSW_API FileWatcher {
168187
/// @param recursive Set this to true to include subdirectories
169188
/// @param options Allows customization of a watcher
170189
/// @return Returns the watch id for the directory or, on error, a WatchID with Error type.
171-
WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive,
172-
const std::vector<WatcherOption> &options );
190+
WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive,
191+
const std::vector<WatcherOption>& options );
173192

174193
/// Remove a directory watch. This is a brute force search O(nlogn).
175194
void removeWatch( const std::string& directory );
@@ -226,13 +245,19 @@ class FileWatchListener {
226245
virtual void handleFileAction( WatchID watchid, const std::string& dir,
227246
const std::string& filename, Action action,
228247
std::string oldFilename = "" ) = 0;
248+
249+
/// Handles that have missed file actions
250+
/// @param watchid The watch id for the directory
251+
/// @param dir The directory
252+
virtual void handleMissedFileActions( WatchID /*watchid*/,
253+
const std::string& /*dir*/ ) {}
229254
};
230255

231256
/// Optional, typically platform specific parameter for customization of a watcher.
232257
/// @class WatcherOption
233258
class WatcherOption {
234259
public:
235-
WatcherOption(Option option, int value) : mOption(option), mValue(value) {};
260+
WatcherOption( Option option, int value ) : mOption( option ), mValue( value ){};
236261
Option mOption;
237262
int mValue;
238263
};

dep/efsw/src/efsw/Debug.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ void efPRINTC( unsigned int cond, const char* format, ... );
4949
#define efDEBUGC( cond, format, args... ) \
5050
{}
5151
#else
52-
#define efDEBUG
53-
#define efDEBUGC
52+
#define efDEBUG( ... ) \
53+
{}
54+
#define efDEBUGC( ... ) \
55+
{}
5456
#endif
5557

5658
#endif

0 commit comments

Comments
 (0)