ClickHouse/programs/disks/CommandMove.cpp

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

40 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 CommandMove final : public ICommand
{
public:
CommandMove()
{
command_name = "move";
2023-08-29 12:25:04 +00:00
description = "Move file or directory from `from_path` to `to_path`";
2024-05-27 11:44:45 +00:00
options_description.add_options()("path-from", po::value<String>(), "path from which we copy (mandatory, positional)")(
"path-to", po::value<String>(), "path to which we copy (mandatory, positional)");
positional_options_description.add("path-from", 1);
positional_options_description.add("path-to", 1);
}
2024-05-27 11:44:45 +00:00
void executeImpl(const CommandLineOptions & options, DisksClient & client) override
{
2024-05-27 11:44:45 +00:00
auto disk = client.getCurrentDiskWithPath();
2024-05-27 11:44:45 +00:00
String path_from = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-from"));
String path_to = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-to"));
2024-05-27 11:44:45 +00:00
if (disk.getDisk()->isFile(path_from))
disk.getDisk()->moveFile(path_from, path_from);
else
2024-05-27 11:44:45 +00:00
disk.getDisk()->moveDirectory(path_from, path_from);
}
};
2024-05-27 11:44:45 +00:00
CommandPtr makeCommandMove()
{
return std::make_unique<DB::CommandMove>();
}
2024-05-27 11:44:45 +00:00
}