|
12 | 12 | #include <Disks/ObjectStorages/ObjectStorageFactory.h> |
13 | 13 | #include <Poco/Util/MapConfiguration.h> |
14 | 14 | #include <IO/S3/URI.h> |
| 15 | +#include <filesystem> |
15 | 16 | #if USE_AWS_S3 |
16 | 17 | #include <Disks/ObjectStorages/S3/S3ObjectStorage.h> |
17 | 18 | #endif |
@@ -454,7 +455,39 @@ std::pair<DB::ObjectStoragePtr, std::string> resolveObjectStorageForPath( |
454 | 455 | endpoint.push_back('/'); |
455 | 456 | cfg->setString(config_prefix + ".endpoint", endpoint); |
456 | 457 | } |
457 | | - // No extra config needed for local storage (file://) |
| 458 | + else if (target_norm == "file") |
| 459 | + { |
| 460 | + // For file:// URIs, extract the directory path |
| 461 | + // file:///absolute/path/to/file -> path = /absolute/path/to/, key = /absolute/path/to/file (full path) |
| 462 | + std::string full_path = "/" + target.key; // Reconstruct full path |
| 463 | + std::filesystem::path fs_path(full_path); |
| 464 | + std::filesystem::path parent = fs_path.parent_path(); |
| 465 | + std::string dir_path = parent.string(); |
| 466 | + |
| 467 | + // Ensure directory path ends with / |
| 468 | + if (dir_path.empty() || dir_path == "/") |
| 469 | + { |
| 470 | + // Root directory |
| 471 | + dir_path = "/"; |
| 472 | + } |
| 473 | + else if (dir_path.back() != '/') |
| 474 | + { |
| 475 | + dir_path += '/'; |
| 476 | + } |
| 477 | + |
| 478 | + cfg->setString(config_prefix + ".path", dir_path); |
| 479 | + |
| 480 | + auto & factory = DB::ObjectStorageFactory::instance(); |
| 481 | + |
| 482 | + // Also use the cache key as a (unique) storage name |
| 483 | + DB::ObjectStoragePtr storage = factory.create(cache_key, *cfg, config_prefix, context, /*skip_access_check*/ true); |
| 484 | + |
| 485 | + secondary_storages.emplace(cache_key, storage); |
| 486 | + |
| 487 | + // For local storage, getObjectMetadata expects the full path, not just the filename |
| 488 | + // Return the full absolute path as the key |
| 489 | + return {storage, full_path}; |
| 490 | + } |
458 | 491 |
|
459 | 492 | auto & factory = DB::ObjectStorageFactory::instance(); |
460 | 493 |
|
|
0 commit comments