Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
freespacechecker.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#include <qt/guiutil.h>
8#include <util/fs.h>
9
10#include <QDir>
11#include <QString>
12
13#include <cstdint>
14
16{
18 fs::path dataDir = GUIUtil::QStringToPath(dataDirStr);
20 int replyStatus = ST_OK;
21 QString replyMessage = tr("A new data directory will be created.");
22
23 /* Find first parent that exists, so that fs::space does not fail */
24 fs::path parentDir = dataDir;
25 fs::path parentDirOld = fs::path();
26 while(parentDir.has_parent_path() && !fs::exists(parentDir))
27 {
28 parentDir = parentDir.parent_path();
29
30 /* Check if we make any progress, break if not to prevent an infinite loop here */
32 break;
33
35 }
36
37 try {
38 freeBytesAvailable = fs::space(parentDir).available;
39 if(fs::exists(dataDir))
40 {
41 if(fs::is_directory(dataDir))
42 {
43 QString separator = "<code>" + QDir::toNativeSeparators("/") + tr("name") + "</code>";
45 replyMessage = tr("Directory already exists. Add %1 if you intend to create a new directory here.").arg(separator);
46 } else {
48 replyMessage = 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 */
55 replyMessage = tr("Cannot create data directory here.");
56 }
58}
virtual QString getPathToCheck()=0
void reply(int status, const QString &message, quint64 available)
static bool exists(const path &p)
Definition fs.h:95
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
Definition guiutil.cpp:670
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73