Skip to content

Commit eea96b2

Browse files
committed
works for file
1 parent 627bdbe commit eea96b2

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/Storages/ObjectStorage/Utils.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Disks/ObjectStorages/ObjectStorageFactory.h>
1313
#include <Poco/Util/MapConfiguration.h>
1414
#include <IO/S3/URI.h>
15+
#include <filesystem>
1516
#if USE_AWS_S3
1617
#include <Disks/ObjectStorages/S3/S3ObjectStorage.h>
1718
#endif
@@ -454,7 +455,39 @@ std::pair<DB::ObjectStoragePtr, std::string> resolveObjectStorageForPath(
454455
endpoint.push_back('/');
455456
cfg->setString(config_prefix + ".endpoint", endpoint);
456457
}
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+
}
458491

459492
auto & factory = DB::ObjectStorageFactory::instance();
460493

0 commit comments

Comments
 (0)