Changeset View
Changeset View
Standalone View
Standalone View
src/flatfile.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2019 The Bitcoin Core developers | |||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <stdexcept> | #include <stdexcept> | ||||
#include <flatfile.h> | #include <flatfile.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <util.h> | #include <util.h> | ||||
FlatFileSeq::FlatFileSeq(fs::path dir, const char *prefix, size_t chunk_size) | FlatFileSeq::FlatFileSeq(fs::path dir, const char *prefix, size_t chunk_size) | ||||
: m_dir(std::move(dir)), m_prefix(prefix), m_chunk_size(chunk_size) { | : m_dir(std::move(dir)), m_prefix(prefix), m_chunk_size(chunk_size) { | ||||
if (chunk_size == 0) { | if (chunk_size == 0) { | ||||
throw std::invalid_argument("chunk_size must be positive"); | throw std::invalid_argument("chunk_size must be positive"); | ||||
} | } | ||||
} | } | ||||
std::string CDiskBlockPos::ToString() const { | |||||
return strprintf("CDiskBlockPos(nFile=%i, nPos=%i)", nFile, nPos); | |||||
} | |||||
fs::path FlatFileSeq::FileName(const CDiskBlockPos &pos) const { | fs::path FlatFileSeq::FileName(const CDiskBlockPos &pos) const { | ||||
return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile); | return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile); | ||||
} | } | ||||
FILE *FlatFileSeq::Open(const CDiskBlockPos &pos, bool fReadOnly) { | FILE *FlatFileSeq::Open(const CDiskBlockPos &pos, bool fReadOnly) { | ||||
if (pos.IsNull()) return nullptr; | if (pos.IsNull()) return nullptr; | ||||
fs::path path = FileName(pos); | fs::path path = FileName(pos); | ||||
fs::create_directories(path.parent_path()); | fs::create_directories(path.parent_path()); | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |