From 5bfc9daba13501308a607307ba09ae341012accc Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 17 Jan 2023 13:49:21 -0500 Subject: [PATCH] LibCore: Move FileWatcher implementations into separate files Rather than one big file with (eventually) all implementations for each OS, let's keep OS-specific implementations in their own files. --- Userland/Libraries/LibCore/CMakeLists.txt | 8 +++- ...ileWatcher.cpp => FileWatcherSerenity.cpp} | 33 ++-------------- .../LibCore/FileWatcherUnimplemented.cpp | 38 +++++++++++++++++++ 3 files changed, 49 insertions(+), 30 deletions(-) rename Userland/Libraries/LibCore/{FileWatcher.cpp => FileWatcherSerenity.cpp} (91%) create mode 100644 Userland/Libraries/LibCore/FileWatcherUnimplemented.cpp diff --git a/Userland/Libraries/LibCore/CMakeLists.txt b/Userland/Libraries/LibCore/CMakeLists.txt index 92cd286d79..9465e4b3b6 100644 --- a/Userland/Libraries/LibCore/CMakeLists.txt +++ b/Userland/Libraries/LibCore/CMakeLists.txt @@ -10,7 +10,6 @@ set(SOURCES Event.cpp EventLoop.cpp File.cpp - FileWatcher.cpp IODevice.cpp LockFile.cpp MappedFile.cpp @@ -45,5 +44,12 @@ if (NOT ANDROID AND NOT WIN32 AND NOT EMSCRIPTEN) ) endif() +# FIXME: Implement Core::FileWatcher for Linux, macOS, *BSD, and Windows. +if (SERENITYOS) + list(APPEND SOURCES FileWatcherSerenity.cpp) +else() + list(APPEND SOURCES FileWatcherUnimplemented.cpp) +endif() + serenity_lib(LibCore core) target_link_libraries(LibCore PRIVATE LibCrypt LibSystem) diff --git a/Userland/Libraries/LibCore/FileWatcher.cpp b/Userland/Libraries/LibCore/FileWatcherSerenity.cpp similarity index 91% rename from Userland/Libraries/LibCore/FileWatcher.cpp rename to Userland/Libraries/LibCore/FileWatcherSerenity.cpp index ff7e9cad05..d58f972fc3 100644 --- a/Userland/Libraries/LibCore/FileWatcher.cpp +++ b/Userland/Libraries/LibCore/FileWatcherSerenity.cpp @@ -18,10 +18,11 @@ #include #include -namespace Core { +#if !defined(AK_OS_SERENITY) +static_assert(false, "This file must only be used for SerenityOS"); +#endif -// Only supported in serenity mode because we use InodeWatcher syscalls -#ifdef AK_OS_SERENITY +namespace Core { static Optional get_event_from_fd(int fd, HashMap const& wd_to_path) { @@ -206,30 +207,4 @@ FileWatcher::~FileWatcher() dbgln_if(FILE_WATCHER_DEBUG, "Stopped watcher at fd {}", m_notifier->fd()); } -#else -// FIXME: Implement Core::FileWatcher for linux, macOS, and *BSD -FileWatcher::~FileWatcher() { } -FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr notifier) - : FileWatcherBase(watcher_fd) - , m_notifier(move(notifier)) -{ -} - -ErrorOr> FileWatcher::create(InodeWatcherFlags) -{ - return Error::from_errno(ENOTSUP); -} - -ErrorOr FileWatcherBase::add_watch(DeprecatedString, FileWatcherEvent::Type) -{ - return Error::from_errno(ENOTSUP); -} - -ErrorOr FileWatcherBase::remove_watch(DeprecatedString) -{ - return Error::from_errno(ENOTSUP); -} - -#endif - } diff --git a/Userland/Libraries/LibCore/FileWatcherUnimplemented.cpp b/Userland/Libraries/LibCore/FileWatcherUnimplemented.cpp new file mode 100644 index 0000000000..7ee143c304 --- /dev/null +++ b/Userland/Libraries/LibCore/FileWatcherUnimplemented.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020, Itamar S. + * Copyright (c) 2021, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "FileWatcher.h" +#include +#include +#include + +namespace Core { + +ErrorOr> FileWatcher::create(InodeWatcherFlags) +{ + return Error::from_errno(ENOTSUP); +} + +FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr notifier) + : FileWatcherBase(watcher_fd) + , m_notifier(move(notifier)) +{ +} + +FileWatcher::~FileWatcher() = default; + +ErrorOr FileWatcherBase::add_watch(DeprecatedString, FileWatcherEvent::Type) +{ + return Error::from_errno(ENOTSUP); +} + +ErrorOr FileWatcherBase::remove_watch(DeprecatedString) +{ + return Error::from_errno(ENOTSUP); +} + +}