MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / checkTableFilePath

Method checkTableFilePath

src/Databases/DatabaseFilesystem.cpp:82–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82bool 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
116StoragePtr DatabaseFilesystem::tryGetTableFromCache(const std::string & name) const
117{

Callers

nothing calls this directly

Calls 6

containsGlobsFunction · 0.85
getApplicationTypeMethod · 0.80
getUserFilesPathMethod · 0.80
ExceptionClass · 0.50
existsFunction · 0.50

Tested by

no test coverage detected