From 921725efdb2c50d2bc81e9d007dbed9b284ca09f Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 9 Aug 2022 00:12:35 +0200 Subject: [PATCH] Improve setting the CWD for client, at basic error handling --- src/FileUtils.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 102e5f5..cc30ec5 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -36,9 +36,18 @@ std::string getFullPathForFSClient(FSClient *pClient, const char *path) { } void setWorkingDirForFSClient(FSClient *client, const char *path) { + if (!path) { + DEBUG_FUNCTION_LINE_WARN("Path was NULL"); + return; + } std::lock_guard workingDirLock(workingDirMutexFS); - workingDirsFS[client] = path; + std::string cwd(path); + if (cwd.empty() || cwd.back() != '/') { + cwd.push_back('/'); + } + + workingDirsFS[client] = cwd; OSMemoryBarrier(); }