SQLUserDefinedFunctionsLoader allow symlinks in user_defined directory

This commit is contained in:
Maksim Kita 2022-06-17 17:43:42 +02:00
parent 53f5f355d9
commit 965b706350

View File

@ -86,29 +86,34 @@ void UserDefinedSQLObjectsLoader::loadObjects(ContextPtr context)
if (unlikely(!enable_persistence))
return;
LOG_DEBUG(log, "loading user defined objects");
LOG_DEBUG(log, "Loading user defined objects");
String dir_path = context->getUserDefinedPath();
Poco::DirectoryIterator dir_end;
for (Poco::DirectoryIterator it(dir_path); it != dir_end; ++it)
{
if (it->isLink())
if (it->isDirectory())
continue;
const auto & file_name = it.name();
const std::string & file_name = it.name();
/// For '.svn', '.gitignore' directory and similar.
if (file_name.at(0) == '.')
continue;
if (!it->isDirectory() && endsWith(file_name, ".sql"))
{
if (!startsWith(file_name, "function_") || !endsWith(file_name, ".sql"))
continue;
std::string_view object_name = file_name;
object_name.remove_suffix(strlen(".sql"));
object_name.remove_prefix(strlen("function_"));
object_name.remove_suffix(strlen(".sql"));
if (object_name.empty())
continue;
loadUserDefinedObject(context, UserDefinedSQLObjectType::Function, object_name, dir_path + it.name());
}
}
}
void UserDefinedSQLObjectsLoader::storeObject(ContextPtr context, UserDefinedSQLObjectType object_type, const String & object_name, const IAST & ast, bool replace)