[mythtv] [PATCH] Autoexpire blocked by missing file.

Nicholas McCoy mccoyn at gmail.com
Sun Mar 6 00:18:34 UTC 2005


This is my first patch so please forgive and correct my missteps.

This problem resulted from corrupted database tables.  Some recording
entries couldn't be deleted for some reason.  The first time the
auto-expire code tries to delete one of these it deletes the file, but
doesn't delete the database record (I think.)  After that, it tries to
delete the file again, but always fails, preventing the auto-expire
code from doing any meaningful work.

This patch will check to make sure a file exists before it will
attempt to delete it.  If it doesn't exist, it will try to find
another file to delete.

This doesn't fix the problem of a corrupt table, but it does prevent
the problem from blocking the auto-expire code.

I used "cvs diff -uw >autoexpire-file-not-found.patch" to create the patch.
-------------- next part --------------
? autoexpire-file-not-found.patch
Index: autoexpire.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/autoexpire.cpp,v
retrieving revision 1.21
diff -u -w -r1.21 autoexpire.cpp
--- autoexpire.cpp	23 Feb 2005 05:04:36 -0000	1.21
+++ autoexpire.cpp	6 Mar 2005 00:09:22 -0000
@@ -4,6 +4,7 @@
 #include <qregexp.h>
 #include <qstring.h>
 #include <qdatetime.h>
+#include <qfile.h>
 
 #include <iostream>
 #include <algorithm>
@@ -76,8 +77,46 @@
                 (expireList.size() > 0))
             {
                 // delete the "first" item on our list (really off the end)
-                ProgramInfo *pginfo = expireList.back();
+				vector<ProgramInfo *>::reverse_iterator i;
+				ProgramInfo *pginfo;
+				bool done = false;
+
+				pginfo = *(expireList.rend()); // error condition
+				for (i = expireList.rbegin(); (!done) && (i != expireList.rend()); i++)
+				{
+					pginfo = *i;
+					QString filename = pginfo->GetRecordFilename(recordfileprefix);
+					QFile checkFile(filename);
+
+					if (checkFile.exists())
+					{
+						// This file should work.  No need to look further.
+						done = true;
+					}
+					else
+					{
+						// Couldn't find the file.  Delete would probally fail, so find another file.
+						VERBOSE(VB_ALL, QString("ERROR when trying to autoexpire file: %1. File "
+												"doesn't exist.  Database metadata"
+												"will not be removed.")
+												.arg(filename));
+						gContext->LogEntry("mythbackend", LP_WARNING, "Autoexpire Recording",
+										QString("File %1 does not exist when trying "
+												"to autoexpire recording.")
+												.arg(filename));
+					}
+				}
 
+				if (i == expireList.rend())
+				{
+					// Couldn't find any autoexpire files.
+					VERBOSE(VB_ALL, QString("ERROR when trying to autoexpire files.  "
+											"Could not find any files to expire."));
+					gContext->LogEntry("mythbackend", LP_WARNING, "Autoexpire Recording",
+									QString("Could not find any files to expire."));
+				}
+				else
+				{
                 QString msg = QString("AutoExpiring: %1 %2 %3 MBytes")
                                       .arg(pginfo->title)
                                       .arg(pginfo->startts.toString())
@@ -92,8 +131,14 @@
                 MythEvent me(message);
                 gContext->dispatch(me);
 
+					vector<ProgramInfo *>::iterator forward_iterator;					
+					for (forward_iterator = expireList.begin();
+						(forward_iterator != expireList.end()) && (*forward_iterator != pginfo);
+						forward_iterator++)
+					{}
+
                 delete pginfo;
-                expireList.erase(expireList.end() - 1);
+					expireList.erase(forward_iterator);
 
                 if (statfs(recordfileprefix.ascii(), &statbuf) == 0)
                 {
@@ -101,6 +146,7 @@
                         statbuf.f_bavail / (1024*1024*1024/statbuf.f_bsize);
                 }
             }
+            }
 
             if (freespace < minFree)
             {


More information about the mythtv-dev mailing list