MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / expandPath

Method expandPath

src/storage/storage_utils.cpp:72–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72std::string StorageUtils::expandPath(const main::ClientContext* context, const std::string& path) {
73 if (main::DBConfig::isDBPathInMemory(path)) {
74 return path;
75 }
76 auto fullPath = path;
77 // Handle '~' for home directory expansion
78 if (path.starts_with('~')) {
79 fullPath =
80 context->getCurrentSetting(main::HomeDirectorySetting::name).getValue<std::string>() +
81 fullPath.substr(1);
82 }
83#ifdef __EMSCRIPTEN__
84 if (isWindowsDrivePath(fullPath) || isWindowsUNCPath(fullPath)) {
85 for (auto& ch : fullPath) {
86 if (ch == '\\') {
87 ch = '/';
88 }
89 }
90 }
91#endif
92 // Normalize the path to resolve '.' and '..'. Avoid std::filesystem::absolute
93 // when the input already names a Windows drive/UNC path because absolute may
94 // consult current_path(), which can fail if the process cwd has been deleted.
95 std::filesystem::path normalizedPath;
96 std::filesystem::path filePath{fullPath};
97 auto shouldAvoidAbsolute = filePath.is_absolute();
98#if defined(_WIN32) || defined(__EMSCRIPTEN__)
99 shouldAvoidAbsolute =
100 shouldAvoidAbsolute || isWindowsDrivePath(fullPath) || isWindowsUNCPath(fullPath);
101#endif
102 if (shouldAvoidAbsolute) {
103 normalizedPath = filePath.lexically_normal();
104 } else {
105 normalizedPath = std::filesystem::absolute(filePath).lexically_normal();
106 }
107 return normalizedPath.string();
108}
109
110uint32_t StorageUtils::getDataTypeSize(const LogicalType& type) {
111 switch (type.getPhysicalType()) {

Callers 3

AttachedLbugDatabaseMethod · 0.45

Calls 3

isWindowsDrivePathFunction · 0.85
isWindowsUNCPathFunction · 0.85
getCurrentSettingMethod · 0.80

Tested by

no test coverage detected