Joseph A. Caputo wrote:

On Thursday 03 November 2005 21:51, Michael T. Dean wrote:
I was looking for a way to derive the basename from the pathname even in the situation where the basename contains directory information (allowing recordings to be stored in subdirectories of the recordings directory). So, just taking the filename doesn't work.
Sorry to come late to the party...

No problem.  The more the merrier...

IIUC, you have a pathname and you want to somehow determine which part of it is the basename (which may or may not include an arbitrary number of levels tail-end directories). Do I have that correct? Is the pathname you're parsing an absolute path? If so I have some ideas...
It's the pathname field in the ProgramInfo class, and, specifically, the use of it to derive a basename on line 1222.

http://svn.mythtv.org/trac/browser/trunk/mythtv/libs/libmythtv/programinfo.cpp?rev=7720#L1217

The current code assumes that the basename is the filename at the end of pathname. However--like you said--I would like for it to allow the inclusion of "an arbitrary number of levels" of subdirectory information (to allow for grouping of recordings, or--more importantly--the use of multiple filesystems for storage of recordings (although it does require manually moving the files after recording).

AIUI, the pathname may be an absolute path /or/ may be a "myth://" path. Therefore, and because of the possibility of multiple RecordFilePrefixes when using multiple backends, we can't just strip the RecordFilePrefix. We could check for "myth://" and if not there, attempt to strip all possible RecordFilePrefixes but that would not be very elegant and would likely require querying the DB (which defeats the purpose of deriving the basename from pathname in the first place). And, even if we did this, we wouldn't be handling the situation where the pathname is a "myth://" path, so files in subdirectories that were recorded by remote backends would always be streamed--even if they're available through a network filesystem.

The only "sure-fire" approaches I can think of are to a) add an explicit basename field to ProgramInfo in addition to the pathname field or b) disable the code that derives basename from pathname and query the DB every time GetRecordBasename is called. I've done b) in my tree and it seems to work quite well, but I wasn't willing to call it "ready for primetime," so I was hoping for some dialog. It may also have an effect on videos not recorded by Myth, but I haven't looked into that (and I don't use the Internal player for my non-Myth videos).

Also, I want to ensure that this doesn't cause any additional security concerns over the current solution. Bruce had some concerns about this, but I don't think the extent of the change was obvious, since at the point he replied, most of the information about the the proposed change was spread out over several posts in the thread--and I never explicitly asked, "is there a way to derive basename from pathname if we allow subdirectory information in basenames?" I think he may have thought I was proposing the use of an absolute pathname, instead, and I completely agree this would be a major security problem. We've had part of a dialog offline, but he hasn't yet replied to my reply from yesterday. However, the approach he proposed is significantly better than mine, and he indicated he has some code already. See http://www.gossamer-threads.com/lists/mythtv/dev/158425#158425 .

Attached is a patch that shows b) (but doesn't fix indentation to make the true extent of the change more obvious). Sorry if this post is too long, but I'm trying to group together much of the information that's spread throughout this thread.

Mike
Index: libs/libmythtv/programinfo.cpp
===================================================================
--- libs/libmythtv/programinfo.cpp      (revision 7682)
+++ libs/libmythtv/programinfo.cpp      (working copy)
@@ -1218,10 +1218,6 @@
 {
     QString retval = "";
 
-    if (!pathname.isEmpty())
-        retval = pathname.section('/', -1);
-    else
-    {
         MSqlQuery query(MSqlQuery::InitCon());
         query.prepare("SELECT basename FROM recorded "
                       "WHERE chanid = :CHANID AND "
@@ -1238,7 +1234,6 @@
             query.next();
             retval = query.value(0).toString();
         }
-    }
 
     return retval;
 }               
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

Reply via email to