Fixed test

This commit is contained in:
Alexey Milovidov 2020-01-05 23:11:26 +03:00
parent 5620fb1561
commit 31f4fd0e4b

View File

@ -64,11 +64,13 @@ static std::vector<std::string> listFilesWithRegexpMatching(const std::string &
const std::string suffix_with_globs = for_match.substr(end_of_path_without_globs); /// begin with '/' 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); 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<std::string> result; std::vector<std::string> result;
const std::string prefix_without_globs = path_for_ls + for_match.substr(1, end_of_path_without_globs); 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; return result;
} }
@ -113,11 +115,11 @@ static void checkCreationIsAllowed(const Context & context_global, const std::st
/// "/dev/null" is allowed for perf testing /// "/dev/null" is allowed for perf testing
if (!startsWith(table_path, db_dir_path) && table_path != "/dev/null") 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); Poco::File table_path_poco_file = Poco::File(table_path);
if (table_path_poco_file.exists() && table_path_poco_file.isDirectory()) 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(); const std::string path = poco_path.absolute().toString();
if (path.find_first_of("*?{") == std::string::npos) if (path.find_first_of("*?{") == std::string::npos)
{
paths.push_back(path); paths.push_back(path);
}
else else
paths = listFilesWithRegexpMatching("/", path); paths = listFilesWithRegexpMatching("/", path);
for (const auto & cur_path : paths) for (const auto & cur_path : paths)
checkCreationIsAllowed(args.context, user_files_absolute_path, cur_path); 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 &) 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) if (paths.size() != 1)
throw Exception("Can't truncate table '" + table_name + "' in readonly mode", ErrorCodes::DATABASE_ACCESS_DENIED); 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 else
{ {
if (!Poco::File(paths[0]).exists())
return;
if (0 != ::truncate(paths[0].c_str(), 0)) if (0 != ::truncate(paths[0].c_str(), 0))
throwFromErrnoWithPath("Cannot truncate file " + paths[0], paths[0], ErrorCodes::CANNOT_TRUNCATE_FILE); throwFromErrnoWithPath("Cannot truncate file " + paths[0], paths[0], ErrorCodes::CANNOT_TRUNCATE_FILE);
} }