mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Change GetBlocksDir() to ArgsManager.GetBlocksDirPath().
This commit is contained in:
parent
83292e2a70
commit
b4190eff72
5 changed files with 43 additions and 40 deletions
|
@ -637,7 +637,7 @@ static void CleanupBlockRevFiles()
|
|||
// Remove the rev files immediately and insert the blk file paths into an
|
||||
// ordered map keyed by block file index.
|
||||
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
|
||||
fs::path blocksdir = GetBlocksDir();
|
||||
fs::path blocksdir = gArgs.GetBlocksDirPath();
|
||||
for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
|
||||
if (fs::is_regular_file(*it) &&
|
||||
it->path().filename().string().length() == 12 &&
|
||||
|
@ -919,7 +919,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
|||
InitWarning(warnings);
|
||||
}
|
||||
|
||||
if (!fs::is_directory(GetBlocksDir())) {
|
||||
if (!fs::is_directory(gArgs.GetBlocksDirPath())) {
|
||||
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
|
||||
}
|
||||
|
||||
|
@ -1759,8 +1759,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||
InitError(strprintf(_("Error: Disk space is low for %s"), GetDataDir()));
|
||||
return false;
|
||||
}
|
||||
if (!CheckDiskSpace(GetBlocksDir())) {
|
||||
InitError(strprintf(_("Error: Disk space is low for %s"), GetBlocksDir()));
|
||||
if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
|
||||
InitError(strprintf(_("Error: Disk space is low for %s"), gArgs.GetBlocksDirPath()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ QString ClientModel::dataDir() const
|
|||
|
||||
QString ClientModel::blocksDir() const
|
||||
{
|
||||
return GUIUtil::boostPathToQString(GetBlocksDir());
|
||||
return GUIUtil::boostPathToQString(gArgs.GetBlocksDirPath());
|
||||
}
|
||||
|
||||
void ClientModel::updateBanlist()
|
||||
|
|
|
@ -388,6 +388,32 @@ std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) co
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
const fs::path& ArgsManager::GetBlocksDirPath()
|
||||
{
|
||||
LOCK(cs_args);
|
||||
fs::path& path = m_cached_blocks_path;
|
||||
|
||||
// Cache the path to avoid calling fs::create_directories on every call of
|
||||
// this function
|
||||
if (!path.empty()) return path;
|
||||
|
||||
if (IsArgSet("-blocksdir")) {
|
||||
path = fs::system_complete(GetArg("-blocksdir", ""));
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
}
|
||||
} else {
|
||||
path = GetDataDirPath(false);
|
||||
}
|
||||
|
||||
path /= BaseParams().DataDir();
|
||||
path /= "blocks";
|
||||
fs::create_directories(path);
|
||||
path = StripRedundantLastElementsOfPath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
const fs::path& ArgsManager::GetDataDirPath(bool net_specific) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
|
@ -425,6 +451,7 @@ void ArgsManager::ClearDatadirPathCache()
|
|||
|
||||
m_cached_datadir_path = fs::path();
|
||||
m_cached_network_datadir_path = fs::path();
|
||||
m_cached_blocks_path = fs::path();
|
||||
}
|
||||
|
||||
std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
|
||||
|
@ -775,35 +802,6 @@ fs::path GetDefaultDataDir()
|
|||
#endif
|
||||
}
|
||||
|
||||
static fs::path g_blocks_path_cache_net_specific;
|
||||
static RecursiveMutex csPathCached;
|
||||
|
||||
const fs::path &GetBlocksDir()
|
||||
{
|
||||
LOCK(csPathCached);
|
||||
fs::path &path = g_blocks_path_cache_net_specific;
|
||||
|
||||
// Cache the path to avoid calling fs::create_directories on every call of
|
||||
// this function
|
||||
if (!path.empty()) return path;
|
||||
|
||||
if (gArgs.IsArgSet("-blocksdir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
}
|
||||
} else {
|
||||
path = GetDataDir(false);
|
||||
}
|
||||
|
||||
path /= BaseParams().DataDir();
|
||||
path /= "blocks";
|
||||
fs::create_directories(path);
|
||||
path = StripRedundantLastElementsOfPath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
const fs::path &GetDataDir(bool fNetSpecific)
|
||||
{
|
||||
return gArgs.GetDataDirPath(fNetSpecific);
|
||||
|
@ -818,7 +816,6 @@ bool CheckDataDirOption()
|
|||
void ClearDatadirCache()
|
||||
{
|
||||
gArgs.ClearDatadirPathCache();
|
||||
g_blocks_path_cache_net_specific = fs::path();
|
||||
}
|
||||
|
||||
fs::path GetConfigFile(const std::string& confPath)
|
||||
|
|
|
@ -91,8 +91,6 @@ void ReleaseDirectoryLocks();
|
|||
|
||||
bool TryCreateDirectories(const fs::path& p);
|
||||
fs::path GetDefaultDataDir();
|
||||
// The blocks directory is always net specific.
|
||||
const fs::path &GetBlocksDir();
|
||||
const fs::path &GetDataDir(bool fNetSpecific = true);
|
||||
// Return true if -datadir option points to a valid directory or is not specified.
|
||||
bool CheckDataDirOption();
|
||||
|
@ -200,6 +198,7 @@ protected:
|
|||
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
|
||||
bool m_accept_any_command GUARDED_BY(cs_args){true};
|
||||
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args);
|
||||
fs::path m_cached_blocks_path GUARDED_BY(cs_args);
|
||||
mutable fs::path m_cached_datadir_path GUARDED_BY(cs_args);
|
||||
mutable fs::path m_cached_network_datadir_path GUARDED_BY(cs_args);
|
||||
|
||||
|
@ -265,6 +264,13 @@ public:
|
|||
*/
|
||||
std::optional<const Command> GetCommand() const;
|
||||
|
||||
/**
|
||||
* Get blocks directory path
|
||||
*
|
||||
* @return Blocks path which is network specific
|
||||
*/
|
||||
const fs::path& GetBlocksDirPath();
|
||||
|
||||
/**
|
||||
* Get data directory path
|
||||
*
|
||||
|
|
|
@ -2204,7 +2204,7 @@ bool CChainState::FlushStateToDisk(
|
|||
// Write blocks and block index to disk.
|
||||
if (fDoFullFlush || fPeriodicWrite) {
|
||||
// Depend on nMinDiskSpace to ensure we can write block index
|
||||
if (!CheckDiskSpace(GetBlocksDir())) {
|
||||
if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
|
||||
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
|
||||
}
|
||||
{
|
||||
|
@ -3890,12 +3890,12 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
|
|||
|
||||
static FlatFileSeq BlockFileSeq()
|
||||
{
|
||||
return FlatFileSeq(GetBlocksDir(), "blk", gArgs.GetBoolArg("-fastprune", false) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
|
||||
return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", gArgs.GetBoolArg("-fastprune", false) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
static FlatFileSeq UndoFileSeq()
|
||||
{
|
||||
return FlatFileSeq(GetBlocksDir(), "rev", UNDOFILE_CHUNK_SIZE);
|
||||
return FlatFileSeq(gArgs.GetBlocksDirPath(), "rev", UNDOFILE_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly) {
|
||||
|
|
Loading…
Add table
Reference in a new issue