| 216 | } |
| 217 | |
| 218 | void performAtomicRename(const DB::ASTPtr & parsed_query, const String & out_file) |
| 219 | { |
| 220 | if (const auto * query_with_output = dynamic_cast<const DB::ASTQueryWithOutput *>(parsed_query.get())) |
| 221 | { |
| 222 | if (query_with_output->isOutfileTruncate() && query_with_output->out_file) |
| 223 | { |
| 224 | const auto & tmp_file_node = query_with_output->out_file->as<DB::ASTLiteral &>(); |
| 225 | String tmp_file = tmp_file_node.value.safeGet<std::string>(); |
| 226 | |
| 227 | try |
| 228 | { |
| 229 | fs::rename(tmp_file, out_file); |
| 230 | } |
| 231 | catch (const fs::filesystem_error & e) |
| 232 | { |
| 233 | /// Clean up temporary file |
| 234 | if (fs::exists(tmp_file)) |
| 235 | fs::remove(tmp_file); |
| 236 | |
| 237 | throw DB::Exception(DB::ErrorCodes::CANNOT_WRITE_TO_FILE, |
| 238 | "Cannot rename temporary file {} to {}: {}", |
| 239 | tmp_file, out_file, e.what()); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | } |
| 246 |
no test coverage detected