Fix out of bound error in disk web

This commit is contained in:
alesapin 2023-10-10 15:44:27 +02:00
parent 5ded0005a3
commit 37f5c445b4

View File

@ -162,7 +162,22 @@ bool WebObjectStorage::exists(const std::string & path) const
if (startsWith(it->first, path)
|| (it != files.begin() && startsWith(std::prev(it)->first, path)))
{
shared_lock.unlock();
std::unique_lock unique_lock(metadata_mutex);
/// The code relies on invariant that if this function returned true
/// the file exists in files.
/// In this case we have a directory which doesn't explicitly exists (like store/xxx/yyy)
/// ^^^^^
/// Adding it to the files
files.emplace(std::make_pair(path, FileData({.type = FileType::Directory})));
unique_lock.unlock();
shared_lock.lock();
return true;
}
return false;
}