#pragma once #include #include #include #include #include #include #include #include #include #include namespace fs = std::filesystem; namespace DB { std::vector split(const String & text, const String & delimiters); using ProgramOptionsDescription = boost::program_options::options_description; using CommandLineOptions = boost::program_options::variables_map; class DiskWithPath { public: explicit DiskWithPath(DiskPtr disk_, std::optional path_ = std::nullopt); String getAbsolutePath(const String & any_path) const { return normalizePath(fs::path(path) / any_path); } String getCurrentPath() const { return path; } bool isDirectory(const String & any_path) const { return disk->isDirectory(getRelativeFromRoot(any_path)) || (getRelativeFromRoot(any_path).empty() && (disk->isDirectory("/"))); } std::vector listAllFilesByPath(const String & any_path) const; std::vector getAllFilesByPattern(const String & pattern) const; DiskPtr getDisk() const { return disk; } void setPath(const String & any_path); String getRelativeFromRoot(const String & any_path) const { return normalizePathAndGetAsRelative(getAbsolutePath(any_path)); } private: static String validatePathAndGetAsRelative(const String & path); static std::string normalizePathAndGetAsRelative(const std::string & messyPath); static std::string normalizePath(const std::string & messyPath); const DiskPtr disk; String path; }; class DisksClient { public: explicit DisksClient(std::vector>> && disks_with_paths, std::optional begin_disk); const DiskWithPath & getDiskWithPath(const String & disk) const; DiskWithPath & getDiskWithPath(const String & disk); const DiskWithPath & getCurrentDiskWithPath() const; DiskWithPath & getCurrentDiskWithPath(); DiskPtr getCurrentDisk() const { return getCurrentDiskWithPath().getDisk(); } DiskPtr getDisk(const String & disk) const { return getDiskWithPath(disk).getDisk(); } void switchToDisk(const String & disk_, const std::optional & path_); std::vector getAllDiskNames() const; std::vector getAllFilesByPatternFromAllDisks(const String & pattern) const; private: void addDisk(DiskPtr disk_, const std::optional & path_); String current_disk; std::unordered_map disks; }; }