Fix path to files in MetadataStorageFromPlainObjectStorage

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2022-10-24 19:39:02 +02:00
parent 742d9af397
commit f6d0c03ee5
2 changed files with 14 additions and 10 deletions

View File

@ -33,10 +33,14 @@ const std::string & MetadataStorageFromPlainObjectStorage::getPath() const
{
return object_storage_root_path;
}
std::filesystem::path MetadataStorageFromPlainObjectStorage::getAbsolutePath(const std::string & path) const
{
return fs::path(object_storage_root_path) / path;
}
bool MetadataStorageFromPlainObjectStorage::exists(const std::string & path) const
{
auto object = StoredObject::create(*object_storage, fs::path(object_storage_root_path) / path);
auto object = StoredObject::create(*object_storage, getAbsolutePath(path));
return object_storage->exists(object);
}
@ -48,7 +52,7 @@ bool MetadataStorageFromPlainObjectStorage::isFile(const std::string & path) con
bool MetadataStorageFromPlainObjectStorage::isDirectory(const std::string & path) const
{
std::string directory = path;
std::string directory = getAbsolutePath(path);
trimRight(directory);
directory += "/";
@ -77,7 +81,7 @@ time_t MetadataStorageFromPlainObjectStorage::getLastChanged(const std::string &
uint64_t MetadataStorageFromPlainObjectStorage::getFileSize(const String & path) const
{
RelativePathsWithSize children;
object_storage->listPrefix(path, children);
object_storage->listPrefix(getAbsolutePath(path), children);
if (children.empty())
return 0;
if (children.size() != 1)
@ -88,7 +92,7 @@ uint64_t MetadataStorageFromPlainObjectStorage::getFileSize(const String & path)
std::vector<std::string> MetadataStorageFromPlainObjectStorage::listDirectory(const std::string & path) const
{
RelativePathsWithSize children;
object_storage->listPrefix(path, children);
object_storage->listPrefix(getAbsolutePath(path), children);
std::vector<std::string> result;
for (const auto & path_size : children)
@ -120,11 +124,8 @@ std::unordered_map<String, String> MetadataStorageFromPlainObjectStorage::getSer
StoredObjects MetadataStorageFromPlainObjectStorage::getStorageObjects(const std::string & path) const
{
std::string blob_name = object_storage->generateBlobNameForPath(path);
std::string object_path = fs::path(object_storage_root_path) / blob_name;
size_t object_size = getFileSize(object_path);
auto object = StoredObject::create(*object_storage, object_path, object_size, /* exists */true);
size_t object_size = getFileSize(blob_name);
auto object = StoredObject::create(*object_storage, getAbsolutePath(blob_name), object_size, /* exists */true);
return {std::move(object)};
}
@ -150,7 +151,7 @@ void MetadataStorageFromPlainObjectStorageTransaction::setLastModified(const std
void MetadataStorageFromPlainObjectStorageTransaction::unlinkFile(const std::string & path)
{
auto object = StoredObject::create(*metadata_storage.object_storage, fs::path(metadata_storage.object_storage_root_path) / path);
auto object = StoredObject::create(*metadata_storage.object_storage, metadata_storage.getAbsolutePath(path));
metadata_storage.object_storage->removeObject(object);
}

View File

@ -70,6 +70,9 @@ public:
StoredObjects getStorageObjects(const std::string & path) const override;
std::string getObjectStorageRootPath() const override { return object_storage_root_path; }
private:
std::filesystem::path getAbsolutePath(const std::string & path) const;
};
class MetadataStorageFromPlainObjectStorageTransaction final : public IMetadataTransaction