Ticket #7731: delay_unlink.patch

File delay_unlink.patch, 1.8 KB (added by stichnot@…, 12 years ago)
  • programs/mythtranscode/main.cpp

     
    816816    return unlink(filename.toLocal8Bit().constData());
    817817}
    818818
     819void WaitToDelete(ProgramInfo *pginfo)
     820{
     821    VERBOSE(VB_GENERAL,
     822            "Transcode: delete old file: "
     823            "waiting while program is in use.");
     824    unsigned inUse = 1;
     825    MSqlQuery query(MSqlQuery::InitCon());
     826    while (inUse)
     827    {
     828        query.prepare("SELECT count(*) FROM inuseprograms "
     829                      "WHERE chanid = :CHANID "
     830                      "AND starttime = :STARTTIME "
     831                      "AND recusage != 'jobqueue' ;");
     832        query.bindValue(":CHANID", pginfo->chanid);
     833        query.bindValue(":STARTTIME", pginfo->recstartts);
     834        if (!query.exec() || !query.next())
     835        {
     836            VERBOSE(VB_GENERAL,
     837                    "Transcode: delete old file: in-use query failed;");
     838            VERBOSE(VB_GENERAL,
     839                    "    proceeding with delete of old file.");
     840            return;
     841        }
     842        inUse = query.value(0).toUInt();
     843        if (inUse)
     844        {
     845            unsigned secondsToWait = 10;
     846            VERBOSE(VB_GENERAL,
     847                    QString("Transcode: program in use, "
     848                            "rechecking in %1 seconds.").arg(secondsToWait));
     849            sleep(secondsToWait);
     850        }
     851    }
     852    VERBOSE(VB_GENERAL, "Transcode: program is no longer in use.");
     853}
     854
    819855void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)
    820856{
    821857    int status = JobQueue::GetJobStatus(jobID);
     
    871907
    872908        if (!gContext->GetNumSetting("SaveTranscoding", 0))
    873909        {
     910            WaitToDelete(pginfo);
    874911            int err;
    875912            bool followLinks = gContext->GetNumSetting("DeletesFollowLinks", 0);
    876913