diff --git a/src/FSWrapper.cpp b/src/FSWrapper.cpp index e4b17a5..5a151c1 100644 --- a/src/FSWrapper.cpp +++ b/src/FSWrapper.cpp @@ -83,7 +83,7 @@ FSError FSWrapper::FSReadDirWrapper(FSDirectoryHandle handle, FSDirectoryEntry * struct dirent *entry_ = readdir(dir); if (entry_) { - if (SkipDeletedFilesInReadDir() && std::string_view(entry_->d_name).starts_with(deletePrefix)) { + if (SkipDeletedFilesInReadDir() && starts_with_case_insensitive(entry_->d_name, deletePrefix)) { DEBUG_FUNCTION_LINE_ERR("Skip file file name %s because of the prefix", entry_->d_name); continue; } @@ -317,7 +317,7 @@ FSError FSWrapper::FSCloseFileWrapper(FSFileHandle handle) { bool FSWrapper::CheckFileShouldBeIgnored(std::string &path) { auto asPath = std::filesystem::path(path); - if (std::string(asPath.filename().c_str()).starts_with(deletePrefix)) { + if (starts_with_case_insensitive(asPath.filename().c_str(), deletePrefix)) { DEBUG_FUNCTION_LINE_VERBOSE("[%s] Ignore %s, filename starts with %s", getName().c_str(), path.c_str(), deletePrefix.c_str()); return true; } @@ -673,8 +673,9 @@ bool FSWrapper::IsFileModeAllowed(const char *mode) { return false; } + bool FSWrapper::IsPathToReplace(const std::string_view &path) { - return path.starts_with(pPathToReplace); + return starts_with_case_insensitive(path, pPathToReplace); } std::string FSWrapper::GetNewPath(const std::string_view &path) { diff --git a/src/FSWrapperMergeDirsWithParent.cpp b/src/FSWrapperMergeDirsWithParent.cpp index b781956..df82c5b 100644 --- a/src/FSWrapperMergeDirsWithParent.cpp +++ b/src/FSWrapperMergeDirsWithParent.cpp @@ -1,4 +1,5 @@ #include "FSWrapperMergeDirsWithParent.h" +#include "utils/StringTools.h" #include "utils/logger.h" #include "utils/utils.h" #include @@ -83,7 +84,7 @@ FSError FSWrapperMergeDirsWithParent::FSReadDirWrapper(FSADirectoryHandle handle /** * Read the next entry if this entry starts with deletePrefix. We keep the entry but mark it as deleted. */ - if (std::string_view(entry->name).starts_with(deletePrefix)) { + if (starts_with_case_insensitive(entry->name, deletePrefix)) { dirHandle->readResult[dirHandle->readResultNumberOfEntries].isMarkedAsDeleted = true; OSMemoryBarrier(); diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index e825367..78ec91a 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -11,4 +11,14 @@ std::string string_format(const std::string &format, Args... args) { auto buf = std::make_unique(size); std::snprintf(buf.get(), size, format.c_str(), args...); return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside -} \ No newline at end of file +} + +static inline bool starts_with_case_insensitive(std::string_view str, std::string_view prefix) { + if (str.size() < prefix.size()) + return false; + + return std::equal(prefix.begin(), prefix.end(), str.begin(), + [](char a, char b) { + return std::tolower(a) == std::tolower(b); + }); +}