MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / concatPath

Method concatPath

src/common/os/win32/path_utils.cpp:131–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131void PathUtils::concatPath(PathName& result,
132 const PathName& first,
133 const PathName& second)
134{
135 if (first.length() == 0)
136 {
137 result = second;
138 return;
139 }
140
141 result = first;
142
143 // First path used to be from trusted sources like getRootDirectory, etc.
144 // Second path is mostly user-entered and must be carefully parsed to avoid hacking
145 if (second.length() == 0)
146 {
147 return;
148 }
149
150 ensureSeparator(result);
151
152 PathName::size_type cur_pos = 0;
153
154 for (PathName::size_type pos = 0; cur_pos < second.length(); cur_pos = pos + 1)
155 {
156 static const char separators[] = "/\\";
157 static const PathName::size_type separatorsLen =
158 static_cast<PathName::size_type>(strlen(separators));
159
160 pos = second.find_first_of(separators, cur_pos, separatorsLen);
161 if (pos == PathName::npos) // simple name, simple handling
162 pos = second.length();
163
164 if (pos == cur_pos) // Empty piece, ignore
165 continue;
166
167 if (pos == cur_pos + curr_dir_link_len &&
168 memcmp(second.c_str() + cur_pos, curr_dir_link, curr_dir_link_len) == 0) // Current dir, ignore
169 {
170 continue;
171 }
172
173 if (pos == cur_pos + up_dir_link_len &&
174 memcmp(second.c_str() + cur_pos, up_dir_link, up_dir_link_len) == 0) // One dir up
175 {
176 if (result.length() < 2)
177 {
178 // We have nothing to cut off, ignore this piece (may be throw an error?..)
179 continue;
180 }
181
182 const PathName::size_type up_dir = result.find_last_of(
183 separators, result.length() - 2, separatorsLen);
184
185 if (up_dir == PathName::npos)
186 continue;
187
188 result.erase(up_dir + 1);

Callers

nothing calls this directly

Calls 6

lengthMethod · 0.45
find_first_ofMethod · 0.45
c_strMethod · 0.45
find_last_ofMethod · 0.45
eraseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected