mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Merge pull request #36088 from israelg99/fix_executable
Fix CH silently failing when it cannot execute a file
This commit is contained in:
commit
ca89af89a1
@ -234,6 +234,11 @@ bool createFile(const std::string & path)
|
||||
DB::throwFromErrnoWithPath("Cannot create file: " + path, path, DB::ErrorCodes::CANNOT_CREATE_FILE);
|
||||
}
|
||||
|
||||
bool exists(const std::string & path)
|
||||
{
|
||||
return faccessat(AT_FDCWD, path.c_str(), F_OK, AT_EACCESS) == 0;
|
||||
}
|
||||
|
||||
bool canRead(const std::string & path)
|
||||
{
|
||||
struct stat st;
|
||||
@ -249,7 +254,6 @@ bool canRead(const std::string & path)
|
||||
DB::throwFromErrnoWithPath("Cannot check read access to file: " + path, path, DB::ErrorCodes::PATH_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
|
||||
bool canWrite(const std::string & path)
|
||||
{
|
||||
struct stat st;
|
||||
@ -265,6 +269,13 @@ bool canWrite(const std::string & path)
|
||||
DB::throwFromErrnoWithPath("Cannot check write access to file: " + path, path, DB::ErrorCodes::PATH_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
bool canExecute(const std::string & path)
|
||||
{
|
||||
if (exists(path))
|
||||
return faccessat(AT_FDCWD, path.c_str(), X_OK, AT_EACCESS) == 0;
|
||||
DB::throwFromErrnoWithPath("Cannot check execute access to file: " + path, path, DB::ErrorCodes::PATH_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
time_t getModificationTime(const std::string & path)
|
||||
{
|
||||
struct stat st;
|
||||
|
@ -70,8 +70,10 @@ namespace FS
|
||||
{
|
||||
bool createFile(const std::string & path);
|
||||
|
||||
bool exists(const std::string & path);
|
||||
bool canRead(const std::string & path);
|
||||
bool canWrite(const std::string & path);
|
||||
bool canExecute(const std::string & path);
|
||||
|
||||
time_t getModificationTime(const std::string & path);
|
||||
Poco::Timestamp getModificationTimestamp(const std::string & path);
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <base/logger_useful.h>
|
||||
#include <Common/LocalDateTime.h>
|
||||
#include <Common/filesystemHelpers.h>
|
||||
#include <Common/ShellCommand.h>
|
||||
|
||||
#include <Processors/Sources/ShellCommandSource.h>
|
||||
#include <Processors/Sources/SourceFromSingleChunk.h>
|
||||
@ -15,12 +14,10 @@
|
||||
|
||||
#include <Interpreters/Context.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
|
||||
#include <Dictionaries/DictionarySourceFactory.h>
|
||||
#include <Dictionaries/DictionarySourceHelpers.h>
|
||||
#include <Dictionaries/DictionaryStructure.h>
|
||||
#include <Dictionaries/registerDictionaries.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -51,12 +48,18 @@ namespace
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
if (!std::filesystem::exists(std::filesystem::path(script_path)))
|
||||
if (!FS::exists(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} does not exist inside user scripts folder {}",
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
if (!FS::canExecute(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} is not executable inside user scripts folder {}",
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
command = std::move(script_path);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <base/logger_useful.h>
|
||||
#include <Common/LocalDateTime.h>
|
||||
#include <Common/filesystemHelpers.h>
|
||||
#include <Common/ShellCommand.h>
|
||||
|
||||
#include <Processors/Formats/IOutputFormat.h>
|
||||
#include <Processors/Sources/ShellCommandSource.h>
|
||||
@ -20,7 +19,6 @@
|
||||
#include <Dictionaries/DictionarySourceHelpers.h>
|
||||
#include <Dictionaries/DictionaryStructure.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -113,12 +111,18 @@ Pipe ExecutablePoolDictionarySource::getStreamForBlock(const Block & block)
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
if (!std::filesystem::exists(std::filesystem::path(script_path)))
|
||||
if (!FS::exists(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} does not exist inside user scripts folder {}",
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
if (!FS::canExecute(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} is not executable inside user scripts folder {}",
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
command = std::move(script_path);
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include <Common/filesystemHelpers.h>
|
||||
|
||||
#include <IO/WriteHelpers.h>
|
||||
|
||||
#include <Processors/Sources/ShellCommandSource.h>
|
||||
#include <Processors/Sources/SourceFromSingleChunk.h>
|
||||
#include <Formats/formatBlock.h>
|
||||
@ -78,12 +76,18 @@ public:
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
if (!std::filesystem::exists(std::filesystem::path(script_path)))
|
||||
if (!FS::exists(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} does not exist inside user scripts folder {}",
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
if (!FS::canExecute(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} is not executable inside user scripts folder {}",
|
||||
command,
|
||||
user_scripts_path);
|
||||
|
||||
command = std::move(script_path);
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,19 @@
|
||||
#include <Storages/StorageExecutable.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
#include <Common/ShellCommand.h>
|
||||
#include <Common/filesystemHelpers.h>
|
||||
|
||||
#include <Core/Block.h>
|
||||
|
||||
#include <IO/ReadHelpers.h>
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ASTSelectWithUnionQuery.h>
|
||||
#include <Parsers/ASTCreateQuery.h>
|
||||
|
||||
#include <QueryPipeline/Pipe.h>
|
||||
#include <Processors/ISimpleTransform.h>
|
||||
#include <Processors/Executors/CompletedPipelineExecutor.h>
|
||||
#include <Processors/Formats/IOutputFormat.h>
|
||||
#include <Processors/Sources/SourceFromSingleChunk.h>
|
||||
@ -123,12 +121,18 @@ Pipe StorageExecutable::read(
|
||||
script_name,
|
||||
user_scripts_path);
|
||||
|
||||
if (!std::filesystem::exists(std::filesystem::path(script_path)))
|
||||
if (!FS::exists(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} does not exist inside user scripts folder {}",
|
||||
script_name,
|
||||
user_scripts_path);
|
||||
|
||||
if (!FS::canExecute(script_path))
|
||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD,
|
||||
"Executable file {} is not executable inside user scripts folder {}",
|
||||
script_name,
|
||||
user_scripts_path);
|
||||
|
||||
Pipes inputs;
|
||||
inputs.reserve(input_queries.size());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user