diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2002-01-20 16:47:09 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2002-01-20 16:47:09 +0100 |
commit | 305abd449f33d3885d2167c05f33d3144ee05d15 (patch) | |
tree | 4540162e082ea1224d2c3a9d2ef1e2b6476aa496 | |
parent | fd839aae7b0a443db6f0eab59fcc93f03aafd0ba (diff) | |
download | vdr-305abd449f33d3885d2167c05f33d3144ee05d15.tar.gz vdr-305abd449f33d3885d2167c05f33d3144ee05d15.tar.bz2 |
Now using 'ftw()' instead of an external 'find' to collect recordings
-rw-r--r-- | CONTRIBUTORS | 3 | ||||
-rw-r--r-- | HISTORY | 3 | ||||
-rw-r--r-- | recording.c | 58 | ||||
-rw-r--r-- | recording.h | 3 | ||||
-rw-r--r-- | tools.c | 13 | ||||
-rw-r--r-- | tools.h | 3 |
6 files changed, 57 insertions, 26 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 7a077b69..38084be7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -175,3 +175,6 @@ Stephan Schreiber <stephan@sschreiber.de> Lauri Pesonen <lauri.pesonen@firsthop.com> for avoiding linking in 'libncurses' if compiling without DEBUG_OSD=1 and REMOTE=KBD + +Emil Naepflein <Emil.Naepflein@philosys.de> + for his hint about the 'ftw()' library function @@ -900,3 +900,6 @@ Video Disk Recorder Revision History subdirectories for the recordings. This can be controlled through the "RecordingDirs" parameter in the "Setup" menu. See "MANUAL/Replaying a Recording" for details. +- Now using a call to the 'ftw()' library function instead of an external 'find' + command to collect the recordings (thanks to Emil Naepflein for his hint about + this function). diff --git a/recording.c b/recording.c index 2ce0cf78..faabd4ca 100644 --- a/recording.c +++ b/recording.c @@ -4,12 +4,13 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 1.43 2002/01/20 12:14:25 kls Exp $ + * $Id: recording.c 1.44 2002/01/20 16:47:09 kls Exp $ */ #include "recording.h" #include <errno.h> #include <fcntl.h> +#include <ftw.h> #include <stdio.h> #include <string.h> #include <sys/stat.h> @@ -31,8 +32,6 @@ #define SUMMARYFILESUFFIX "/summary.vdr" #define MARKSFILESUFFIX "/marks.vdr" -#define FINDCMD "find %s -follow -type d -name '%s' 2> /dev/null" - #define MINDISKSPACE 1024 // MB #define DELETEDLIFETIME 1 // hours after which a deleted recording will be actually removed @@ -473,35 +472,50 @@ bool cRecording::Delete(void) bool cRecording::Remove(void) { + // let's do a final safety check here: + if (!endswith(FileName(), DELEXT)) { + esyslog(LOG_ERR, "attempt to remove recording %s", FileName()); + return false; + } isyslog(LOG_INFO, "removing recording %s", FileName()); return RemoveVideoFile(FileName()); } // --- cRecordings ----------------------------------------------------------- +cRecordings *FilterRecordings = NULL; +const char *FilterSuffix = NULL; + +static int Filter(const char *Name, const struct stat *Stat, int Status) +{ + if (FilterRecordings && FilterSuffix) { + if (Status == FTW_D) { + if (endswith(Name, FilterSuffix)) { + cRecording *r = new cRecording(Name); + FilterRecordings->Add(r); + } + } + return 0; + } + return 1; +} + bool cRecordings::Load(bool Deleted) { + if (FilterRecordings) + return false; // because of the static Filter() function only _one_ call at a time is allowed! Clear(); - bool result = false; - char *cmd = NULL; - asprintf(&cmd, FINDCMD, VideoDirectory, Deleted ? "*" DELEXT : "*" RECEXT); - FILE *p = popen(cmd, "r"); - if (p) { - char *s; - while ((s = readline(p)) != NULL) { - cRecording *r = new cRecording(s); - if (r->name) - Add(r); - else - delete r; - } - pclose(p); - Sort(); - result = Count() > 0; + bool result = true; + FilterRecordings = this; + FilterSuffix = Deleted ? DELEXT : RECEXT; + if (ftw(VideoDirectory, Filter, 10) < 0) { + LOG_ERROR; + result = false; } - else - Interface->Error("Error while opening pipe!"); - delete cmd; + Sort(); + result = result && Count() > 0; + FilterRecordings = NULL; + FilterSuffix = NULL; return result; } diff --git a/recording.h b/recording.h index c098271a..15a65e06 100644 --- a/recording.h +++ b/recording.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.h 1.19 2002/01/20 11:35:32 kls Exp $ + * $Id: recording.h 1.20 2002/01/20 16:05:24 kls Exp $ */ #ifndef __RECORDING_H @@ -29,7 +29,6 @@ public: }; class cRecording : public cListObject { - friend class cRecordings; private: int resume; char *titleBuffer; @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.50 2001/10/19 13:12:45 kls Exp $ + * $Id: tools.c 1.51 2002/01/20 15:43:35 kls Exp $ */ #include "tools.h" @@ -145,6 +145,17 @@ bool startswith(const char *s, const char *p) return true; } +bool endswith(const char *s, const char *p) +{ + const char *se = s + strlen(s) - 1; + const char *pe = p + strlen(p) - 1; + while (pe >= p) { + if (*pe-- != *se-- || (se < s && pe >= p)) + return false; + } + return true; +} + bool isempty(const char *s) { return !(s && *skipspace(s)); @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 1.36 2001/09/30 10:20:59 kls Exp $ + * $Id: tools.h 1.37 2002/01/20 15:39:53 kls Exp $ */ #ifndef __TOOLS_H @@ -51,6 +51,7 @@ char *skipspace(const char *s); char *stripspace(char *s); char *compactspace(char *s); bool startswith(const char *s, const char *p); +bool endswith(const char *s, const char *p); bool isempty(const char *s); int time_ms(void); void delay_ms(int ms); |