From e0e5e812a7f6eaaf2e51b078ce9bf9c45e130379 Mon Sep 17 00:00:00 2001 From: hcz Date: Tue, 5 Nov 2019 17:48:49 +0800 Subject: [PATCH] Allow relative user_files_path --- dbms/src/Storages/StorageFile.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dbms/src/Storages/StorageFile.cpp b/dbms/src/Storages/StorageFile.cpp index d38f1f76ccd..1a05f646670 100644 --- a/dbms/src/Storages/StorageFile.cpp +++ b/dbms/src/Storages/StorageFile.cpp @@ -134,6 +134,8 @@ StorageFile::StorageFile( setColumns(columns_); setConstraints(constraints_); + std::string db_dir_path_abs = Poco::Path(db_dir_path).makeAbsolute().makeDirectory().toString(); + if (table_fd < 0) /// Will use file { use_table_fd = false; @@ -142,20 +144,20 @@ StorageFile::StorageFile( { Poco::Path poco_path = Poco::Path(table_path_); if (poco_path.isRelative()) - poco_path = Poco::Path(db_dir_path, poco_path); + poco_path = Poco::Path(db_dir_path_abs, poco_path); const std::string path = poco_path.absolute().toString(); paths = listFilesWithRegexpMatching("/", path); for (const auto & cur_path : paths) - checkCreationIsAllowed(context_global, db_dir_path, cur_path); + checkCreationIsAllowed(context_global, db_dir_path_abs, cur_path); is_db_table = false; } else /// Is DB's file { - if (db_dir_path.empty()) + if (db_dir_path_abs.empty()) throw Exception("Storage " + getName() + " requires data path", ErrorCodes::INCORRECT_FILE_NAME); - paths = {getTablePath(db_dir_path, table_name, format_name)}; + paths = {getTablePath(db_dir_path_abs, table_name, format_name)}; is_db_table = true; Poco::File(Poco::Path(paths.back()).parent()).createDirectories(); }