ClickHouse/programs/disks/CommandLink.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.2 KiB
C++
Raw Normal View History

2022-07-20 20:30:16 +00:00
#include <Interpreters/Context.h>
2024-05-27 11:44:45 +00:00
#include "ICommand.h"
namespace DB
{
class CommandLink final : public ICommand
{
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
}
2024-05-27 11:44:45 +00:00
void executeImpl(const CommandLineOptions & options, DisksClient & client) override
{
2024-10-15 16:24:06 +00:00
const auto & disk = client.getCurrentDiskWithPath();
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"));
2024-05-27 11:44:45 +00:00
disk.getDisk()->createHardLink(path_from, path_to);
}
};
2024-05-27 11:44:45 +00:00
CommandPtr makeCommandLink()
{
return std::make_shared<DB::CommandLink>();
}
2024-05-27 11:44:45 +00:00
}