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

Commit

Permalink
#371: respect PostStrategy when starting another direct unpack
Browse files Browse the repository at this point in the history
to avoid running way too many direct unpack jobs at the same time.
  • Loading branch information
hugbug committed Jun 6, 2017
1 parent 53da572 commit 5dcca72
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
20 changes: 20 additions & 0 deletions daemon/postprocess/DirectUnpack.cpp
Expand Up @@ -143,6 +143,11 @@ void DirectUnpack::Run()
}

AddExtraTime(nzbInfo);

if (nzbInfo->GetPostInfo())
{
nzbInfo->GetPostInfo()->SetWorking(false);
}
}

debug("Exiting DirectUnpack-loop for %i", m_nzbId);
Expand Down Expand Up @@ -402,6 +407,10 @@ void DirectUnpack::Stop(DownloadQueue* downloadQueue, NzbInfo* nzbInfo)
}
}
AddExtraTime(nzbInfo);
if (nzbInfo->GetPostInfo())
{
nzbInfo->GetPostInfo()->SetWorking(false);
}
Thread::Stop();
if (m_unpacking)
{
Expand Down Expand Up @@ -524,3 +533,14 @@ void DirectUnpack::AddExtraTime(NzbInfo* nzbInfo)
m_extraStartTime = 0;
}
}

bool DirectUnpack::IsArchiveFilename(const char* filename)
{
if (Util::EndsWith(filename, ".rar", false))
{
return true;
}

RegEx regExRarMultiSeq(".*\\.[r-z][0-9][0-9]$");
return regExRarMultiSeq.Match(filename);
}
1 change: 1 addition & 0 deletions daemon/postprocess/DirectUnpack.h
Expand Up @@ -35,6 +35,7 @@ class DirectUnpack : public Thread, public ScriptController
void FileDownloaded(DownloadQueue* downloadQueue, FileInfo* fileInfo);
void NzbDownloaded(DownloadQueue* downloadQueue, NzbInfo* nzbInfo);
void NzbDeleted(DownloadQueue* downloadQueue, NzbInfo* nzbInfo);
static bool IsArchiveFilename(const char* filename);

protected:
virtual bool ReadLine(char* buf, int bufSize, FILE* stream);
Expand Down
17 changes: 11 additions & 6 deletions daemon/postprocess/PrePostProcessor.cpp
Expand Up @@ -325,6 +325,8 @@ void PrePostProcessor::NzbDownloaded(DownloadQueue* downloadQueue, NzbInfo* nzbI

if (nzbInfo->GetUnpackThread())
{
nzbInfo->GetPostInfo()->SetWorking(true);
m_activeJobs.push_back(nzbInfo);
((DirectUnpack*)nzbInfo->GetUnpackThread())->NzbDownloaded(downloadQueue, nzbInfo);
}

Expand Down Expand Up @@ -878,6 +880,11 @@ bool PrePostProcessor::PostQueueDelete(DownloadQueue* downloadQueue, IdList* idL
postInfo->GetPostThread()->Stop();
ok = true;
}
else if (postInfo->GetNzbInfo()->GetUnpackThread())
{
((DirectUnpack*)postInfo->GetNzbInfo()->GetUnpackThread())->NzbDeleted(downloadQueue, postInfo->GetNzbInfo());
ok = true;
}
else
{
error("Internal error in PrePostProcessor::QueueDelete");
Expand All @@ -888,11 +895,6 @@ bool PrePostProcessor::PostQueueDelete(DownloadQueue* downloadQueue, IdList* idL
postInfo->GetNzbInfo()->PrintMessage(Message::mkInfo,
"Deleting queued post-job %s", postInfo->GetNzbInfo()->GetName());

if (postInfo->GetNzbInfo()->GetUnpackThread())
{
((DirectUnpack*)postInfo->GetNzbInfo()->GetUnpackThread())->NzbDeleted(downloadQueue, postInfo->GetNzbInfo());
}

JobCompleted(downloadQueue, postInfo);

m_activeJobs.erase(std::remove_if(m_activeJobs.begin(), m_activeJobs.end(),
Expand Down Expand Up @@ -926,7 +928,10 @@ void PrePostProcessor::FileDownloaded(DownloadQueue* downloadQueue, NzbInfo* nzb

if (g_Options->GetDirectUnpack() && g_Options->GetDecode())
{
if (nzbInfo->GetDirectUnpackStatus() == NzbInfo::nsNone)
bool allowPar;
if (nzbInfo->GetDirectUnpackStatus() == NzbInfo::nsNone &&
DirectUnpack::IsArchiveFilename(fileInfo->GetFilename()) &&
CanRunMoreJobs(&allowPar))
{
NzbParameter* unpackParameter = nzbInfo->GetParameters()->Find("*Unpack:", false);
bool wantUnpack = !(unpackParameter && !strcasecmp(unpackParameter->GetValue(), "no"));
Expand Down

0 comments on commit 5dcca72

Please sign in to comment.