MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeImpl

Method executeImpl

programs/disks/CommandRemove.cpp:27–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 }
26
27 void executeImpl(const CommandLineOptions & options, DisksClient & client) override
28 {
29 const auto & disk = client.getCurrentDiskWithPath();
30 const String & path = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path"));
31 bool recursive = options.contains("recursive");
32 if (disk.getDisk()->existsDirectory(path))
33 {
34 if (!recursive)
35 {
36 throw Exception(ErrorCodes::BAD_ARGUMENTS, "cannot remove '{}': Is a directory", path);
37 }
38
39 LOG_INFO(log, "Removing directory '{}' at disk '{}'", path, disk.getDisk()->getName());
40
41 disk.getDisk()->removeRecursiveWithLimit(path);
42 }
43 else if (disk.getDisk()->existsFile(path))
44 {
45 LOG_INFO(log, "Removing file '{}' at disk '{}'", path, disk.getDisk()->getName());
46 disk.getDisk()->removeFileIfExists(path);
47 }
48 else
49 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Path {} on disk {} doesn't exist", path, disk.getDisk()->getName());
50 }
51};
52
53CommandPtr makeCommandRemove()

Callers

nothing calls this directly

Calls 9

getRelativeFromRootMethod · 0.80
ExceptionClass · 0.50
containsMethod · 0.45
existsDirectoryMethod · 0.45
getDiskMethod · 0.45
getNameMethod · 0.45
existsFileMethod · 0.45
removeFileIfExistsMethod · 0.45

Tested by

no test coverage detected