diff --git a/dbms/src/Storages/StorageFile.cpp b/dbms/src/Storages/StorageFile.cpp index e4cb68280b1..776a7fca4b6 100644 --- a/dbms/src/Storages/StorageFile.cpp +++ b/dbms/src/Storages/StorageFile.cpp @@ -42,15 +42,14 @@ static std::string getTablePath(const std::string & db_dir_path, const std::stri return db_dir_path + escapeForFileName(table_name) + "/data." + escapeForFileName(format_name); } -static void checkCreationIsAllowed(Context & context_global, const std::string & table_path, const std::string & db_dir_path) +static void checkCreationIsAllowed(Context & context_global, const std::string & db_dir_path, const std::string & table_path, const int & table_fd) { if (context_global.getApplicationType() != Context::ApplicationType::SERVER) return; - if (table_path.empty()) + if (table_fd >= 0) throw Exception("Using file descriptor as source of storage isn't allowed for server daemons", ErrorCodes::DATABASE_ACCESS_DENIED); - - if (!startsWith(table_path, db_dir_path)) + else if (!startsWith(table_path, db_dir_path)) throw Exception("Part path " + table_path + " is not inside " + db_dir_path, ErrorCodes::DATABASE_ACCESS_DENIED); } @@ -77,7 +76,7 @@ StorageFile::StorageFile( poco_path = Poco::Path(db_dir_path, poco_path); path = poco_path.absolute().toString(); - checkCreationIsAllowed(context_global, path, db_dir_path); + checkCreationIsAllowed(context_global, db_dir_path, path, table_fd); is_db_table = false; } else /// Is DB's file @@ -92,7 +91,7 @@ StorageFile::StorageFile( } else /// Will use FD { - checkCreationIsAllowed(context_global, "", db_dir_path); + checkCreationIsAllowed(context_global, db_dir_path, path, table_fd); is_db_table = false; use_table_fd = true;