| 27 | } |
| 28 | |
| 29 | void addInitFileDirToSearchPath(const std::shared_ptr<Connection>& conn, |
| 30 | const std::string& initFile) { |
| 31 | auto slashPos = initFile.find_last_of('/'); |
| 32 | if (slashPos == std::string::npos) { |
| 33 | return; |
| 34 | } |
| 35 | auto initDirPath = initFile.substr(0, slashPos); |
| 36 | if (initDirPath.empty()) { |
| 37 | initDirPath = "/"; |
| 38 | } else if (initFile.find("://") == std::string::npos) { |
| 39 | initDirPath = std::filesystem::absolute(initDirPath).lexically_normal().string(); |
| 40 | } |
| 41 | auto clientConfig = conn->getClientContext()->getClientConfigUnsafe(); |
| 42 | auto& fileSearchPath = clientConfig->fileSearchPath; |
| 43 | if (!fileSearchPath.empty()) { |
| 44 | auto searchPaths = StringUtils::split(fileSearchPath, ","); |
| 45 | if (std::find(searchPaths.begin(), searchPaths.end(), initDirPath) != searchPaths.end()) { |
| 46 | return; |
| 47 | } |
| 48 | fileSearchPath = std::format("{},{}", initDirPath, fileSearchPath); |
| 49 | return; |
| 50 | } |
| 51 | fileSearchPath = initDirPath; |
| 52 | } |
| 53 | |
| 54 | void processRunCommands(EmbeddedShell& shell, const std::shared_ptr<Connection>& conn, |
| 55 | const std::string& filename) { |