Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#162: combining free space on all paths of "DestDir"
Browse files Browse the repository at this point in the history
1) When checking free space (option “DiskSpace”) the total free size of
directories in “DestDir” is checked;
2) Web-interface shows the total free size of all directories.
  • Loading branch information
hugbug committed Jan 31, 2016
1 parent ec87c3c commit 00d8179
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
8 changes: 2 additions & 6 deletions daemon/main/DiskService.cpp
Expand Up @@ -60,14 +60,10 @@ void DiskService::ServiceWork()

void DiskService::CheckDiskSpace()
{
CString firstDestDir = g_Options->GetDestDir();
// Taking the first path from the list
if (char* p = strpbrk(firstDestDir, ";,")) *p = '\0';

int64 freeSpace = FileSystem::FreeDiskSize(firstDestDir);
int64 freeSpace = FileSystem::FreeDiskSize(Util::SplitStr(g_Options->GetDestDir(), ";,"));
if (freeSpace > -1 && freeSpace / 1024 / 1024 < g_Options->GetDiskSpace())
{
warn("Low disk space on %s. Pausing download", *firstDestDir);
warn("Low disk space on %s. Pausing download", g_Options->GetDestDir());
g_Options->SetPauseDownload(true);
}

Expand Down
7 changes: 1 addition & 6 deletions daemon/remote/XmlRpc.cpp
Expand Up @@ -1347,12 +1347,7 @@ void StatusXmlCommand::Execute()
Util::SplitInt64(allBytes, &downloadedSizeHi, &downloadedSizeLo);
int averageDownloadRate = (int)(downloadTimeSec > 0 ? allBytes / downloadTimeSec : 0);
uint32 freeDiskSpaceHi, freeDiskSpaceLo;

CString firstDestDir = g_Options->GetDestDir();
// Taking the first path from the list
if (char* p = strpbrk(firstDestDir, ";,")) *p = '\0';
int64 freeDiskSpace = FileSystem::FreeDiskSize(firstDestDir);

int64 freeDiskSpace = FileSystem::FreeDiskSize(Util::SplitStr(g_Options->GetDestDir(), ";,"));
Util::SplitInt64(freeDiskSpace, &freeDiskSpaceHi, &freeDiskSpaceLo);
int freeDiskSpaceMB = (int)(freeDiskSpace / 1024 / 1024);
int serverTime = Util::CurrentTime();
Expand Down
10 changes: 10 additions & 0 deletions daemon/util/FileSystem.cpp
Expand Up @@ -597,6 +597,16 @@ int64 FileSystem::FreeDiskSize(const char* path)
return -1;
}

int64 FileSystem::FreeDiskSize(std::vector<CString> paths)
{
int64 total = 0;
for (CString& path : paths)
{
total += FreeDiskSize(path);
}
return total;
}

bool FileSystem::RenameBak(const char* filename, const char* bakPart, bool removeOldExtension, CString& newName)
{
BString<1024> changedFilename;
Expand Down
1 change: 1 addition & 0 deletions daemon/util/FileSystem.h
Expand Up @@ -59,6 +59,7 @@ class FileSystem
static bool SetCurrentDirectory(const char* dirFilename);
static int64 FileSize(const char* filename);
static int64 FreeDiskSize(const char* path);
static int64 FreeDiskSize(std::vector<CString> paths);
static bool DirEmpty(const char* dirFilename);
static bool RenameBak(const char* filename, const char* bakPart, bool removeOldExtension, CString& newName);
#ifndef WIN32
Expand Down
11 changes: 11 additions & 0 deletions daemon/util/Util.cpp
Expand Up @@ -424,6 +424,17 @@ char* Util::ReduceStr(char* str, const char* from, const char* to)
return str;
}

std::vector<CString> Util::SplitStr(const char* str, const char* separators)
{
std::vector<CString> result;
Tokenizer tok(str, separators);
while (const char* substr = tok.Next())
{
result.emplace_back(substr);
}
return result;
}

/* Calculate Hash using Bob Jenkins (1996) algorithm
* http://burtleburtle.net/bob/c/lookup2.c
*/
Expand Down
1 change: 1 addition & 0 deletions daemon/util/Util.h
Expand Up @@ -60,6 +60,7 @@ class Util
static void TrimRight(char* str);
static char* Trim(char* str);
static bool EmptyStr(const char* str) { return !str || !*str; }
static std::vector<CString> SplitStr(const char* str, const char* separators);

/* replace all occurences of szFrom to szTo in string szStr with a limitation that szTo must be shorter than szFrom */
static char* ReduceStr(char* str, const char* from, const char* to);
Expand Down
3 changes: 1 addition & 2 deletions nzbget.conf
Expand Up @@ -885,8 +885,7 @@ AccurateRate=no
# Disk space is checked for directories pointed by option <DestDir> and
# option <InterDir>.
#
# If <DestDir> contains multiple directories only the first directory is
# checked.
# If <DestDir> contains multiple directories their free sizes are added.
#
# Value "0" disables the check.
DiskSpace=250
Expand Down

0 comments on commit 00d8179

Please sign in to comment.