fs::absolute to fs::canonical

This commit is contained in:
kssenii 2021-05-24 19:03:09 +03:00
parent 866b29fb5a
commit 31107816bb
8 changed files with 16 additions and 19 deletions

View File

@ -71,7 +71,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
// Set up two channel chains.
log_file = new Poco::FileChannel;
log_file->setProperty(Poco::FileChannel::PROP_PATH, fs::absolute(log_path));
log_file->setProperty(Poco::FileChannel::PROP_PATH, fs::weakly_canonical(log_path));
log_file->setProperty(Poco::FileChannel::PROP_ROTATION, config.getRawString("logger.size", "100M"));
log_file->setProperty(Poco::FileChannel::PROP_ARCHIVE, "number");
log_file->setProperty(Poco::FileChannel::PROP_COMPRESS, config.getRawString("logger.compress", "true"));
@ -103,7 +103,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
std::cerr << "Logging errors to " << errorlog_path << std::endl;
error_log_file = new Poco::FileChannel;
error_log_file->setProperty(Poco::FileChannel::PROP_PATH, fs::absolute(errorlog_path));
error_log_file->setProperty(Poco::FileChannel::PROP_PATH, fs::weakly_canonical(errorlog_path));
error_log_file->setProperty(Poco::FileChannel::PROP_ROTATION, config.getRawString("logger.size", "100M"));
error_log_file->setProperty(Poco::FileChannel::PROP_ARCHIVE, "number");
error_log_file->setProperty(Poco::FileChannel::PROP_COMPRESS, config.getRawString("logger.compress", "true"));

View File

@ -40,7 +40,7 @@ void ClusterCopierApp::initialize(Poco::Util::Application & self)
process_id = std::to_string(DateLUT::instance().toNumYYYYMMDDhhmmss(timestamp)) + "_" + std::to_string(curr_pid);
host_id = escapeForFileName(getFQDNOrHostName()) + '#' + process_id;
process_path = fs::absolute(fs::path(base_dir) / ("clickhouse-copier_" + process_id));
process_path = fs::weakly_canonical(fs::path(base_dir) / ("clickhouse-copier_" + process_id));
fs::create_directories(process_path);
/// Override variables for BaseDaemon

View File

@ -288,7 +288,7 @@ int mainEntryClickHouseInstall(int argc, char ** argv)
bool is_symlink = fs::is_symlink(symlink_path);
fs::path points_to;
if (is_symlink)
points_to = fs::absolute(fs::read_symlink(symlink_path));
points_to = fs::weakly_canonical(fs::read_symlink(symlink_path));
if (is_symlink && points_to == main_bin_path)
{

View File

@ -61,8 +61,8 @@ private:
class DiskLocalDirectoryIterator : public IDiskDirectoryIterator
{
public:
explicit DiskLocalDirectoryIterator(const fs::path & disk_path_, const String & dir_path_)
: dir_path(dir_path_), entry(disk_path_ / dir_path_)
explicit DiskLocalDirectoryIterator(const String & disk_path_, const String & dir_path_)
: dir_path(dir_path_), entry(fs::path(disk_path_) / dir_path_)
{
}
@ -196,7 +196,7 @@ void DiskLocal::moveDirectory(const String & from_path, const String & to_path)
DiskDirectoryIteratorPtr DiskLocal::iterateDirectory(const String & path)
{
return std::make_unique<DiskLocalDirectoryIterator>(fs::path(disk_path), path);
return std::make_unique<DiskLocalDirectoryIterator>(disk_path, path);
}
void DiskLocal::moveFile(const String & from_path, const String & to_path)
@ -314,12 +314,9 @@ void DiskLocal::copy(const String & from_path, const std::shared_ptr<IDisk> & to
if (isSameDiskType(*this, *to_disk))
{
fs::path to = fs::path(to_disk->getPath()) / to_path;
fs::path from;
fs::path from = fs::path(disk_path) / from_path;
if (from_path.ends_with('/'))
from = fs::path(disk_path) / from_path.substr(0, from_path.size() - 1);
else
from = fs::path(disk_path) / from_path;
from = from.parent_path();
if (fs::is_directory(from))
to /= from.filename();

View File

@ -140,9 +140,9 @@ void StaticRequestHandler::writeResponse(WriteBuffer & out)
{
const auto & file_name = response_expression.substr(file_prefix.size(), response_expression.size() - file_prefix.size());
fs::path user_files_absolute_path = fs::absolute(fs::path(server.context()->getUserFilesPath()));
fs::path user_files_absolute_path = fs::canonical(fs::path(server.context()->getUserFilesPath()));
/// Fixme: it does not work with fs::path(user_files_absolute_path) / file_name
String file_path = fs::absolute(user_files_absolute_path.string() + "/" + file_name);
String file_path = fs::canonical(user_files_absolute_path.string() + "/" + file_name);
if (!fs::exists(file_path))
throw Exception("Invalid file name " + file_path + " for static HTTPHandler. ", ErrorCodes::INCORRECT_FILE_NAME);

View File

@ -652,8 +652,8 @@ void Fetcher::downloadBaseOrProjectionPartToDisk(
/// File must be inside "absolute_part_path" directory.
/// Otherwise malicious ClickHouse replica may force us to write to arbitrary path.
String absolute_file_path = fs::absolute(fs::path(part_download_path) / file_name);
if (!startsWith(absolute_file_path, fs::absolute(part_download_path).string()))
String absolute_file_path = fs::weakly_canonical(fs::path(part_download_path) / file_name);
if (!startsWith(absolute_file_path, fs::weakly_canonical(part_download_path).string()))
throw Exception("File path (" + absolute_file_path + ") doesn't appear to be inside part path (" + part_download_path + ")."
" This may happen if we are trying to download part from malicious replica or logical error.",
ErrorCodes::INSECURE_PATH);

View File

@ -4406,7 +4406,7 @@ PartitionCommandsResultInfo MergeTreeData::freezePartitionsByMatcher(
const String & with_name,
ContextPtr local_context)
{
String clickhouse_path = fs::absolute(local_context->getPath());
String clickhouse_path = fs::canonical(local_context->getPath());
String default_shadow_path = fs::path(clickhouse_path) / "shadow/";
fs::create_directories(default_shadow_path);
auto increment = Increment(fs::path(default_shadow_path) / "increment.txt").get(true);

View File

@ -129,13 +129,13 @@ void checkCreationIsAllowed(ContextPtr context_global, const std::string & db_di
Strings StorageFile::getPathsList(const String & table_path, const String & user_files_path, ContextPtr context)
{
fs::path user_files_absolute_path = fs::absolute(user_files_path);
fs::path user_files_absolute_path = fs::weakly_canonical(user_files_path);
fs::path fs_table_path(table_path);
if (fs_table_path.is_relative())
fs_table_path = user_files_absolute_path / fs_table_path;
Strings paths;
const String path = fs::absolute(fs_table_path);
const String path = fs::weakly_canonical(fs_table_path);
if (path.find_first_of("*?{") == std::string::npos)
paths.push_back(path);
else