summaryrefslogtreecommitdiff
path: root/recording.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2005-12-18 12:14:11 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2005-12-18 12:14:11 +0100
commit78990eb18811079d78cbe6ffe24fd5b750a22eac (patch)
tree2e6dc79074762f9e1ec3624f5ab14ca277f61ce1 /recording.c
parent579719a7f24079bc36939c6b7757030b7299ba29 (diff)
downloadvdr-78990eb18811079d78cbe6ffe24fd5b750a22eac.tar.gz
vdr-78990eb18811079d78cbe6ffe24fd5b750a22eac.tar.bz2
Now avoiding unnecessary disk access when checking if there are deleted recordings that need to be removed; fixed handling the DELETEDLIFETIME
Diffstat (limited to 'recording.c')
-rw-r--r--recording.c53
1 files changed, 21 insertions, 32 deletions
diff --git a/recording.c b/recording.c
index bf66fcfe..73625498 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.125 2005/12/17 13:30:50 kls Exp $
+ * $Id: recording.c 1.126 2005/12/18 12:06:36 kls Exp $
*/
#include "recording.h"
@@ -48,8 +48,8 @@
#define MINDISKSPACE 1024 // MB
-#define DELETEDLIFETIME 1 // hours after which a deleted recording will be actually removed
-#define REMOVECHECKDELTA 3600 // seconds between checks for removing deleted files
+#define REMOVECHECKDELTA 60 // seconds between checks for removing deleted files
+#define DELETEDLIFETIME 3600 // seconds after which a deleted recording will be actually removed
#define DISKCHECKDELTA 100 // seconds between checks for free disk space
#define REMOVELATENCY 10 // seconds to wait until next check after removing a file
@@ -65,35 +65,19 @@ cRecordings DeletedRecordings(true);
void RemoveDeletedRecordings(void)
{
static time_t LastRemoveCheck = 0;
- if (LastRemoveCheck == 0) {
- DeletedRecordings.Update();
- LastRemoveCheck = time(NULL) - REMOVECHECKDELTA * 9 / 10;
- }
- else if (time(NULL) - LastRemoveCheck > REMOVECHECKDELTA) {
- // Make sure only one instance of VDR does this:
- cLockFile LockFile(VideoDirectory);
- if (!LockFile.Lock())
- return;
- // Remove the oldest file that has been "deleted":
+ if (time(NULL) - LastRemoveCheck > REMOVECHECKDELTA) {
cThreadLock DeletedRecordingsLock(&DeletedRecordings);
- if (DeletedRecordings.Count()) {
- cRecording *r = DeletedRecordings.First();
- cRecording *r0 = r;
- while (r) {
- if (r->start < r0->start)
- r0 = r;
- r = DeletedRecordings.Next(r);
- }
- if (r0 && time(NULL) - r0->start > DELETEDLIFETIME * 3600) {
- r0->Remove();
- DeletedRecordings.Del(r0);
- RemoveEmptyVideoDirectories();
- LastRemoveCheck += REMOVELATENCY;
- return;
- }
- }
- else
- DeletedRecordings.Update();
+ for (cRecording *r = DeletedRecordings.First(); r; r = DeletedRecordings.Next(r)) {
+ if (r->deleted && time(NULL) - r->deleted > DELETEDLIFETIME) {
+ // Make sure only one instance of VDR does this:
+ cLockFile LockFile(VideoDirectory);
+ if (LockFile.Lock()) {
+ r->Remove();
+ DeletedRecordings.Del(r);
+ RemoveEmptyVideoDirectories();
+ }
+ }
+ }
LastRemoveCheck = time(NULL);
}
}
@@ -401,6 +385,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
fileName = NULL;
name = NULL;
fileSizeMB = -1; // unknown
+ deleted = 0;
// set up the actual name:
const char *Title = Event ? Event->Title() : NULL;
const char *Subtitle = Event ? Event->ShortText() : NULL;
@@ -455,6 +440,7 @@ cRecording::cRecording(const char *FileName)
{
resume = RESUME_NOT_INITIALIZED;
fileSizeMB = -1; // unknown
+ deleted = 0;
titleBuffer = NULL;
sortBuffer = NULL;
fileName = strdup(FileName);
@@ -816,8 +802,10 @@ void cRecordings::ScanVideoDir(const char *DirName, bool Foreground)
Add(r);
ChangeState();
Unlock();
- if (deleted)
+ if (deleted) {
r->fileSizeMB = DirSizeMB(buffer);
+ r->deleted = time(NULL);
+ }
}
else
delete r;
@@ -893,6 +881,7 @@ void cRecordings::DelByName(const char *FileName)
if (ext) {
strncpy(ext, DELEXT, strlen(ext));
recording->fileSizeMB = DirSizeMB(recording->FileName());
+ recording->deleted = time(NULL);
DeletedRecordings.Add(recording);
}
else