Rename void setWorkingDir -> setWorkingDirForFSClient and getFullPathForClient -> getFullPathForFSClient

This commit is contained in:
Maschell 2022-08-08 19:28:43 +02:00
parent fca2193e40
commit 6bcde4764a
4 changed files with 29 additions and 29 deletions

View File

@ -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<IFSWrapper> &layer) -> FSError {
[f = getFullPathForFSClient(client, path), h = handle](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[f = getFullPathForFSClient(client, path), h = handle](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[f = getFullPathForFSClient(client, path)](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[f = getFullPathForFSClient(client, path)](std::unique_ptr<IFSWrapper> &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);
}

View File

@ -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<IFSWrapper> &layer) -> FSError {
[f = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[p = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[f = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[p = getFullPathForFSClient(client, path), m = mode, h = handle](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[p = getFullPathForFSClient(client, path), s = stats](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[p = getFullPathForFSClient(client, path), s = stats](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[p = getFullPathForFSClient(client, path)](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[p = getFullPathForFSClient(client, path)](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[oP = getFullPathForFSClient(client, oldPath), nP = getFullPathForFSClient(client, newPath)](std::unique_ptr<IFSWrapper> &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<IFSWrapper> &layer) -> FSError {
[oP = getFullPathForFSClient(client, oldPath), nP = getFullPathForFSClient(client, newPath)](std::unique_ptr<IFSWrapper> &layer) -> FSError {
return layer->FSRenameWrapper(oP.c_str(), nP.c_str());
},
ASYNC_RESULT_HANDLER);

View File

@ -6,23 +6,23 @@
#include "utils/utils.h"
#include <coreinit/cache.h>
#include <coreinit/filesystem_fsa.h>
#include <coreinit/thread.h>
#include <map>
#include <unistd.h>
#include <wums.h>
std::mutex workingDirMutex;
std::map<FSClient *, std::string> workingDirs;
std::mutex workingDirMutexFS;
std::map<FSClient *, std::string> workingDirsFS;
std::mutex fsLayerMutex;
std::vector<std::unique_ptr<IFSWrapper>> fsLayers;
std::string getFullPathForClient(FSClient *pClient, const char *path) {
std::string getFullPathForFSClient(FSClient *pClient, const char *path) {
std::lock_guard<std::mutex> 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<std::mutex> workingDirLock(workingDirMutex);
void setWorkingDirForFSClient(FSClient *client, const char *path) {
std::lock_guard<std::mutex> workingDirLock(workingDirMutexFS);
workingDirs[client] = path;
workingDirsFS[client] = path;
OSMemoryBarrier();
}
void clearFSLayer() {
{
std::lock_guard<std::mutex> workingDirLock(workingDirMutex);
workingDirs.clear();
std::lock_guard<std::mutex> workingDirLock(workingDirMutexFS);
workingDirsFS.clear();
}
{
std::lock_guard<std::mutex> layerLock(fsLayerMutex);

View File

@ -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,