MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / RealPath

Method RealPath

common/FileSystem.cpp:288–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286}
287
288std::string Path::RealPath(const std::string_view path)
289{
290 // Resolve non-absolute paths first.
291 std::vector<std::string_view> components;
292 // We need to keep the full combined path in scope
293 // as SplitNativePath() returns string_views to it.
294 std::string buf;
295 if (!IsAbsolute(path))
296 {
297 buf = Path::Combine(FileSystem::GetWorkingDirectory(), path);
298 components = Path::SplitNativePath(buf);
299 }
300 else
301 components = Path::SplitNativePath(path);
302
303 std::string realpath;
304 if (components.empty())
305 return realpath;
306
307 // Different to path because relative.
308 realpath.reserve(std::accumulate(components.begin(), components.end(), static_cast<size_t>(0),
309 [](size_t l, const std::string_view& s) { return l + s.length(); }) +
310 components.size() + 1);
311
312#ifdef _WIN32
313 std::wstring wrealpath;
314 std::vector<WCHAR> symlink_buf;
315 wrealpath.reserve(realpath.size());
316 symlink_buf.resize(path.size() + 1);
317
318 // Check for any symbolic links throughout the path while adding components.
319 const bool skip_first = IsUNCPath(path);
320 bool test_symlink = true;
321 for (const std::string_view& comp : components)
322 {
323 if (!realpath.empty())
324 {
325 realpath.push_back(FS_OSPATH_SEPARATOR_CHARACTER);
326 realpath.append(comp);
327 }
328 else if (skip_first)
329 {
330 realpath.append(comp);
331 continue;
332 }
333 else
334 {
335 realpath.append(comp);
336 }
337 if (test_symlink)
338 {
339 DWORD attribs;
340 if (FileSystem::GetWin32Path(&wrealpath, realpath) &&
341 (attribs = GetFileAttributesW(wrealpath.c_str())) != INVALID_FILE_ATTRIBUTES)
342 {
343 // if not a link, go to the next component
344 if (attribs & FILE_ATTRIBUTE_REPARSE_POINT)
345 {

Callers

nothing calls this directly

Calls 15

CombineFunction · 0.85
IsUNCPathFunction · 0.85
GetFileAttributesWFunction · 0.85
WideStringToUTF8StringFunction · 0.85
CloseHandleFunction · 0.85
starts_withMethod · 0.80
emptyMethod · 0.45
reserveMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected