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 CommandMove final : public ICommand
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
|
|
|
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)")(
|
2024-06-14 13:02:41 +00:00
|
|
|
"path-to", po::value<String>(), "path to which we copy (mandatory, positional)")s;
|
2024-05-27 11:44:45 +00:00
|
|
|
positional_options_description.add("path-from", 1);
|
|
|
|
positional_options_description.add("path-to", 1);
|
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-06-14 13:02:41 +00:00
|
|
|
auto disk = getDiskWithPath(client, options, "disk");
|
2022-04-08 07:52:16 +00:00
|
|
|
|
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"));
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
if (disk.getDisk()->isFile(path_from))
|
2024-05-28 13:17:49 +00:00
|
|
|
disk.getDisk()->moveFile(path_from, path_to);
|
2022-04-08 07:52:16 +00:00
|
|
|
else
|
2024-05-28 13:17:49 +00:00
|
|
|
disk.getDisk()->moveDirectory(path_from, path_to);
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-27 11:44:45 +00:00
|
|
|
CommandPtr makeCommandMove()
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
|
|
|
return std::make_unique<DB::CommandMove>();
|
|
|
|
}
|
2024-05-27 11:44:45 +00:00
|
|
|
|
|
|
|
}
|