Commit b749957c authored by Philip Trettner's avatar Philip Trettner

fix for gcc false positive warning

parent 6c99baa6
......@@ -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)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment