Skip to content

Commit e2c0d3c

Browse files
authored
Allows to override FileUtils::getWritablePath() on Linux. (#2906)
1 parent a076ac8 commit e2c0d3c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

core/platform/FileUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ const std::vector<std::string>& FileUtils::getOriginalSearchPaths() const
779779
void FileUtils::setWritablePath(std::string_view writablePath)
780780
{
781781
_writablePath = writablePath;
782+
783+
if (!_writablePath.empty() && (_writablePath.back() != '/'))
784+
_writablePath += '/';
782785
}
783786

784787
const std::string& FileUtils::getDefaultResourceRootPath() const

core/platform/linux/FileUtils-linux.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ using namespace std;
3939
namespace ax
4040
{
4141

42-
static std::string _checkPath(const char* path) {
42+
static std::string _checkPath(const char* path)
43+
{
4344
std::string ret;
4445
ret.resize(PATH_MAX - 1);
4546
int n = readlink(path, &ret.front(), PATH_MAX);
46-
if (n > 0) {
47+
if (n > 0)
48+
{
4749
ret.resize(n);
4850
return ret;
4951
}
@@ -72,8 +74,9 @@ FileUtilsLinux::FileUtilsLinux() {}
7274
bool FileUtilsLinux::init()
7375
{
7476
// application path
75-
if (s_exeDir.empty()) {
76-
s_exeDir = _checkPath("/proc/self/exe");
77+
if (s_exeDir.empty())
78+
{
79+
s_exeDir = _checkPath("/proc/self/exe");
7780
auto slash = s_exeDir.find_last_of('/');
7881
assert(slash != std::string::npos);
7982
s_exeName = s_exeDir.substr(slash + 1);
@@ -104,9 +107,9 @@ bool FileUtilsLinux::init()
104107
xdgConfigPath = xdg_config_path;
105108
}
106109
_writablePath = xdgConfigPath;
107-
_writablePath += "/";
110+
_writablePath += '/';
108111
_writablePath += s_exeName;
109-
_writablePath += "/";
112+
_writablePath += '/';
110113

111114
bool ret = FileUtils::init();
112115

@@ -140,4 +143,4 @@ bool FileUtilsLinux::isFileExistInternal(std::string_view path) const
140143
return (stat(path.data(), &sts) == 0) && S_ISREG(sts.st_mode);
141144
}
142145

143-
}
146+
} // namespace ax

core/platform/linux/FileUtils-linux.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class AX_DLL FileUtilsLinux : public FileUtils
4747
protected:
4848
FileUtilsLinux();
4949

50-
private:
51-
std::string _writablePath;
52-
5350
public:
5451
/* override functions */
5552
bool init() override;

0 commit comments

Comments
 (0)