Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#include "db/filename.h"7#include "db/dbformat.h"8#include "port/port.h"9#include "util/logging.h"10#include "util/testharness.h"12namespace leveldb {14class FileNameTest {};16TEST(FileNameTest, Parse) {17Slice db;18FileType type;19uint64_t number;21// Successful parses22static struct {23const char* fname;24uint64_t number;25FileType type;26} cases[] = {27{"100.log", 100, kLogFile},28{"0.log", 0, kLogFile},29{"0.sst", 0, kTableFile},30{"0.ldb", 0, kTableFile},31{"CURRENT", 0, kCurrentFile},32{"LOCK", 0, kDBLockFile},33{"MANIFEST-2", 2, kDescriptorFile},34{"MANIFEST-7", 7, kDescriptorFile},35{"LOG", 0, kInfoLogFile},36{"LOG.old", 0, kInfoLogFile},37{"18446744073709551615.log", 18446744073709551615ull, kLogFile},38};39for (int i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {40std::string f = cases[i].fname;41ASSERT_TRUE(ParseFileName(f, &number, &type)) << f;42ASSERT_EQ(cases[i].type, type) << f;43ASSERT_EQ(cases[i].number, number) << f;44}46// Errors47static const char* errors[] = {"",48"foo",49"foo-dx-100.log",50".log",51"",52"manifest",53"CURREN",54"CURRENTX",55"MANIFES",56"MANIFEST",57"MANIFEST-",58"XMANIFEST-3",59"MANIFEST-3x",60"LOC",61"LOCKx",62"LO",63"LOGx",64"18446744073709551616.log",65"184467440737095516150.log",66"100",67"100.",68"100.lop"};69for (int i = 0; i < sizeof(errors) / sizeof(errors[0]); i++) {70std::string f = errors[i];71ASSERT_TRUE(!ParseFileName(f, &number, &type)) << f;72}73}75TEST(FileNameTest, Construction) {76uint64_t number;77FileType type;78std::string fname;80fname = CurrentFileName("foo");81ASSERT_EQ("foo/", std::string(fname.data(), 4));82ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));83ASSERT_EQ(0, number);84ASSERT_EQ(kCurrentFile, type);86fname = LockFileName("foo");87ASSERT_EQ("foo/", std::string(fname.data(), 4));88ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));89ASSERT_EQ(0, number);90ASSERT_EQ(kDBLockFile, type);92fname = LogFileName("foo", 192);93ASSERT_EQ("foo/", std::string(fname.data(), 4));94ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));95ASSERT_EQ(192, number);96ASSERT_EQ(kLogFile, type);98fname = TableFileName("bar", 200);99ASSERT_EQ("bar/", std::string(fname.data(), 4));100ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));101ASSERT_EQ(200, number);102ASSERT_EQ(kTableFile, type);104fname = DescriptorFileName("bar", 100);105ASSERT_EQ("bar/", std::string(fname.data(), 4));106ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));107ASSERT_EQ(100, number);108ASSERT_EQ(kDescriptorFile, type);110fname = TempFileName("tmp", 999);111ASSERT_EQ("tmp/", std::string(fname.data(), 4));112ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));113ASSERT_EQ(999, number);114ASSERT_EQ(kTempFile, type);116fname = InfoLogFileName("foo");117ASSERT_EQ("foo/", std::string(fname.data(), 4));118ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));119ASSERT_EQ(0, number);120ASSERT_EQ(kInfoLogFile, type);122fname = OldInfoLogFileName("foo");123ASSERT_EQ("foo/", std::string(fname.data(), 4));124ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));125ASSERT_EQ(0, number);126ASSERT_EQ(kInfoLogFile, type);127}129} // namespace leveldb131int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.