diff --git a/dbms/src/Storages/StorageFile.cpp b/dbms/src/Storages/StorageFile.cpp index b845c9dca2c..e640d08beb0 100644 --- a/dbms/src/Storages/StorageFile.cpp +++ b/dbms/src/Storages/StorageFile.cpp @@ -64,11 +64,13 @@ static std::vector listFilesWithRegexpMatching(const std::string & const std::string suffix_with_globs = for_match.substr(end_of_path_without_globs); /// begin with '/' const size_t next_slash = suffix_with_globs.find('/', 1); - re2::RE2 matcher(makeRegexpPatternFromGlobs(suffix_with_globs.substr(0, next_slash))); + auto regexp = makeRegexpPatternFromGlobs(suffix_with_globs.substr(0, next_slash)); + std::cerr << regexp << "\n"; + re2::RE2 matcher(regexp); std::vector result; const std::string prefix_without_globs = path_for_ls + for_match.substr(1, end_of_path_without_globs); - if (!fs::exists(fs::path(prefix_without_globs.data()))) + if (!fs::exists(fs::path(prefix_without_globs))) { return result; } @@ -113,11 +115,11 @@ static void checkCreationIsAllowed(const Context & context_global, const std::st /// "/dev/null" is allowed for perf testing if (!startsWith(table_path, db_dir_path) && table_path != "/dev/null") - throw Exception("Part path " + table_path + " is not inside " + db_dir_path, ErrorCodes::DATABASE_ACCESS_DENIED); + throw Exception("File is not inside " + db_dir_path, ErrorCodes::DATABASE_ACCESS_DENIED); Poco::File table_path_poco_file = Poco::File(table_path); if (table_path_poco_file.exists() && table_path_poco_file.isDirectory()) - throw Exception("File " + table_path + " must not be a directory", ErrorCodes::INCORRECT_FILE_NAME); + throw Exception("File must not be a directory", ErrorCodes::INCORRECT_FILE_NAME); } } @@ -148,11 +150,10 @@ StorageFile::StorageFile(const std::string & table_path_, const std::string & us const std::string path = poco_path.absolute().toString(); if (path.find_first_of("*?{") == std::string::npos) - { paths.push_back(path); - } else paths = listFilesWithRegexpMatching("/", path); + for (const auto & cur_path : paths) checkCreationIsAllowed(args.context, user_files_absolute_path, cur_path); } @@ -369,8 +370,6 @@ void StorageFile::rename(const String & new_path_to_table_data, const String & n void StorageFile::truncate(const ASTPtr & /*query*/, const Context & /* context */, TableStructureWriteLockHolder &) { - /// NOTE: It will throw exception if the file is not created yet. - if (paths.size() != 1) throw Exception("Can't truncate table '" + table_name + "' in readonly mode", ErrorCodes::DATABASE_ACCESS_DENIED); @@ -383,6 +382,9 @@ void StorageFile::truncate(const ASTPtr & /*query*/, const Context & /* context } else { + if (!Poco::File(paths[0]).exists()) + return; + if (0 != ::truncate(paths[0].c_str(), 0)) throwFromErrnoWithPath("Cannot truncate file " + paths[0], paths[0], ErrorCodes::CANNOT_TRUNCATE_FILE); }