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

Method executeImpl

programs/disks/CommandCopy.cpp:36–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 }
35
36 void executeImpl(const CommandLineOptions & options, DisksClient & client) override
37 {
38 auto disk_from = getDiskWithPath(client, options, "disk-from");
39 auto disk_to = getDiskWithPath(client, options, "disk-to");
40 String path_from = disk_from.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-from"));
41 String path_to = disk_to.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-to"));
42 bool recursive = options.contains("recursive");
43
44 if (disk_from.getDisk()->existsFile(path_from))
45 {
46 auto target_location = getTargetLocation(path_from, disk_to, path_to);
47 if (!disk_to.getDisk()->existsDirectory(target_location))
48 {
49 LOG_INFO(
50 log,
51 "Copying file from disk '{}', file path '{}' to disk '{}', file path '{}'",
52 disk_from.getDisk()->getName(),
53 path_from,
54 disk_to.getDisk()->getName(),
55 target_location);
56 disk_from.getDisk()->copyFile(
57 path_from,
58 *disk_to.getDisk(),
59 target_location,
60 /* read_settings= */ {},
61 /* write_settings= */ {},
62 /* cancellation_hook= */ {});
63 }
64 else
65 {
66 throw Exception(
67 ErrorCodes::BAD_ARGUMENTS, "cannot overwrite directory '{}' with non-directory '{}'", target_location, path_from);
68 }
69 }
70 else if (disk_from.getDisk()->existsDirectory(path_from))
71 {
72 if (!recursive)
73 {
74 throw Exception(ErrorCodes::BAD_ARGUMENTS, "--recursive not specified; omitting directory '{}'", path_from);
75 }
76 auto target_location = getTargetLocation(path_from, disk_to, path_to);
77
78 if (disk_to.getDisk()->existsFile(target_location))
79 {
80 throw Exception(ErrorCodes::BAD_ARGUMENTS, "cannot overwrite non-directory {} with directory {}", path_to, target_location);
81 }
82 if (!disk_to.getDisk()->existsDirectory(target_location))
83 {
84 disk_to.getDisk()->createDirectory(target_location);
85 }
86 LOG_INFO(
87 log,
88 "Copying directory content from disk '{}', directory path '{}' to disk '{}', directory path '{}'",
89 disk_from.getDisk()->getName(),
90 path_from,
91 disk_to.getDisk()->getName(),
92 target_location);
93

Callers

nothing calls this directly

Calls 10

getRelativeFromRootMethod · 0.80
ExceptionClass · 0.50
containsMethod · 0.45
existsFileMethod · 0.45
getDiskMethod · 0.45
existsDirectoryMethod · 0.45
getNameMethod · 0.45
copyFileMethod · 0.45
createDirectoryMethod · 0.45
copyDirectoryContentMethod · 0.45

Tested by

no test coverage detected