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-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/freespacechecker.h>7#include <qt/guiutil.h>8#include <util/fs.h>10#include <QDir>11#include <QString>13#include <cstdint>15void FreespaceChecker::check()16{17QString dataDirStr = intro->getPathToCheck();18fs::path dataDir = GUIUtil::QStringToPath(dataDirStr);19uint64_t freeBytesAvailable = 0;20int replyStatus = ST_OK;21QString replyMessage = tr("A new data directory will be created.");23/* Find first parent that exists, so that fs::space does not fail */24fs::path parentDir = dataDir;25fs::path parentDirOld = fs::path();26while(parentDir.has_parent_path() && !fs::exists(parentDir))27{28parentDir = parentDir.parent_path();30/* Check if we make any progress, break if not to prevent an infinite loop here */31if (parentDirOld == parentDir)32break;34parentDirOld = parentDir;35}37try {38freeBytesAvailable = fs::space(parentDir).available;39if(fs::exists(dataDir))40{41if(fs::is_directory(dataDir))42{43QString separator = "<code>" + QDir::toNativeSeparators("/") + tr("name") + "</code>";44replyStatus = ST_OK;45replyMessage = tr("Directory already exists. Add %1 if you intend to create a new directory here.").arg(separator);46} else {47replyStatus = ST_ERROR;48replyMessage = tr("Path already exists, and is not a directory.");49}50}51} catch (const fs::filesystem_error&)52{53/* Parent directory does not exist or is not accessible */54replyStatus = ST_ERROR;55replyMessage = tr("Cannot create data directory here.");56}57Q_EMIT reply(replyStatus, replyMessage, freeBytesAvailable);58}
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.