Skip to content

Commit f60b1ae

Browse files
authored
Merge pull request #76 from erikzenker/feature/erikzenker/std-filesystem
feat: Update to c++17 (std::filesystem)
2 parents 5d0d203 + bccfcbe commit f60b1ae

17 files changed

+71
-73
lines changed

.github/workflows/build_and_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-16.04
12+
runs-on: ubuntu-20.04
1313

1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Install Dependencies
17-
run: sudo apt install cmake libboost-filesystem-dev libboost-test-dev gcc
17+
run: sudo apt install cmake libboost-all-dev libboost-test-dev gcc
1818
- name: Print System Information
1919
run: |
2020
cmake --version

.github/workflows/example.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-16.04
12+
runs-on: ubuntu-20.04
1313

1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Install Dependencies
17-
run: sudo apt install cmake libboost-filesystem-dev libboost-test-dev gcc
17+
run: sudo apt install cmake libboost-all-dev gcc
1818
- name: Print System Information
1919
run: |
2020
cmake --version
@@ -25,7 +25,7 @@ jobs:
2525
export CXX=g++
2626
export CC=gcc
2727
mkdir build && cd build
28-
cmake ..
28+
cmake .. -DBUILD_TEST=OFF
2929
cmake --build . --target inotify_example
3030
- name: Run example
3131
run: |

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ test/unit/testDirectory/
99
install_manifest.txt
1010
.idea/
1111
**/build/
12-
cmake-build-debug/
12+
cmake-build-debug/
13+
.vscode

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the implementation of a simple filesystem event watcher for the commandline.
1111
```c++
1212
#include <inotify-cpp/NotifierBuilder.h>
1313

14-
#include <boost/filesystem.hpp>
14+
#include <filesystem>
1515

1616
#include <iostream>
1717
#include <thread>
@@ -27,7 +27,7 @@ int main(int argc, char** argv)
2727
}
2828

2929
// Parse the directory to watch
30-
boost::filesystem::path path(argv[1]);
30+
std::filesystem::path path(argv[1]);
3131

3232
// Set the event handler which will be used to process particular events
3333
auto handleNotification = [&](Notification notification) {
@@ -98,7 +98,7 @@ cmake --build . --target inotify_example
9898
## Dependencies ##
9999
+ lib
100100
+ boost 1.54.0
101-
+ c++11
101+
+ c++17
102102
+ linux 2.6.13
103103
+ build
104104
+ cmake 3.8

example/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313
###############################################################################
1414
find_package(
1515
Boost 1.54.0
16-
COMPONENTS unit_test_framework system filesystem
16+
COMPONENTS unit_test_framework system
1717
REQUIRED
1818
)
1919

@@ -26,10 +26,8 @@ find_package(Threads)
2626
# Target
2727
###############################################################################
2828
add_executable(inotify_example main.cpp)
29+
target_compile_features(inotify_example PRIVATE cxx_std_17)
2930
target_link_libraries(inotify_example
3031
PRIVATE
3132
inotify-cpp::inotify-cpp
32-
Boost::unit_test_framework
33-
Boost::system
34-
Boost::filesystem
3533
${CMAKE_THREAD_LIBS_INIT})

example/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <inotify-cpp/NotifierBuilder.h>
22

3-
#include <boost/filesystem.hpp>
3+
#include <filesystem>
44

55
#include <iostream>
66
#include <thread>
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
1616
}
1717

1818
// Parse the directory to watch
19-
boost::filesystem::path path(argv[1]);
19+
std::filesystem::path path(argv[1]);
2020

2121
// Set the event handler which will be used to process particular events
2222
auto handleNotification = [&](Notification notification) {

src/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ include(GNUInstallDirs)
1515
# dependencies
1616
find_package(
1717
Boost 1.54.0
18-
COMPONENTS system filesystem
1918
REQUIRED
2019
)
2120

@@ -40,8 +39,7 @@ macro(configure_target target)
4039
target_include_directories(${target} PUBLIC
4140
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
4241
$<INSTALL_INTERFACE:include>)
43-
target_link_libraries(${target}
44-
INTERFACE Boost::system Boost::filesystem)
42+
target_compile_features(${target} PRIVATE cxx_std_17)
4543
endmacro(configure_target target)
4644

4745
# library definition

src/FileSystemEvent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace inotify {
66
FileSystemEvent::FileSystemEvent(
77
const int wd,
88
uint32_t mask,
9-
const boost::filesystem::path& path,
9+
const std::filesystem::path& path,
1010
const std::chrono::steady_clock::time_point& eventTime)
1111
: wd(wd)
1212
, mask(mask)

src/Inotify.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11

22
#include <inotify-cpp/Inotify.h>
33

4+
#include <iostream>
5+
#include <optional>
46
#include <string>
57
#include <vector>
6-
#include <iostream>
78

89
#include <sys/epoll.h>
910
#include <fcntl.h>
1011
#include <unistd.h>
1112

12-
namespace fs = boost::filesystem;
13+
namespace fs = std::filesystem;
1314

1415
namespace inotify {
1516

@@ -97,14 +98,15 @@ Inotify::~Inotify()
9798
*/
9899
void Inotify::watchDirectoryRecursively(fs::path path)
99100
{
100-
std::vector<boost::filesystem::path> paths;
101+
std::vector<std::filesystem::path> paths;
101102

102103
if (fs::exists(path)) {
103104
paths.push_back(path);
104105

105106
if (fs::is_directory(path)) {
106-
boost::system::error_code ec;
107-
fs::recursive_directory_iterator it(path, fs::symlink_option::recurse, ec);
107+
std::error_code ec;
108+
fs::recursive_directory_iterator it(
109+
path, fs::directory_options::follow_directory_symlink, ec);
108110
fs::recursive_directory_iterator end;
109111

110112
for (; it != end; it.increment(ec)) {
@@ -234,7 +236,7 @@ void Inotify::setEventTimeout(
234236
* @return A new FileSystemEvent
235237
*
236238
*/
237-
boost::optional<FileSystemEvent> Inotify::getNextEvent()
239+
std::optional<FileSystemEvent> Inotify::getNextEvent()
238240
{
239241
std::vector<FileSystemEvent> newEvents;
240242

@@ -245,7 +247,7 @@ boost::optional<FileSystemEvent> Inotify::getNextEvent()
245247
}
246248

247249
if (mStopped) {
248-
return boost::none;
250+
return std::nullopt;
249251
}
250252

251253
auto event = mEventQueue.front();

src/Notification.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace inotify {
44

55
Notification::Notification(
66
const Event& event,
7-
const boost::filesystem::path& path,
7+
const std::filesystem::path& path,
88
std::chrono::steady_clock::time_point time)
99
: event(event)
1010
, path(path)

src/NotifierBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ NotifierBuilder BuildNotifier()
1313
return {};
1414
}
1515

16-
auto NotifierBuilder::watchPathRecursively(boost::filesystem::path path) -> NotifierBuilder&
16+
auto NotifierBuilder::watchPathRecursively(std::filesystem::path path) -> NotifierBuilder&
1717
{
1818
mInotify->watchDirectoryRecursively(path);
1919
return *this;
2020
}
2121

22-
auto NotifierBuilder::watchFile(boost::filesystem::path file) -> NotifierBuilder&
22+
auto NotifierBuilder::watchFile(std::filesystem::path file) -> NotifierBuilder&
2323
{
2424
mInotify->watchFile(file);
2525
return *this;
2626
}
2727

28-
auto NotifierBuilder::unwatchFile(boost::filesystem::path file) -> NotifierBuilder&
28+
auto NotifierBuilder::unwatchFile(std::filesystem::path file) -> NotifierBuilder&
2929
{
3030
mInotify->unwatchFile(file);
3131
return *this;
3232
}
3333

34-
auto NotifierBuilder::ignoreFileOnce(boost::filesystem::path file) -> NotifierBuilder&
34+
auto NotifierBuilder::ignoreFileOnce(std::filesystem::path file) -> NotifierBuilder&
3535
{
3636
mInotify->ignoreFileOnce(file.string());
3737
return *this;
3838
}
3939

40-
auto NotifierBuilder::ignoreFile(boost::filesystem::path file) -> NotifierBuilder&
40+
auto NotifierBuilder::ignoreFile(std::filesystem::path file) -> NotifierBuilder&
4141
{
4242
mInotify->ignoreFile(file.string());
4343
return *this;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
#include <boost/filesystem.hpp>
2+
#include <filesystem>
33

44
#include <chrono>
55
#include <string>
@@ -10,15 +10,15 @@ class FileSystemEvent {
1010
FileSystemEvent(
1111
int wd,
1212
uint32_t mask,
13-
const boost::filesystem::path& path,
13+
const std::filesystem::path& path,
1414
const std::chrono::steady_clock::time_point& eventTime);
1515

1616
~FileSystemEvent();
1717

1818
public:
1919
int wd;
2020
uint32_t mask;
21-
boost::filesystem::path path;
21+
std::filesystem::path path;
2222
std::chrono::steady_clock::time_point eventTime;
2323
};
2424
}

src/include/inotify-cpp/Inotify.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
**/
77
#pragma once
88
#include <assert.h>
9-
#include <boost/filesystem.hpp>
10-
#include <boost/optional.hpp>
9+
#include <atomic>
1110
#include <boost/bimap.hpp>
11+
#include <chrono>
1212
#include <errno.h>
1313
#include <exception>
14+
#include <filesystem>
1415
#include <map>
1516
#include <memory>
17+
#include <optional>
1618
#include <queue>
1719
#include <sstream>
1820
#include <string>
19-
#include <sys/inotify.h>
2021
#include <sys/epoll.h>
22+
#include <sys/inotify.h>
23+
#include <thread>
2124
#include <time.h>
2225
#include <vector>
23-
#include <chrono>
24-
#include <thread>
25-
#include <atomic>
2626

2727
#include <inotify-cpp/FileSystemEvent.h>
2828

@@ -79,20 +79,20 @@ class Inotify {
7979
public:
8080
Inotify();
8181
~Inotify();
82-
void watchDirectoryRecursively(boost::filesystem::path path);
83-
void watchFile(boost::filesystem::path file);
84-
void unwatchFile(boost::filesystem::path file);
85-
void ignoreFileOnce(boost::filesystem::path file);
86-
void ignoreFile(boost::filesystem::path file);
82+
void watchDirectoryRecursively(std::filesystem::path path);
83+
void watchFile(std::filesystem::path file);
84+
void unwatchFile(std::filesystem::path file);
85+
void ignoreFileOnce(std::filesystem::path file);
86+
void ignoreFile(std::filesystem::path file);
8787
void setEventMask(uint32_t eventMask);
8888
uint32_t getEventMask();
8989
void setEventTimeout(std::chrono::milliseconds eventTimeout, std::function<void(FileSystemEvent)> onEventTimeout);
90-
boost::optional<FileSystemEvent> getNextEvent();
90+
std::optional<FileSystemEvent> getNextEvent();
9191
void stop();
9292
bool hasStopped();
9393

9494
private:
95-
boost::filesystem::path wdToPath(int wd);
95+
std::filesystem::path wdToPath(int wd);
9696
bool isIgnored(std::string file);
9797
bool isOnTimeout(const std::chrono::steady_clock::time_point &eventTime);
9898
void removeWatch(int wd);
@@ -110,7 +110,7 @@ class Inotify {
110110
std::vector<std::string> mIgnoredDirectories;
111111
std::vector<std::string> mOnceIgnoredDirectories;
112112
std::queue<FileSystemEvent> mEventQueue;
113-
boost::bimap<int, boost::filesystem::path> mDirectorieMap;
113+
boost::bimap<int, std::filesystem::path> mDirectorieMap;
114114
int mInotifyFd;
115115
std::atomic<bool> mStopped;
116116
int mEpollFd;

src/include/inotify-cpp/Notification.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <inotify-cpp/Event.h>
44

5-
#include <boost/filesystem.hpp>
5+
#include <filesystem>
66

77
#include <chrono>
88

@@ -12,12 +12,12 @@ class Notification {
1212
public:
1313
Notification(
1414
const Event& event,
15-
const boost::filesystem::path& path,
15+
const std::filesystem::path& path,
1616
std::chrono::steady_clock::time_point time);
1717

1818
public:
1919
const Event event;
20-
const boost::filesystem::path path;
20+
const std::filesystem::path path;
2121
const std::chrono::steady_clock::time_point time;
2222
};
2323
}

src/include/inotify-cpp/NotifierBuilder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <inotify-cpp/Inotify.h>
44
#include <inotify-cpp/Notification.h>
55

6-
#include <boost/filesystem.hpp>
6+
#include <filesystem>
77

88
#include <memory>
99
#include <string>
@@ -19,11 +19,11 @@ class NotifierBuilder {
1919
auto run() -> void;
2020
auto runOnce() -> void;
2121
auto stop() -> void;
22-
auto watchPathRecursively(boost::filesystem::path path) -> NotifierBuilder&;
23-
auto watchFile(boost::filesystem::path file) -> NotifierBuilder&;
24-
auto unwatchFile(boost::filesystem::path file) -> NotifierBuilder&;
25-
auto ignoreFileOnce(boost::filesystem::path file) -> NotifierBuilder&;
26-
auto ignoreFile(boost::filesystem::path file) -> NotifierBuilder&;
22+
auto watchPathRecursively(std::filesystem::path path) -> NotifierBuilder&;
23+
auto watchFile(std::filesystem::path file) -> NotifierBuilder&;
24+
auto unwatchFile(std::filesystem::path file) -> NotifierBuilder&;
25+
auto ignoreFileOnce(std::filesystem::path file) -> NotifierBuilder&;
26+
auto ignoreFile(std::filesystem::path file) -> NotifierBuilder&;
2727
auto onEvent(Event event, EventObserver) -> NotifierBuilder&;
2828
auto onEvents(std::vector<Event> event, EventObserver) -> NotifierBuilder&;
2929
auto onUnexpectedEvent(EventObserver) -> NotifierBuilder&;

0 commit comments

Comments
 (0)