Skip to content

Commit 50fb05a

Browse files
committed
fix issue with file path
1 parent 4aa58ab commit 50fb05a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

config.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,28 @@ std::string Config::command() const
126126
return cmd;
127127
}
128128

129-
static const char *startsWith(const char *arg, const char *start) {
129+
static const char *startsWith(const char *arg, const char *start)
130+
{
130131
if (std::strncmp(arg, start, std::strlen(start)) != 0)
131132
return NULL;
132133
return arg + std::strlen(start);
133134
}
134135

136+
static std::filesystem::path normalizePath(const std::filesystem::path path)
137+
{
138+
std::filesystem::path result;
139+
for (auto component : path) {
140+
if (component.string() == ".")
141+
continue;
142+
if (component.string() == "..") {
143+
result = result.parent_path();
144+
continue;
145+
}
146+
result /= component;
147+
}
148+
return result;
149+
}
150+
135151
std::string Config::parseArgs(int argc, char **argv)
136152
{
137153
(void) argc;
@@ -177,6 +193,9 @@ std::string Config::parseArgs(int argc, char **argv)
177193
if (!m_projectFilePath.empty() && m_projectFilePath.is_relative())
178194
m_projectFilePath = m_configPath.parent_path() / m_projectFilePath;
179195

196+
if (m_filename.is_relative())
197+
m_filename = normalizePath(std::filesystem::current_path() / m_filename);
198+
180199
return "";
181200
}
182201

0 commit comments

Comments
 (0)