Ticket #3475: mythtv-mythfilldatabase_log_path_checks.patch

File mythtv-mythfilldatabase_log_path_checks.patch, 2.8 KB (added by sphery <mtdean@…>, 17 years ago)
  • programs/mythbackend/housekeeper.cpp

     
    77#include <qstring.h>
    88#include <qdatetime.h>
    99#include <qstringlist.h>
     10#include <qfileinfo.h>
    1011
    1112#include <iostream>
    1213using namespace std;
     
    302303    QString mfarg = gContext->GetSetting("MythFillDatabaseArgs", "");
    303304    QString mflog = gContext->GetSetting("MythFillDatabaseLog",
    304305                                         "/var/log/mythfilldatabase.log");
     306    bool logOutput = (!mflog.isEmpty());
    305307
    306308    if (mfpath == "mythfilldatabase")
    307309        mfpath = gContext->GetInstallPrefix() + "/bin/mythfilldatabase";
    308310
    309     if (mflog == "")
     311    if (logOutput)
     312    {
     313        QFileInfo testFile(mflog);
     314        if (testFile.exists())
     315        {
     316            // If the file or directory is not writable, disable logging
     317            if (!testFile.isWritable())
     318            {
     319                VERBOSE(VB_IMPORTANT,
     320                        QString("Invalid mythfilldatabase log path: %1 "
     321                                "is not writable.")
     322                                .arg(mflog));
     323                logOutput = false;
     324            }
     325            else if (testFile.isDir())
     326            {
     327                mflog.append("/mythfilldatabase.log");
     328                // Although the directory is writable, the new filename may
     329                // refer to an unwritable file
     330                testFile.setFile(mflog);
     331                if ((testFile.exists()) && (!testFile.isWritable()))
     332                {
     333                    VERBOSE(VB_IMPORTANT,
     334                            QString("Invalid mythfilldatabase log path: %1 "
     335                                    "is not writable.")
     336                                    .arg(mflog));
     337                    logOutput = false;
     338                }
     339            }
     340        }
     341        else
     342        {
     343            // The log file does not yet exist.  Verify the directory exists
     344            // and is writable.
     345            QString dir = testFile.dirPath();
     346            testFile.setFile(dir);
     347            if ((!testFile.exists()) || (!testFile.isWritable()))
     348            {
     349                VERBOSE(VB_IMPORTANT,
     350                        QString("Invalid mythfilldatabase log path: %1")
     351                                .arg(mflog));
     352                logOutput = false;
     353            }
     354        }
     355    }
     356
     357    if (logOutput)
     358        command = QString("%1 %2 >>%3 2>&1").arg(mfpath).arg(mfarg).arg(mflog);
     359    else
    310360        command = QString("%1 %2").arg(mfpath).arg(mfarg);
    311     else
    312         command = QString("%1 %2 >>%3 2>&1").arg(mfpath).arg(mfarg).arg(mflog);
    313361
    314362    myth_system(command.ascii(), MYTH_SYSTEM_DONT_BLOCK_LIRC |
    315363                                 MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU);