2022-07-20 20:30:16 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2024-05-27 11:44:45 +00:00
|
|
|
#include "ICommand.h"
|
2022-04-08 07:52:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-12-08 17:20:54 +00:00
|
|
|
class CommandLink final : public ICommand
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CommandLink()
|
|
|
|
{
|
|
|
|
command_name = "link";
|
2023-08-29 12:25:04 +00:00
|
|
|
description = "Create hardlink from `from_path` to `to_path`";
|
2024-05-27 11:44:45 +00:00
|
|
|
options_description.add_options()(
|
2024-07-04 14:09:43 +00:00
|
|
|
"path-from", po::value<String>(), "the path from which a hard link will be created (mandatory, positional)")(
|
|
|
|
"path-to", po::value<String>(), "the path where a hard link will be created (mandatory, positional)");
|
2024-05-27 11:44:45 +00:00
|
|
|
positional_options_description.add("path-from", 1);
|
|
|
|
positional_options_description.add("path-to", 1);
|
2022-06-21 14:40:22 +00:00
|
|
|
}
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
void executeImpl(const CommandLineOptions & options, DisksClient & client) override
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
2024-10-15 16:24:06 +00:00
|
|
|
const auto & disk = client.getCurrentDiskWithPath();
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
const String & path_from = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-from"));
|
|
|
|
const String & path_to = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-to"));
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
disk.getDisk()->createHardLink(path_from, path_to);
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
CommandPtr makeCommandLink()
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
2024-07-01 17:35:07 +00:00
|
|
|
return std::make_shared<DB::CommandLink>();
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
}
|