diff --git a/src/storage/v2/durability/durability.cpp b/src/storage/v2/durability/durability.cpp index 4bd4e9d39..1f1052528 100644 --- a/src/storage/v2/durability/durability.cpp +++ b/src/storage/v2/durability/durability.cpp @@ -74,6 +74,12 @@ std::vector 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) { diff --git a/src/storage/v2/durability/snapshot.cpp b/src/storage/v2/durability/snapshot.cpp index 4a65731db..61c159c99 100644 --- a/src/storage/v2/durability/snapshot.cpp +++ b/src/storage/v2/durability/snapshot.cpp @@ -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" diff --git a/src/utils/file.cpp b/src/utils/file.cpp index 96fa0763e..7be907428 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -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 must fit into ssize_t!"); InputFile::~InputFile() { Close(); } diff --git a/src/utils/file.hpp b/src/utils/file.hpp index 5e1345742..f40e1f3da 100644 --- a/src/utils/file.hpp +++ b/src/utils/file.hpp @@ -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,