aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJim Posen <jim.posen@gmail.com>2018-09-01 15:18:02 -0700
committerJim Posen <jim.posen@gmail.com>2019-02-22 17:38:45 -0800
commit62e7addb632cad77cbd5fbccbaee51c7b32505d0 (patch)
treed1251329ff8b5fc6dd6c85a0fdee883d66736f0e /src/util
parentf3f9c1de19e6d254e0c3a26ce7a3d8cd57fb7641 (diff)
downloadbitcoin-62e7addb632cad77cbd5fbccbaee51c7b32505d0.tar.xz
util: Move CheckDiskSpace to util.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/system.cpp8
-rw-r--r--src/util/system.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 6e82de743a..3e6c2ae5d4 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -135,6 +135,14 @@ bool DirIsWritable(const fs::path& directory)
return true;
}
+bool CheckDiskSpace(const fs::path& dir, uint64_t nAdditionalBytes)
+{
+ constexpr uint64_t nMinDiskSpace = 52428800; // 50 MiB
+
+ uint64_t nFreeBytesAvailable = fs::space(dir).available;
+ return nFreeBytesAvailable >= nMinDiskSpace + nAdditionalBytes;
+}
+
/**
* Interpret a string argument as a boolean.
*
diff --git a/src/util/system.h b/src/util/system.h
index 69ae11d1ed..2a2ee9bc1d 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -72,6 +72,7 @@ bool RenameOver(fs::path src, fs::path dest);
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
bool DirIsWritable(const fs::path& directory);
+bool CheckDiskSpace(const fs::path& dir, uint64_t nAdditionalBytes = 0);
/** Release all directory locks. This is used for unit testing only, at runtime
* the global destructor will take care of the locks.