Skip to content

Commit

Permalink
Make sure all path checks are case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed May 8, 2024
1 parent 60b711c commit 45efb02
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/FSWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/FSWrapperMergeDirsWithParent.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "FSWrapperMergeDirsWithParent.h"
#include "utils/StringTools.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include <coreinit/cache.h>
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 11 additions & 1 deletion src/utils/StringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ std::string string_format(const std::string &format, Args... args) {
auto buf = std::make_unique<char[]>(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
}
}

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);
});
}

0 comments on commit 45efb02

Please sign in to comment.