From 6bcde4764a0dde31ca9159d0cf89f0912c1cba2c Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 8 Aug 2022 19:28:43 +0200 Subject: [PATCH] Rename void setWorkingDir -> setWorkingDirForFSClient and getFullPathForClient -> getFullPathForFSClient --- src/FSDirReplacements.cpp | 10 +++++----- src/FSFileReplacements.cpp | 20 ++++++++++---------- src/FileUtils.cpp | 24 ++++++++++++------------ src/FileUtils.h | 4 ++-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/FSDirReplacements.cpp b/src/FSDirReplacements.cpp index dba7366..329a311 100644 --- a/src/FSDirReplacements.cpp +++ b/src/FSDirReplacements.cpp @@ -16,7 +16,7 @@ DECL_FUNCTION(FSStatus, FSOpenDir, FSClient *client, FSCmdBlock *block, const ch [c = client, b = block, h = handle, p = path](FSErrorFlag realErrorMask) -> FSStatus { return real_FSOpenDir(c, b, p, h, realErrorMask); }, - [f = getFullPathForClient(client, path), h = handle](std::unique_ptr &layer) -> FSError { + [f = getFullPathForFSClient(client, path), h = handle](std::unique_ptr &layer) -> FSError { return layer->FSOpenDirWrapper(f.c_str(), h); }, SYNC_RESULT_HANDLER); @@ -34,7 +34,7 @@ DECL_FUNCTION(FSStatus, FSOpenDirAsync, FSClient *client, FSCmdBlock *block, con [c = client, b = block, h = handle, p = path, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSOpenDirAsync(c, b, p, h, realErrorMask, a); }, - [f = getFullPathForClient(client, path), h = handle](std::unique_ptr &layer) -> FSError { + [f = getFullPathForFSClient(client, path), h = handle](std::unique_ptr &layer) -> FSError { return layer->FSOpenDirWrapper(f.c_str(), h); }, ASYNC_RESULT_HANDLER); @@ -169,7 +169,7 @@ DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, const ch [c = client, b = block, p = path](FSErrorFlag realErrorMask) -> FSStatus { return real_FSMakeDir(c, b, p, realErrorMask); }, - [f = getFullPathForClient(client, path)](std::unique_ptr &layer) -> FSError { + [f = getFullPathForFSClient(client, path)](std::unique_ptr &layer) -> FSError { return layer->FSMakeDirWrapper(f.c_str()); }, SYNC_RESULT_HANDLER); @@ -186,7 +186,7 @@ DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, con [c = client, b = block, p = path, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSMakeDirAsync(c, b, p, realErrorMask, a); }, - [f = getFullPathForClient(client, path)](std::unique_ptr &layer) -> FSError { + [f = getFullPathForFSClient(client, path)](std::unique_ptr &layer) -> FSError { return layer->FSMakeDirWrapper(f.c_str()); }, ASYNC_RESULT_HANDLER); @@ -194,7 +194,7 @@ DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, con DECL_FUNCTION(FSStatus, FSChangeDirAsync, FSClient *client, FSCmdBlock *block, const char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DEBUG_FUNCTION_LINE_VERBOSE("FSChangeDirAsync %s", path); - setWorkingDir(client, path); + setWorkingDirForFSClient(client, path); return real_FSChangeDirAsync(client, block, path, errorMask, asyncData); } diff --git a/src/FSFileReplacements.cpp b/src/FSFileReplacements.cpp index 3954060..bba8b9e 100644 --- a/src/FSFileReplacements.cpp +++ b/src/FSFileReplacements.cpp @@ -15,7 +15,7 @@ DECL_FUNCTION(FSStatus, FSOpenFileEx, FSClient *client, FSCmdBlock *block, const [c = client, b = block, p = path, m = mode, cm = createMode, of = openFlag, pa = preallocSize, h = handle](FSErrorFlag realErrorMask) -> FSStatus { return real_FSOpenFileEx(c, b, p, m, cm, of, pa, h, realErrorMask); }, - [f = getFullPathForClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { + [f = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { return layer->FSOpenFileWrapper(f.c_str(), m, h); }, SYNC_RESULT_HANDLER); @@ -32,7 +32,7 @@ DECL_FUNCTION(FSStatus, FSOpenFileExAsync, FSClient *client, FSCmdBlock *block, [c = client, b = block, p = path, m = mode, cm = createMode, of = openFlag, pa = preallocSize, h = handle, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSOpenFileExAsync(c, b, p, m, cm, of, pa, h, realErrorMask, a); }, - [p = getFullPathForClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { + [p = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { return layer->FSOpenFileWrapper(p.c_str(), m, h); }, ASYNC_RESULT_HANDLER); @@ -49,7 +49,7 @@ DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *p [c = client, b = block, p = path, m = mode, h = handle](FSErrorFlag realErrorMask) -> FSStatus { return real_FSOpenFile(c, b, p, m, h, realErrorMask); }, - [f = getFullPathForClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { + [f = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { return layer->FSOpenFileWrapper(f.c_str(), m, h); }, SYNC_RESULT_HANDLER); @@ -66,7 +66,7 @@ DECL_FUNCTION(FSStatus, FSOpenFileAsync, FSClient *client, FSCmdBlock *block, co [c = client, b = block, p = path, m = mode, h = handle, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSOpenFileAsync(c, b, p, m, h, realErrorMask, a); }, - [p = getFullPathForClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { + [p = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSError { return layer->FSOpenFileWrapper(p.c_str(), m, h); }, ASYNC_RESULT_HANDLER); @@ -133,7 +133,7 @@ DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, const ch [c = client, b = block, p = path, s = stats](FSErrorFlag realErrorMask) -> FSStatus { return real_FSGetStat(c, b, p, s, realErrorMask); }, - [p = getFullPathForClient(client, path), s = stats](std::unique_ptr &layer) -> FSError { + [p = getFullPathForFSClient(client, path), s = stats](std::unique_ptr &layer) -> FSError { return layer->FSGetStatWrapper(p.c_str(), s); }, SYNC_RESULT_HANDLER); @@ -150,7 +150,7 @@ DECL_FUNCTION(FSStatus, FSGetStatAsync, FSClient *client, FSCmdBlock *block, con [c = client, b = block, p = path, s = stats, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSGetStatAsync(c, b, p, s, realErrorMask, a); }, - [p = getFullPathForClient(client, path), s = stats](std::unique_ptr &layer) -> FSError { + [p = getFullPathForFSClient(client, path), s = stats](std::unique_ptr &layer) -> FSError { return layer->FSGetStatWrapper(p.c_str(), s); }, ASYNC_RESULT_HANDLER); @@ -442,7 +442,7 @@ DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, const cha [c = client, b = block, p = path](FSErrorFlag realErrorMask) -> FSStatus { return real_FSRemove(c, b, p, realErrorMask); }, - [p = getFullPathForClient(client, path)](std::unique_ptr &layer) -> FSError { + [p = getFullPathForFSClient(client, path)](std::unique_ptr &layer) -> FSError { return layer->FSRemoveWrapper(p.c_str()); }, SYNC_RESULT_HANDLER); @@ -459,7 +459,7 @@ DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, cons [c = client, b = block, p = path, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSRemoveAsync(c, b, p, realErrorMask, a); }, - [p = getFullPathForClient(client, path)](std::unique_ptr &layer) -> FSError { + [p = getFullPathForFSClient(client, path)](std::unique_ptr &layer) -> FSError { return layer->FSRemoveWrapper(p.c_str()); }, ASYNC_RESULT_HANDLER); @@ -476,7 +476,7 @@ DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, const cha [c = client, b = block, oP = oldPath, nP = newPath](FSErrorFlag realErrorMask) -> FSStatus { return real_FSRename(c, b, oP, nP, realErrorMask); }, - [oP = getFullPathForClient(client, oldPath), nP = getFullPathForClient(client, newPath)](std::unique_ptr &layer) -> FSError { + [oP = getFullPathForFSClient(client, oldPath), nP = getFullPathForFSClient(client, newPath)](std::unique_ptr &layer) -> FSError { return layer->FSRenameWrapper(oP.c_str(), nP.c_str()); }, SYNC_RESULT_HANDLER); @@ -499,7 +499,7 @@ DECL_FUNCTION(FSStatus, FSRenameAsync, [c = client, b = block, oP = oldPath, nP = newPath, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { return real_FSRenameAsync(c, b, oP, nP, realErrorMask, a); }, - [oP = getFullPathForClient(client, oldPath), nP = getFullPathForClient(client, newPath)](std::unique_ptr &layer) -> FSError { + [oP = getFullPathForFSClient(client, oldPath), nP = getFullPathForFSClient(client, newPath)](std::unique_ptr &layer) -> FSError { return layer->FSRenameWrapper(oP.c_str(), nP.c_str()); }, ASYNC_RESULT_HANDLER); diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 04a36c2..336a7c4 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -6,23 +6,23 @@ #include "utils/utils.h" #include #include -#include #include #include -#include -std::mutex workingDirMutex; -std::map workingDirs; +std::mutex workingDirMutexFS; +std::map workingDirsFS; std::mutex fsLayerMutex; std::vector> fsLayers; -std::string getFullPathForClient(FSClient *pClient, const char *path) { +std::string getFullPathForFSClient(FSClient *pClient, const char *path) { + std::lock_guard workingDirLock(workingDirMutexFS); + std::string res; if (path[0] != '/' && path[0] != '\\') { - if (workingDirs.count(pClient) > 0) { - res = string_format("%s%s", workingDirs.at(pClient).c_str(), path); + if (workingDirsFS.count(pClient) > 0) { + res = string_format("%s%s", workingDirsFS.at(pClient).c_str(), path); } else { DEBUG_FUNCTION_LINE_ERR("Failed to find working dir for client"); } @@ -35,17 +35,17 @@ std::string getFullPathForClient(FSClient *pClient, const char *path) { return res; } -void setWorkingDir(FSClient *client, const char *path) { - std::lock_guard workingDirLock(workingDirMutex); +void setWorkingDirForFSClient(FSClient *client, const char *path) { + std::lock_guard workingDirLock(workingDirMutexFS); - workingDirs[client] = path; + workingDirsFS[client] = path; OSMemoryBarrier(); } void clearFSLayer() { { - std::lock_guard workingDirLock(workingDirMutex); - workingDirs.clear(); + std::lock_guard workingDirLock(workingDirMutexFS); + workingDirsFS.clear(); } { std::lock_guard layerLock(fsLayerMutex); diff --git a/src/FileUtils.h b/src/FileUtils.h index c5c405a..1276c32 100644 --- a/src/FileUtils.h +++ b/src/FileUtils.h @@ -38,9 +38,9 @@ static inline FSErrorFlag isForceRealFunction(FSErrorFlag flag) { void clearFSLayer(); -std::string getFullPathForClient(FSClient *pClient, const char *path); +std::string getFullPathForFSClient(FSClient *pClient, const char *path); -void setWorkingDir(FSClient *client, const char *path); +void setWorkingDirForFSClient(FSClient *client, const char *path); FSStatus doForLayer(FSClient *client, FSErrorFlag errorMask,