Add check for opening snapshots (#966)

This commit is contained in:
Ante Javor 2023-06-22 13:29:49 +02:00 committed by GitHub
parent da17fe92d6
commit 0ea96663ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 2 deletions

View File

@ -74,6 +74,12 @@ std::vector<SnapshotDurabilityInfo> GetSnapshotFiles(const std::filesystem::path
if (utils::DirExists(snapshot_directory)) {
for (const auto &item : std::filesystem::directory_iterator(snapshot_directory, error_code)) {
if (!item.is_regular_file()) continue;
if (!utils::HasReadAccess(item.path())) {
spdlog::warn(
"Skipping snapshot file '{}' because it is not readable, check file ownership and read permissions!",
item.path());
continue;
}
try {
auto info = ReadSnapshotInfo(item.path());
if (uuid.empty() || info.uuid == uuid) {

View File

@ -26,6 +26,7 @@
#include "storage/v2/vertex.hpp"
#include "storage/v2/vertex_accessor.hpp"
#include "utils/concepts.hpp"
#include "utils/file.hpp"
#include "utils/file_locker.hpp"
#include "utils/logging.hpp"
#include "utils/message.hpp"

View File

@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -82,6 +82,8 @@ bool RenamePath(const std::filesystem::path &src, const std::filesystem::path &d
return !error_code;
}
bool HasReadAccess(const std::filesystem::path &path) { return access(path.c_str(), R_OK) == 0; }
static_assert(std::is_same_v<off_t, ssize_t>, "off_t must fit into ssize_t!");
InputFile::~InputFile() { Close(); }

View File

@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -63,6 +63,9 @@ bool CopyFile(const std::filesystem::path &src, const std::filesystem::path &dst
/// don't exist, the renaming fails. Symlinks are not followed.
bool RenamePath(const std::filesystem::path &src, const std::filesystem::path &dst);
/// Checks if process has read access to the file.
bool HasReadAccess(const std::filesystem::path &path);
/// Buffer size used for `InputFile` and `OutputFile` implementations. Using
/// system calls is very expensive and we can't afford to call either `read` or
/// `write` for each of our (very small) logical reads/writes. Because of that,