- check disk free space on Linuxes
This commit is contained in:
parent
086581a2b1
commit
2986655930
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#if defined(TARGET_LINUX) || defined(TARGET_OSX)
|
||||
# include <unistd.h>
|
||||
# include <sys/statvfs.h>
|
||||
# include <memory.h>
|
||||
#endif
|
||||
|
||||
bool FileHelper::exists(const std::string& s)
|
||||
|
|
@ -88,3 +90,18 @@ std::string FileHelper::mergePathes(const std::string& s1, const std::string& s2
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns free space on volume for path
|
||||
size_t FileHelper::getFreespace(const std::string& path)
|
||||
{
|
||||
size_t r = static_cast<size_t>(-1);
|
||||
|
||||
#if defined(TARGET_LINUX)
|
||||
struct statvfs stats; memset(&stats, 0, sizeof stats);
|
||||
|
||||
int retcode = statvfs(path.c_str(), &stats);
|
||||
if (retcode == 0)
|
||||
r = stats.f_bfree * stats.f_bsize;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ public:
|
|||
|
||||
static std::string addTrailingSlash(const std::string& s);
|
||||
static std::string mergePathes(const std::string& s1, const std::string& s2);
|
||||
|
||||
// Returns free space on volume for path
|
||||
// Works for Linux only. For other systems (size_t)-1 is returned (for errors too)
|
||||
static size_t getFreespace(const std::string& path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue