[mythtv] [PATCH] Autoexpire blocked by missing file.
Nicholas McCoy
mccoyn at gmail.com
Thu Mar 10 22:55:23 UTC 2005
Here is my updated patch. In addition to the changes we discussed
earlier I created a new function, AutoExpire::SelectFile, which
contains the bulk of my changes.
On Wed, 9 Mar 2005 11:20:52 -0500, Nicholas McCoy <mccoyn at gmail.com> wrote:
> Thanks for the tips. I will rework it tonight so it fits better and
> send an updated version. I didn't realize the tabs were a problem,
> but now when I open the patch I see it has made a mess of things. I
> will clear that up.
>
> > Is there a reason for this, why not just set pginfo = NULL when
> > declared above?
>
> That will work. I orginally didn't have anything there and I got an
> warning saying possible use of unitialized value. I just added that
> line to get rid of the warning. NULL might be better.
>
> > Might want to make these VERBOSE calls VB_IMPORTANT.
>
> Can do. I copied the VERBOSE calls from another file, where the
> cannot delete file is reported before this patch. I also copied the
> LogEntry call, which may not be needed.
>
> > Do you really need this loop above? Can't you just use the "i" iterator
> > you were using above since that is pointing to the item we're expiring?
>
> I got an error because the "i" iterator is a reverse_iterator and
> erase() expects a forward iterator. I could be missing something
> here; I've spent the last couple of years in mostly C code so I'm a
> bit rusty. I think, at the very least I'll change it to use the
> std::advance() function to clean up the code a bit.
>
> Thanks for taking the time to look at it and provide comments.
>
-------------- next part --------------
? autoexpire.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 10 Mar 2005 00:38:24 -0000
@@ -4,6 +4,7 @@
#include <qregexp.h>
#include <qstring.h>
#include <qdatetime.h>
+#include <qfile.h>
#include <iostream>
#include <algorithm>
@@ -75,9 +76,14 @@
if ((freespace < minFree) &&
(expireList.size() > 0))
{
- // delete the "first" item on our list (really off the end)
- ProgramInfo *pginfo = expireList.back();
+ vector<ProgramInfo *>::iterator i;
+ ProgramInfo *pginfo;
+
+ i = SelectFile(recordfileprefix);
+ if (i != expireList.end())
+ {
+ pginfo = *i;
QString msg = QString("AutoExpiring: %1 %2 %3 MBytes")
.arg(pginfo->title)
.arg(pginfo->startts.toString())
@@ -93,7 +99,7 @@
gContext->dispatch(me);
delete pginfo;
- expireList.erase(expireList.end() - 1);
+ expireList.erase(i);
if (statfs(recordfileprefix.ascii(), &statbuf) == 0)
{
@@ -101,6 +107,7 @@
statbuf.f_bavail / (1024*1024*1024/statbuf.f_bsize);
}
}
+ }
if (freespace < minFree)
{
@@ -128,6 +135,58 @@
}
}
+
+vector<ProgramInfo *>::iterator
+ AutoExpire::SelectFile(const QString &recordfileprefix)
+{
+ // select the "first" valid item on our list (really off the end)
+ vector<ProgramInfo *>::iterator i;
+ bool done = false;
+
+ i = expireList.end() - 1;
+ while (!done)
+ {
+ QString filename = (*i)->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_IMPORTANT,
+ 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.begin()){
+ done = true;
+ i = expireList.end(); // No files found
+
+ // Couldn't find any autoexpire files.
+ VERBOSE(VB_IMPORTANT, 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 if (!done) {
+ i --;
+ }
+ }
+
+ return i;
+}
+
void *AutoExpire::ExpirerThread(void *param)
{
AutoExpire *expirer = (AutoExpire *)param;
Index: autoexpire.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/autoexpire.h,v
retrieving revision 1.4
diff -u -w -r1.4 autoexpire.h
--- autoexpire.h 23 Feb 2005 05:04:36 -0000 1.4
+++ autoexpire.h 10 Mar 2005 00:38:24 -0000
@@ -25,6 +25,9 @@
static void *ExpirerThread(void *param);
private:
+ vector<ProgramInfo *>::iterator
+ SelectFile (const QString &recordfileprefix);
+
void ClearExpireList(void);
void ExpireEpisodesOverMax(void);
More information about the mythtv-dev
mailing list