summaryrefslogtreecommitdiff
path: root/recording.c
diff options
context:
space:
mode:
Diffstat (limited to 'recording.c')
-rw-r--r--recording.c49
1 files changed, 10 insertions, 39 deletions
diff --git a/recording.c b/recording.c
index e37ccd8..9f3b388 100644
--- a/recording.c
+++ b/recording.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: recording.c 1.12 2000/07/24 16:31:07 kls Exp $
+ * $Id: recording.c 1.15 2000/07/29 14:08:17 kls Exp $
*/
#define _GNU_SOURCE
@@ -13,9 +13,11 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
+#include <sys/stat.h>
#include <unistd.h>
#include "interface.h"
#include "tools.h"
+#include "videodir.h"
#define RECEXT ".rec"
#define DELEXT ".del"
@@ -24,40 +26,12 @@
#define SUMMARYFILESUFFIX "/summary.vdr"
-#define FINDCMD "find %s -type d -name '%s' | sort -df"
+#define FINDCMD "find %s -follow -type d -name '%s' 2> /dev/null | sort -df"
-#define DFCMD "df -m %s"
#define MINDISKSPACE 1024 // MB
#define DISKCHECKDELTA 300 // seconds between checks for free disk space
-const char *BaseDir = "/video";
-
-static bool LowDiskSpace(void)
-{
- //TODO Find a simpler way to determine the amount of free disk space!
- bool result = true;
- char *cmd = NULL;
- asprintf(&cmd, DFCMD, BaseDir);
- FILE *p = popen(cmd, "r");
- if (p) {
- char *s;
- while ((s = readline(p)) != NULL) {
- if (*s == '/') {
- int available;
- sscanf(s, "%*s %*d %*d %d", &available);
- result = available < MINDISKSPACE;
- break;
- }
- }
- pclose(p);
- }
- else
- esyslog(LOG_ERR, "ERROR: can't open pipe for cmd '%s'", cmd);
- delete cmd;
- return result;
-}
-
void AssertFreeDiskSpace(void)
{
// With every call to this function we try to actually remove
@@ -65,7 +39,7 @@ void AssertFreeDiskSpace(void)
// it will get removed during the next call.
static time_t LastFreeDiskCheck = 0;
if (time(NULL) - LastFreeDiskCheck > DISKCHECKDELTA) {
- if (LowDiskSpace()) {
+ if (!VideoFileSpaceAvailable(MINDISKSPACE)) {
// Remove the oldest file that has been "deleted":
cRecordings Recordings;
if (Recordings.Load(true)) {
@@ -123,7 +97,7 @@ cRecording::cRecording(const char *FileName)
{
titleBuffer = NULL;
fileName = strdup(FileName);
- FileName += strlen(BaseDir) + 1;
+ FileName += strlen(VideoDirectory) + 1;
char *p = strrchr(FileName, '/');
name = NULL;
@@ -189,7 +163,7 @@ const char *cRecording::FileName(void)
{
if (!fileName) {
struct tm *t = localtime(&start);
- asprintf(&fileName, NAMEFORMAT, BaseDir, name, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, priority, lifetime);
+ asprintf(&fileName, NAMEFORMAT, VideoDirectory, name, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, priority, lifetime);
if (fileName)
strreplace(fileName, ' ', '_');
}
@@ -239,10 +213,7 @@ bool cRecording::Delete(void)
if (strcmp(ext, RECEXT) == 0) {
strncpy(ext, DELEXT, strlen(ext));
isyslog(LOG_INFO, "deleting recording %s", FileName());
- if (rename(FileName(), NewName) == -1) {
- esyslog(LOG_ERR, "ERROR: %s: %s", FileName(), strerror(errno));
- result = false;
- }
+ result = RenameVideoFile(FileName(), NewName);
}
delete NewName;
return result;
@@ -251,7 +222,7 @@ bool cRecording::Delete(void)
bool cRecording::Remove(void)
{
isyslog(LOG_INFO, "removing recording %s", FileName());
- return RemoveFileOrDir(FileName());
+ return RemoveVideoFile(FileName());
}
// --- cRecordings -----------------------------------------------------------
@@ -261,7 +232,7 @@ bool cRecordings::Load(bool Deleted)
Clear();
bool result = false;
char *cmd = NULL;
- asprintf(&cmd, FINDCMD, BaseDir, Deleted ? "*" DELEXT : "*" RECEXT);
+ asprintf(&cmd, FINDCMD, VideoDirectory, Deleted ? "*" DELEXT : "*" RECEXT);
FILE *p = popen(cmd, "r");
if (p) {
char *s;