-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Expand file tree
/
Copy pathCommandTouch.cpp
More file actions
49 lines (44 loc) · 1.54 KB
/
CommandTouch.cpp
File metadata and controls
49 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <Interpreters/Context.h>
#include <Common/TerminalSize.h>
#include <DisksApp.h>
#include <DisksClient.h>
#include <ICommand.h>
#include <Common/logger_useful.h>
namespace DB
{
class CommandTouch final : public ICommand
{
public:
explicit CommandTouch() : ICommand("CommandTouch")
{
command_name = "touch";
description = "Create a file by path";
options_description.add_options()("path", po::value<String>(), "the path of listing (mandatory, positional)");
positional_options_description.add("path", 1);
}
void executeImpl(const CommandLineOptions & options, DisksClient & client) override
{
const auto & disk = client.getCurrentDiskWithPath();
String path = getValueFromCommandLineOptionsThrow<String>(options, "path");
const auto & disk_impl = disk.getDisk();
const auto & relative_path = disk.getRelativeFromRoot(path);
if (disk_impl->existsFile(relative_path))
{
LOG_WARNING(&Poco::Logger::get("CommandTouch"), "File already exists at path: {}", relative_path);
}
else if (disk_impl->existsDirectory(relative_path))
{
LOG_WARNING(&Poco::Logger::get("CommandTouch"), "Directory already exists at path: {}", relative_path);
}
else
{
LOG_INFO(&Poco::Logger::get("CommandTouch"), "Creating file at path: {}", relative_path);
disk_impl->createFile(relative_path);
}
}
};
CommandPtr makeCommandTouch()
{
return std::make_shared<DB::CommandTouch>();
}
}