diff --git a/src/glow/common/file_watch.cc b/src/glow/common/file_watch.cc index 9a3a7575a420acc173690781bbdb1df4473b8d33..0a72f4d6d86af47cf4bb036c4f4f61f72010d360 100644 --- a/src/glow/common/file_watch.cc +++ b/src/glow/common/file_watch.cc @@ -41,33 +41,6 @@ namespace { static std::size_t constexpr bufferSize = 1024 * 256; -struct FileLocation -{ - std::string directory; - std::string filename; - - FileLocation(std::string const& directory, std::string const& filename) : directory(directory), filename(filename) {} -}; - -const FileLocation getFileLocation(const std::string_view path) -{ - const auto predict = [](char character) -> bool { -#ifdef _WIN32 - return character == _T('\\') || character == _T('/'); -#elif __unix__ || __APPLE__ - return character == '/'; -#endif // __unix__ - }; - - const auto pivot = std::find_if(path.rbegin(), path.rend(), predict).base(); - // if the path is something like "test.txt" there will be no directoy part, however we still need one, so insert './' - const std::string directory = [&]() { - const auto extracted_directory = std::string(path.begin(), pivot); - return (extracted_directory.size() > 0) ? extracted_directory : "./"; - }(); - const std::string filename = std::string(pivot, path.end()); - return FileLocation(directory, filename); -} #ifdef _WIN32 DWORD const sListenFilters = FILE_NOTIFY_CHANGE_SECURITY | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_LAST_ACCESS | FILE_NOTIFY_CHANGE_LAST_WRITE @@ -83,6 +56,34 @@ namespace glow struct FileWatch::Monitor { public: + struct FileLocation + { + std::string directory; + std::string filename; + + FileLocation(std::string const& directory, std::string const& filename) : directory(directory), filename(filename) {} + }; + + static const FileLocation getFileLocation(const std::string_view path) + { + const auto predict = [](char character) -> bool { +#ifdef _WIN32 + return character == _T('\\') || character == _T('/'); +#elif __unix__ || __APPLE__ + return character == '/'; +#endif // __unix__ + }; + + const auto pivot = std::find_if(path.rbegin(), path.rend(), predict).base(); + // if the path is something like "test.txt" there will be no directoy part, however we still need one, so insert './' + const std::string directory = [&]() { + const auto extracted_directory = std::string(path.begin(), pivot); + return (extracted_directory.size() > 0) ? extracted_directory : "./"; + }(); + const std::string filename = std::string(pivot, path.end()); + return FileLocation(directory, filename); + } + struct FileEntry { FileLocation path; @@ -341,7 +342,7 @@ void glow::FileWatch::onFlagDestruction(glow::FileWatch::Flag* flag) glow::FileWatch::SharedFlag glow::FileWatch::watchFile(std::string_view filename, bool forceUnique) { - auto path = getFileLocation(filename); + auto path = Monitor::getFileLocation(filename); if (!forceUnique) {