1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Now using 'ftw()' instead of an external 'find' to collect recordings

This commit is contained in:
Klaus Schmidinger 2002-01-20 16:47:09 +01:00
parent fd839aae7b
commit 305abd449f
6 changed files with 57 additions and 26 deletions

View File

@ -175,3 +175,6 @@ Stephan Schreiber <stephan@sschreiber.de>
Lauri Pesonen <lauri.pesonen@firsthop.com> Lauri Pesonen <lauri.pesonen@firsthop.com>
for avoiding linking in 'libncurses' if compiling without DEBUG_OSD=1 and for avoiding linking in 'libncurses' if compiling without DEBUG_OSD=1 and
REMOTE=KBD REMOTE=KBD
Emil Naepflein <Emil.Naepflein@philosys.de>
for his hint about the 'ftw()' library function

View File

@ -900,3 +900,6 @@ Video Disk Recorder Revision History
subdirectories for the recordings. This can be controlled through the subdirectories for the recordings. This can be controlled through the
"RecordingDirs" parameter in the "Setup" menu. "RecordingDirs" parameter in the "Setup" menu.
See "MANUAL/Replaying a Recording" for details. 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).

View File

@ -4,12 +4,13 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 "recording.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <ftw.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -31,8 +32,6 @@
#define SUMMARYFILESUFFIX "/summary.vdr" #define SUMMARYFILESUFFIX "/summary.vdr"
#define MARKSFILESUFFIX "/marks.vdr" #define MARKSFILESUFFIX "/marks.vdr"
#define FINDCMD "find %s -follow -type d -name '%s' 2> /dev/null"
#define MINDISKSPACE 1024 // MB #define MINDISKSPACE 1024 // MB
#define DELETEDLIFETIME 1 // hours after which a deleted recording will be actually removed #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) 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()); isyslog(LOG_INFO, "removing recording %s", FileName());
return RemoveVideoFile(FileName()); return RemoveVideoFile(FileName());
} }
// --- cRecordings ----------------------------------------------------------- // --- 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) bool cRecordings::Load(bool Deleted)
{ {
if (FilterRecordings)
return false; // because of the static Filter() function only _one_ call at a time is allowed!
Clear(); Clear();
bool result = false; bool result = true;
char *cmd = NULL; FilterRecordings = this;
asprintf(&cmd, FINDCMD, VideoDirectory, Deleted ? "*" DELEXT : "*" RECEXT); FilterSuffix = Deleted ? DELEXT : RECEXT;
FILE *p = popen(cmd, "r"); if (ftw(VideoDirectory, Filter, 10) < 0) {
if (p) { LOG_ERROR;
char *s; result = false;
while ((s = readline(p)) != NULL) {
cRecording *r = new cRecording(s);
if (r->name)
Add(r);
else
delete r;
} }
pclose(p);
Sort(); Sort();
result = Count() > 0; result = result && Count() > 0;
} FilterRecordings = NULL;
else FilterSuffix = NULL;
Interface->Error("Error while opening pipe!");
delete cmd;
return result; return result;
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef __RECORDING_H
@ -29,7 +29,6 @@ public:
}; };
class cRecording : public cListObject { class cRecording : public cListObject {
friend class cRecordings;
private: private:
int resume; int resume;
char *titleBuffer; char *titleBuffer;

13
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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" #include "tools.h"
@ -145,6 +145,17 @@ bool startswith(const char *s, const char *p)
return true; 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) bool isempty(const char *s)
{ {
return !(s && *skipspace(s)); return !(s && *skipspace(s));

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef __TOOLS_H
@ -51,6 +51,7 @@ char *skipspace(const char *s);
char *stripspace(char *s); char *stripspace(char *s);
char *compactspace(char *s); char *compactspace(char *s);
bool startswith(const char *s, const char *p); bool startswith(const char *s, const char *p);
bool endswith(const char *s, const char *p);
bool isempty(const char *s); bool isempty(const char *s);
int time_ms(void); int time_ms(void);
void delay_ms(int ms); void delay_ms(int ms);