diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 5db2eeb..009c1ab 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,12 +9,12 @@ on: jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Install Dependencies - run: sudo apt install cmake libboost-filesystem-dev libboost-test-dev gcc + run: sudo apt install cmake libboost-all-dev libboost-test-dev gcc - name: Print System Information run: | cmake --version diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 0eae955..2667b06 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -9,12 +9,12 @@ on: jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Install Dependencies - run: sudo apt install cmake libboost-filesystem-dev libboost-test-dev gcc + run: sudo apt install cmake libboost-all-dev gcc - name: Print System Information run: | cmake --version @@ -25,7 +25,7 @@ jobs: export CXX=g++ export CC=gcc mkdir build && cd build - cmake .. + cmake .. -DBUILD_TEST=OFF cmake --build . --target inotify_example - name: Run example run: | diff --git a/.gitignore b/.gitignore index 7bf025c..61c3e77 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ test/unit/testDirectory/ install_manifest.txt .idea/ **/build/ -cmake-build-debug/ \ No newline at end of file +cmake-build-debug/ +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 06c3a1f..3f71bae 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ the implementation of a simple filesystem event watcher for the commandline. ```c++ #include -#include +#include #include #include @@ -27,7 +27,7 @@ int main(int argc, char** argv) } // Parse the directory to watch - boost::filesystem::path path(argv[1]); + std::filesystem::path path(argv[1]); // Set the event handler which will be used to process particular events auto handleNotification = [&](Notification notification) { @@ -98,7 +98,7 @@ cmake --build . --target inotify_example ## Dependencies ## + lib + boost 1.54.0 - + c++11 + + c++17 + linux 2.6.13 + build + cmake 3.8 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 3ca9ef4..a689c16 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -13,7 +13,7 @@ endif() ############################################################################### find_package( Boost 1.54.0 - COMPONENTS unit_test_framework system filesystem + COMPONENTS unit_test_framework system REQUIRED ) @@ -26,10 +26,8 @@ find_package(Threads) # Target ############################################################################### add_executable(inotify_example main.cpp) +target_compile_features(inotify_example PRIVATE cxx_std_17) target_link_libraries(inotify_example PRIVATE inotify-cpp::inotify-cpp - Boost::unit_test_framework - Boost::system - Boost::filesystem ${CMAKE_THREAD_LIBS_INIT}) diff --git a/example/main.cpp b/example/main.cpp index 957f549..fd27494 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -16,7 +16,7 @@ int main(int argc, char** argv) } // Parse the directory to watch - boost::filesystem::path path(argv[1]); + std::filesystem::path path(argv[1]); // Set the event handler which will be used to process particular events auto handleNotification = [&](Notification notification) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27b840f..3ec517d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,6 @@ include(GNUInstallDirs) # dependencies find_package( Boost 1.54.0 - COMPONENTS system filesystem REQUIRED ) @@ -40,8 +39,7 @@ macro(configure_target target) target_include_directories(${target} PUBLIC $ $) - target_link_libraries(${target} - INTERFACE Boost::system Boost::filesystem) + target_compile_features(${target} PRIVATE cxx_std_17) endmacro(configure_target target) # library definition diff --git a/src/FileSystemEvent.cpp b/src/FileSystemEvent.cpp index 9991bb0..db5a309 100644 --- a/src/FileSystemEvent.cpp +++ b/src/FileSystemEvent.cpp @@ -6,7 +6,7 @@ namespace inotify { FileSystemEvent::FileSystemEvent( const int wd, uint32_t mask, - const boost::filesystem::path& path, + const std::filesystem::path& path, const std::chrono::steady_clock::time_point& eventTime) : wd(wd) , mask(mask) diff --git a/src/Inotify.cpp b/src/Inotify.cpp index bbce3b4..62605ea 100644 --- a/src/Inotify.cpp +++ b/src/Inotify.cpp @@ -1,15 +1,16 @@ #include +#include +#include #include #include -#include #include #include #include -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace inotify { @@ -97,14 +98,15 @@ Inotify::~Inotify() */ void Inotify::watchDirectoryRecursively(fs::path path) { - std::vector paths; + std::vector paths; if (fs::exists(path)) { paths.push_back(path); if (fs::is_directory(path)) { - boost::system::error_code ec; - fs::recursive_directory_iterator it(path, fs::symlink_option::recurse, ec); + std::error_code ec; + fs::recursive_directory_iterator it( + path, fs::directory_options::follow_directory_symlink, ec); fs::recursive_directory_iterator end; for (; it != end; it.increment(ec)) { @@ -234,7 +236,7 @@ void Inotify::setEventTimeout( * @return A new FileSystemEvent * */ -boost::optional Inotify::getNextEvent() +std::optional Inotify::getNextEvent() { std::vector newEvents; @@ -245,7 +247,7 @@ boost::optional Inotify::getNextEvent() } if (mStopped) { - return boost::none; + return std::nullopt; } auto event = mEventQueue.front(); diff --git a/src/Notification.cpp b/src/Notification.cpp index 2b0c85f..de4ebd9 100644 --- a/src/Notification.cpp +++ b/src/Notification.cpp @@ -4,7 +4,7 @@ namespace inotify { Notification::Notification( const Event& event, - const boost::filesystem::path& path, + const std::filesystem::path& path, std::chrono::steady_clock::time_point time) : event(event) , path(path) diff --git a/src/NotifierBuilder.cpp b/src/NotifierBuilder.cpp index e30a3e5..95e2647 100644 --- a/src/NotifierBuilder.cpp +++ b/src/NotifierBuilder.cpp @@ -13,31 +13,31 @@ NotifierBuilder BuildNotifier() return {}; } -auto NotifierBuilder::watchPathRecursively(boost::filesystem::path path) -> NotifierBuilder& +auto NotifierBuilder::watchPathRecursively(std::filesystem::path path) -> NotifierBuilder& { mInotify->watchDirectoryRecursively(path); return *this; } -auto NotifierBuilder::watchFile(boost::filesystem::path file) -> NotifierBuilder& +auto NotifierBuilder::watchFile(std::filesystem::path file) -> NotifierBuilder& { mInotify->watchFile(file); return *this; } -auto NotifierBuilder::unwatchFile(boost::filesystem::path file) -> NotifierBuilder& +auto NotifierBuilder::unwatchFile(std::filesystem::path file) -> NotifierBuilder& { mInotify->unwatchFile(file); return *this; } -auto NotifierBuilder::ignoreFileOnce(boost::filesystem::path file) -> NotifierBuilder& +auto NotifierBuilder::ignoreFileOnce(std::filesystem::path file) -> NotifierBuilder& { mInotify->ignoreFileOnce(file.string()); return *this; } -auto NotifierBuilder::ignoreFile(boost::filesystem::path file) -> NotifierBuilder& +auto NotifierBuilder::ignoreFile(std::filesystem::path file) -> NotifierBuilder& { mInotify->ignoreFile(file.string()); return *this; diff --git a/src/include/inotify-cpp/FileSystemEvent.h b/src/include/inotify-cpp/FileSystemEvent.h index 8e71c83..2bd2de6 100644 --- a/src/include/inotify-cpp/FileSystemEvent.h +++ b/src/include/inotify-cpp/FileSystemEvent.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include @@ -10,7 +10,7 @@ class FileSystemEvent { FileSystemEvent( int wd, uint32_t mask, - const boost::filesystem::path& path, + const std::filesystem::path& path, const std::chrono::steady_clock::time_point& eventTime); ~FileSystemEvent(); @@ -18,7 +18,7 @@ class FileSystemEvent { public: int wd; uint32_t mask; - boost::filesystem::path path; + std::filesystem::path path; std::chrono::steady_clock::time_point eventTime; }; } \ No newline at end of file diff --git a/src/include/inotify-cpp/Inotify.h b/src/include/inotify-cpp/Inotify.h index abffe0e..348171f 100644 --- a/src/include/inotify-cpp/Inotify.h +++ b/src/include/inotify-cpp/Inotify.h @@ -6,23 +6,23 @@ **/ #pragma once #include -#include -#include +#include #include +#include #include #include +#include #include #include +#include #include #include #include -#include #include +#include +#include #include #include -#include -#include -#include #include @@ -79,20 +79,20 @@ class Inotify { public: Inotify(); ~Inotify(); - void watchDirectoryRecursively(boost::filesystem::path path); - void watchFile(boost::filesystem::path file); - void unwatchFile(boost::filesystem::path file); - void ignoreFileOnce(boost::filesystem::path file); - void ignoreFile(boost::filesystem::path file); + void watchDirectoryRecursively(std::filesystem::path path); + void watchFile(std::filesystem::path file); + void unwatchFile(std::filesystem::path file); + void ignoreFileOnce(std::filesystem::path file); + void ignoreFile(std::filesystem::path file); void setEventMask(uint32_t eventMask); uint32_t getEventMask(); void setEventTimeout(std::chrono::milliseconds eventTimeout, std::function onEventTimeout); - boost::optional getNextEvent(); + std::optional getNextEvent(); void stop(); bool hasStopped(); private: - boost::filesystem::path wdToPath(int wd); + std::filesystem::path wdToPath(int wd); bool isIgnored(std::string file); bool isOnTimeout(const std::chrono::steady_clock::time_point &eventTime); void removeWatch(int wd); @@ -110,7 +110,7 @@ class Inotify { std::vector mIgnoredDirectories; std::vector mOnceIgnoredDirectories; std::queue mEventQueue; - boost::bimap mDirectorieMap; + boost::bimap mDirectorieMap; int mInotifyFd; std::atomic mStopped; int mEpollFd; diff --git a/src/include/inotify-cpp/Notification.h b/src/include/inotify-cpp/Notification.h index c156e95..eb14529 100644 --- a/src/include/inotify-cpp/Notification.h +++ b/src/include/inotify-cpp/Notification.h @@ -2,7 +2,7 @@ #include -#include +#include #include @@ -12,12 +12,12 @@ class Notification { public: Notification( const Event& event, - const boost::filesystem::path& path, + const std::filesystem::path& path, std::chrono::steady_clock::time_point time); public: const Event event; - const boost::filesystem::path path; + const std::filesystem::path path; const std::chrono::steady_clock::time_point time; }; } \ No newline at end of file diff --git a/src/include/inotify-cpp/NotifierBuilder.h b/src/include/inotify-cpp/NotifierBuilder.h index 108532c..bf3dfdb 100644 --- a/src/include/inotify-cpp/NotifierBuilder.h +++ b/src/include/inotify-cpp/NotifierBuilder.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -19,11 +19,11 @@ class NotifierBuilder { auto run() -> void; auto runOnce() -> void; auto stop() -> void; - auto watchPathRecursively(boost::filesystem::path path) -> NotifierBuilder&; - auto watchFile(boost::filesystem::path file) -> NotifierBuilder&; - auto unwatchFile(boost::filesystem::path file) -> NotifierBuilder&; - auto ignoreFileOnce(boost::filesystem::path file) -> NotifierBuilder&; - auto ignoreFile(boost::filesystem::path file) -> NotifierBuilder&; + auto watchPathRecursively(std::filesystem::path path) -> NotifierBuilder&; + auto watchFile(std::filesystem::path file) -> NotifierBuilder&; + auto unwatchFile(std::filesystem::path file) -> NotifierBuilder&; + auto ignoreFileOnce(std::filesystem::path file) -> NotifierBuilder&; + auto ignoreFile(std::filesystem::path file) -> NotifierBuilder&; auto onEvent(Event event, EventObserver) -> NotifierBuilder&; auto onEvents(std::vector event, EventObserver) -> NotifierBuilder&; auto onUnexpectedEvent(EventObserver) -> NotifierBuilder&; diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 279b496..806e8ed 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -13,7 +13,7 @@ endif() ############################################################################### find_package( Boost 1.54.0 - COMPONENTS unit_test_framework system filesystem + COMPONENTS unit_test_framework REQUIRED ) @@ -26,12 +26,11 @@ find_package(Threads) # Test ############################################################################### add_executable(inotify_unit_test main.cpp NotifierBuilderTests.cpp EventTests.cpp) +target_compile_features(inotify_unit_test PRIVATE cxx_std_17) target_link_libraries(inotify_unit_test PRIVATE inotify-cpp::inotify-cpp Boost::unit_test_framework - Boost::system - Boost::filesystem ${CMAKE_THREAD_LIBS_INIT}) add_test(NAME inotify_unit_test COMMAND inotify_unit_test) diff --git a/test/unit/NotifierBuilderTests.cpp b/test/unit/NotifierBuilderTests.cpp index 154108d..4d4a4eb 100644 --- a/test/unit/NotifierBuilderTests.cpp +++ b/test/unit/NotifierBuilderTests.cpp @@ -10,7 +10,7 @@ using namespace inotify; -void openFile(const boost::filesystem::path& file) +void openFile(const std::filesystem::path& file) { std::ifstream stream; stream.open(file.string(), std::ifstream::in); @@ -18,9 +18,9 @@ void openFile(const boost::filesystem::path& file) stream.close(); } -void createFile(const boost::filesystem::path& file) +void createFile(const std::filesystem::path& file) { - boost::filesystem::ofstream stream(file); + std::ofstream stream(file); } struct NotifierBuilderTests { @@ -32,8 +32,8 @@ struct NotifierBuilderTests { , createdFile_(testDirectory_ / "created.txt") , timeout_(1) { - boost::filesystem::create_directories(testDirectory_); - boost::filesystem::create_directories(recursiveTestDirectory_); + std::filesystem::create_directories(testDirectory_); + std::filesystem::create_directories(recursiveTestDirectory_); createFile(testFile_); createFile(recursiveTestFile_); @@ -41,14 +41,14 @@ struct NotifierBuilderTests { ~NotifierBuilderTests() { - boost::filesystem::remove_all(testDirectory_); + std::filesystem::remove_all(testDirectory_); } - boost::filesystem::path testDirectory_; - boost::filesystem::path recursiveTestDirectory_; - boost::filesystem::path testFile_; - boost::filesystem::path recursiveTestFile_; - boost::filesystem::path createdFile_; + std::filesystem::path testDirectory_; + std::filesystem::path recursiveTestDirectory_; + std::filesystem::path testFile_; + std::filesystem::path recursiveTestFile_; + std::filesystem::path createdFile_; std::chrono::seconds timeout_; @@ -139,7 +139,7 @@ BOOST_FIXTURE_TEST_CASE(shouldNotifyOnCombinedEvent, NotifierBuilderTests) std::thread thread([¬ifier]() { notifier.runOnce(); }); - boost::filesystem::create_directories(testDirectory_ / "test"); + std::filesystem::create_directories(testDirectory_ / "test"); auto futureCombinedEvent = promisedCombinedEvent_.get_future(); BOOST_CHECK(futureCombinedEvent.wait_for(timeout_) == std::future_status::ready);