From 864fb92bc777fa2b8bbd2340e9b2e5fe64430ab3 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Thu, 12 May 2016 23:34:08 +0200 Subject: [PATCH] #205: new option "HistoryCleanupDisk" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … extracted from “DeleteCleanupDisk”. --- daemon/main/Options.cpp | 3 +++ daemon/main/Options.h | 2 ++ daemon/postprocess/PrePostProcessor.cpp | 2 +- daemon/queue/HistoryCoordinator.cpp | 2 +- daemon/queue/QueueEditor.cpp | 19 +++++++++---------- nzbget.conf | 25 ++++++++++++++++--------- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/daemon/main/Options.cpp b/daemon/main/Options.cpp index 7ef59b3f..674e378c 100644 --- a/daemon/main/Options.cpp +++ b/daemon/main/Options.cpp @@ -111,6 +111,7 @@ static const char* OPTION_PARPAUSEQUEUE = "ParPauseQueue"; static const char* OPTION_SCRIPTPAUSEQUEUE = "ScriptPauseQueue"; static const char* OPTION_NZBCLEANUPDISK = "NzbCleanupDisk"; static const char* OPTION_DELETECLEANUPDISK = "DeleteCleanupDisk"; +static const char* OPTION_HISTORYCLEANUPDISK = "HistoryCleanupDisk"; static const char* OPTION_PARTIMELIMIT = "ParTimeLimit"; static const char* OPTION_KEEPHISTORY = "KeepHistory"; static const char* OPTION_ACCURATERATE = "AccurateRate"; @@ -470,6 +471,7 @@ void Options::InitDefaults() SetOption(OPTION_SCRIPTPAUSEQUEUE, "no"); SetOption(OPTION_NZBCLEANUPDISK, "no"); SetOption(OPTION_DELETECLEANUPDISK, "no"); + SetOption(OPTION_HISTORYCLEANUPDISK, "no"); SetOption(OPTION_PARTIMELIMIT, "0"); SetOption(OPTION_KEEPHISTORY, "7"); SetOption(OPTION_ACCURATERATE, "no"); @@ -724,6 +726,7 @@ void Options::InitOptions() m_scriptPauseQueue = (bool)ParseEnumValue(OPTION_SCRIPTPAUSEQUEUE, BoolCount, BoolNames, BoolValues); m_nzbCleanupDisk = (bool)ParseEnumValue(OPTION_NZBCLEANUPDISK, BoolCount, BoolNames, BoolValues); m_deleteCleanupDisk = (bool)ParseEnumValue(OPTION_DELETECLEANUPDISK, BoolCount, BoolNames, BoolValues); + m_historyCleanupDisk = (bool)ParseEnumValue(OPTION_HISTORYCLEANUPDISK, BoolCount, BoolNames, BoolValues); m_accurateRate = (bool)ParseEnumValue(OPTION_ACCURATERATE, BoolCount, BoolNames, BoolValues); m_secureControl = (bool)ParseEnumValue(OPTION_SECURECONTROL, BoolCount, BoolNames, BoolValues); m_unpack = (bool)ParseEnumValue(OPTION_UNPACK, BoolCount, BoolNames, BoolValues); diff --git a/daemon/main/Options.h b/daemon/main/Options.h index a3ccfcfd..1fcaafc7 100644 --- a/daemon/main/Options.h +++ b/daemon/main/Options.h @@ -257,6 +257,7 @@ public: bool GetScriptPauseQueue() { return m_scriptPauseQueue; } bool GetNzbCleanupDisk() { return m_nzbCleanupDisk; } bool GetDeleteCleanupDisk() { return m_deleteCleanupDisk; } + bool GetHistoryCleanupDisk() { return m_historyCleanupDisk; } int GetParTimeLimit() { return m_parTimeLimit; } int GetKeepHistory() { return m_keepHistory; } bool GetAccurateRate() { return m_accurateRate; } @@ -402,6 +403,7 @@ private: bool m_scriptPauseQueue = false; bool m_nzbCleanupDisk = false; bool m_deleteCleanupDisk = false; + bool m_historyCleanupDisk = false; int m_parTimeLimit = 0; int m_keepHistory = 0; bool m_accurateRate = false; diff --git a/daemon/postprocess/PrePostProcessor.cpp b/daemon/postprocess/PrePostProcessor.cpp index d2e96231..b5897545 100644 --- a/daemon/postprocess/PrePostProcessor.cpp +++ b/daemon/postprocess/PrePostProcessor.cpp @@ -287,7 +287,7 @@ void PrePostProcessor::NzbCompleted(DownloadQueue* downloadQueue, NzbInfo* nzbIn void PrePostProcessor::DeleteCleanup(NzbInfo* nzbInfo) { - if ((g_Options->GetDeleteCleanupDisk() && nzbInfo->GetCleanupDisk()) || + if (nzbInfo->GetCleanupDisk() || nzbInfo->GetDeleteStatus() == NzbInfo::dsDupe) { // download was cancelled, deleting already downloaded files from disk diff --git a/daemon/queue/HistoryCoordinator.cpp b/daemon/queue/HistoryCoordinator.cpp index 31947aab..75bfb78d 100644 --- a/daemon/queue/HistoryCoordinator.cpp +++ b/daemon/queue/HistoryCoordinator.cpp @@ -292,7 +292,7 @@ void HistoryCoordinator::HistoryDelete(DownloadQueue* downloadQueue, HistoryList } if (historyInfo->GetKind() == HistoryInfo::hkNzb && - g_Options->GetDeleteCleanupDisk() && + g_Options->GetHistoryCleanupDisk() && (historyInfo->GetNzbInfo()->GetDeleteStatus() != NzbInfo::dsNone || historyInfo->GetNzbInfo()->GetParStatus() == NzbInfo::psFailure || historyInfo->GetNzbInfo()->GetUnpackStatus() == NzbInfo::usFailure || diff --git a/daemon/queue/QueueEditor.cpp b/daemon/queue/QueueEditor.cpp index e1f79e69..78fda477 100644 --- a/daemon/queue/QueueEditor.cpp +++ b/daemon/queue/QueueEditor.cpp @@ -1029,17 +1029,13 @@ void QueueEditor::SetNzbName(NzbInfo* nzbInfo, const char* name) } /** -* Check if deletion of already downloaded files is possible (when nzb id deleted from queue). -* The deletion is most always possible, except the case if all remaining files in queue -* (belonging to this nzb-file) are PARS. +* Check if deletion of already downloaded files is possible when nzb is deleted from queue. */ bool QueueEditor::CanCleanupDisk(NzbInfo* nzbInfo) { - if (nzbInfo->GetDeleteStatus() != NzbInfo::dsNone) - { - return true; - } + // Special case: deletion is not possible if all remaining files are PARS. + bool onlyPars = true; for (FileInfo* fileInfo : nzbInfo->GetFileList()) { BString<1024> loFileName = fileInfo->GetFilename(); @@ -1048,11 +1044,14 @@ bool QueueEditor::CanCleanupDisk(NzbInfo* nzbInfo) if (!strstr(loFileName, ".par2")) { // non-par file found - return true; + onlyPars = false; } } - return false; + bool canCleanup = (g_Options->GetDeleteCleanupDisk() && nzbInfo->GetDeleteStatus() != NzbInfo::dsNone) || + (!onlyPars && nzbInfo->GetSuccessArticles() == 0); + + return canCleanup; } bool QueueEditor::CanPark(NzbInfo* nzbInfo) @@ -1075,7 +1074,7 @@ bool QueueEditor::MergeGroups(ItemList* itemList) EditItem& destItem = itemList->front(); - for (EditItem& item : itemList) + for (EditItem& item : itemList) { if (item.m_nzbInfo != destItem.m_nzbInfo) { diff --git a/nzbget.conf b/nzbget.conf index 6cbfd901..b254dd62 100644 --- a/nzbget.conf +++ b/nzbget.conf @@ -552,7 +552,7 @@ Category4.Name=Software # # + - declares a positive term. Terms are positive by default, # the "+" can be omitted; -# - - declares a negative term. If the term succeed the feed +# - - declares a negative term. If the term succeeds the feed # item is ignored; # field - field to which apply the term. If not specified # the default field "title" is used; @@ -899,17 +899,24 @@ AccurateRate=no DiskSpace=250 # Delete already downloaded files from disk when nzb-file is deleted -# (yes, no). +# from queue (yes, no). # -# This option defines if downloaded files must be deleted when: -# 1) download of nzb-file is cancelled (deleted from queue); -# 2) history record with failure-status (par-failure or unpack-failure) -# is deleted from history. +# This option defines if downloaded files must be deleted when an +# nzb-file is deleted from queue, either manually by user or +# automatically by health check. # # If the option is disabled the files remain on disk, including # partially downloaded files. For such downloads commands "Download # remaining files" and "Retry failed articles" are available in history. -DeleteCleanupDisk=yes +DeleteCleanupDisk=no + +# Delete already downloaded files from disk when history item is +# deleted (yes, no). +# +# This option defines if downloaded files must be deleted when a history +# record with failure-status (par-failure or unpack-failure) is deleted +# (or hidden) from history. +HistoryCleanupDisk=yes # Delete source nzb-file when it is not needed anymore (yes, no). # @@ -1253,7 +1260,7 @@ ParRename=yes # If option is set to "Auto" or "Force" this option defines # if the download must be repaired when needed. The option can be # disabled if a computer does not have enough CPU power, since repairing -# may take too many resources and time on a slow computers. +# may consume too many resources and time on a slow computer. ParRepair=yes # What files should be scanned during par-verification (limited, extended, @@ -1803,7 +1810,7 @@ ScanScript= # # In addition to these arguments NZBGet passes all nzbget.conf-options # to the script as environment variables. These variables have prefix -# "NZBOP_" and are written in UPPER CASE. For Example option "ParRepair" +# "NZBOP_" and are written in UPPER CASE. For Example, the option "ParRepair" # is passed as environment variable "NZBOP_PARREPAIR". The dots in option # names are replaced with underscores, for example "SERVER1_HOST". For # options with predefined possible values (yes/no, etc.) the values are