| 80 | } |
| 81 | |
| 82 | bool DatabaseFilesystem::checkTableFilePath(const std::string & table_path, ContextPtr context_, bool throw_on_error) const |
| 83 | { |
| 84 | /// If run in Local mode, no need for path checking. |
| 85 | bool check_path = context_->getApplicationType() != Context::ApplicationType::LOCAL; |
| 86 | const auto & user_files_path = context_->getUserFilesPath(); |
| 87 | |
| 88 | /// Check access for file before checking its existence. |
| 89 | if (check_path && !fileOrSymlinkPathStartsWith(table_path, user_files_path)) |
| 90 | { |
| 91 | /// Access denied is thrown regardless of 'throw_on_error' |
| 92 | throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File is not inside {}", user_files_path); |
| 93 | } |
| 94 | |
| 95 | if (!containsGlobs(table_path)) |
| 96 | { |
| 97 | /// Check if the corresponding file exists. |
| 98 | if (!fs::exists(table_path)) |
| 99 | { |
| 100 | if (throw_on_error) |
| 101 | throw Exception(ErrorCodes::FILE_DOESNT_EXIST, "File does not exist: {}", table_path); |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | if (!fs::is_regular_file(table_path)) |
| 106 | { |
| 107 | if (throw_on_error) |
| 108 | throw Exception(ErrorCodes::FILE_DOESNT_EXIST, "File is directory, but expected a file: {}", table_path); |
| 109 | return false; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | StoragePtr DatabaseFilesystem::tryGetTableFromCache(const std::string & name) const |
| 117 | { |
nothing calls this directly
no test coverage detected