2024-05-27 11:44:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
#include <Client/ReplxxLineReader.h>
|
|
|
|
#include <Loggers/Loggers.h>
|
|
|
|
#include "Disks/IDisk.h"
|
|
|
|
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <boost/program_options/options_description.hpp>
|
|
|
|
#include <boost/program_options/variables_map.hpp>
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<String> split(const String & text, const String & delimiters);
|
|
|
|
|
|
|
|
using ProgramOptionsDescription = boost::program_options::options_description;
|
|
|
|
using CommandLineOptions = boost::program_options::variables_map;
|
|
|
|
|
|
|
|
class DiskWithPath
|
|
|
|
{
|
|
|
|
public:
|
2024-05-29 13:57:29 +00:00
|
|
|
explicit DiskWithPath(DiskPtr disk_, std::optional<String> path_ = std::nullopt);
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
String getAbsolutePath(const String & any_path) const { return normalizePath(fs::path(path) / any_path); }
|
|
|
|
|
|
|
|
String getCurrentPath() const { return path; }
|
|
|
|
|
2024-06-26 15:59:15 +00:00
|
|
|
bool isDirectory(const String & any_path) const
|
|
|
|
{
|
|
|
|
return disk->isDirectory(getRelativeFromRoot(any_path)) || (getRelativeFromRoot(any_path).empty() && (disk->isDirectory("/")));
|
|
|
|
}
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
std::vector<String> listAllFilesByPath(const String & any_path) const;
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-31 13:10:42 +00:00
|
|
|
std::vector<String> getAllFilesByPattern(const String & pattern) const;
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
DiskPtr getDisk() const { return disk; }
|
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
void setPath(const String & any_path);
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
String getRelativeFromRoot(const String & any_path) const { return normalizePathAndGetAsRelative(getAbsolutePath(any_path)); }
|
|
|
|
|
|
|
|
private:
|
2024-05-29 13:57:29 +00:00
|
|
|
static String validatePathAndGetAsRelative(const String & path);
|
|
|
|
static std::string normalizePathAndGetAsRelative(const std::string & messyPath);
|
|
|
|
static std::string normalizePath(const std::string & messyPath);
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
const DiskPtr disk;
|
|
|
|
String path;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DisksClient
|
|
|
|
{
|
|
|
|
public:
|
2024-05-29 13:57:29 +00:00
|
|
|
explicit DisksClient(std::vector<std::pair<DiskPtr, std::optional<String>>> && disks_with_paths, std::optional<String> begin_disk);
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
const DiskWithPath & getDiskWithPath(const String & disk) const;
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
DiskWithPath & getDiskWithPath(const String & disk);
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
const DiskWithPath & getCurrentDiskWithPath() const;
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
DiskWithPath & getCurrentDiskWithPath();
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
DiskPtr getCurrentDisk() const { return getCurrentDiskWithPath().getDisk(); }
|
|
|
|
|
|
|
|
DiskPtr getDisk(const String & disk) const { return getDiskWithPath(disk).getDisk(); }
|
|
|
|
|
2024-05-29 13:57:29 +00:00
|
|
|
void switchToDisk(const String & disk_, const std::optional<String> & path_);
|
|
|
|
|
|
|
|
std::vector<String> getAllDiskNames() const;
|
2024-05-27 11:44:45 +00:00
|
|
|
|
2024-05-31 13:10:42 +00:00
|
|
|
std::vector<String> getAllFilesByPatternFromAllDisks(const String & pattern) const;
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
2024-05-29 13:57:29 +00:00
|
|
|
void addDisk(DiskPtr disk_, const std::optional<String> & path_);
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
String current_disk;
|
|
|
|
std::unordered_map<String, DiskWithPath> disks;
|
|
|
|
};
|
|
|
|
}
|