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

Now avoiding unnecessary disk access when checking if there are deleted recordings that need to be removed; fixed handling the DELETEDLIFETIME

This commit is contained in:
Klaus Schmidinger 2005-12-18 12:14:11 +01:00
parent 579719a7f2
commit 78990eb188
4 changed files with 30 additions and 33 deletions

View File

@ -16,6 +16,8 @@ Carsten Koch <Carsten.Koch@icem.de>
for fixing converting summary.vdr files that would result in a very long 'short text' for fixing converting summary.vdr files that would result in a very long 'short text'
for his help in testing and debugging reading the list of recordings in a for his help in testing and debugging reading the list of recordings in a
separate thread separate thread
for reporting some unnecessary disk access when checking if there are deleted
recordings that need to be removed
Plamen Ganev <pganev@com-it.net> Plamen Ganev <pganev@com-it.net>
for fixing the frequency offset for Hotbird channels for fixing the frequency offset for Hotbird channels

View File

@ -3979,3 +3979,8 @@ Video Disk Recorder Revision History
- When displaying the amount of free disk space, the space consumed by - When displaying the amount of free disk space, the space consumed by
recordings that have been "deleted" but not yet actually "removed" is now recordings that have been "deleted" but not yet actually "removed" is now
taken into account (suggested by Christian Vogt). taken into account (suggested by Christian Vogt).
- Now avoiding unnecessary disk access when checking if there are deleted
recordings that need to be removed (reported by Carsten Koch).
- Fixed handling the DELETEDLIFETIME when removing deleted recordings. Now
a deleted recording is retained at least DELETEDLIFETIME seconds before
actually removing it (unless a new recording requires the disk space).

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.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" #include "recording.h"
@ -48,8 +48,8 @@
#define MINDISKSPACE 1024 // MB #define MINDISKSPACE 1024 // MB
#define DELETEDLIFETIME 1 // hours after which a deleted recording will be actually removed #define REMOVECHECKDELTA 60 // seconds between checks for removing deleted files
#define REMOVECHECKDELTA 3600 // 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 DISKCHECKDELTA 100 // seconds between checks for free disk space
#define REMOVELATENCY 10 // seconds to wait until next check after removing a file #define REMOVELATENCY 10 // seconds to wait until next check after removing a file
@ -65,35 +65,19 @@ cRecordings DeletedRecordings(true);
void RemoveDeletedRecordings(void) void RemoveDeletedRecordings(void)
{ {
static time_t LastRemoveCheck = 0; static time_t LastRemoveCheck = 0;
if (LastRemoveCheck == 0) { if (time(NULL) - LastRemoveCheck > REMOVECHECKDELTA) {
DeletedRecordings.Update(); cThreadLock DeletedRecordingsLock(&DeletedRecordings);
LastRemoveCheck = time(NULL) - REMOVECHECKDELTA * 9 / 10; for (cRecording *r = DeletedRecordings.First(); r; r = DeletedRecordings.Next(r)) {
} if (r->deleted && time(NULL) - r->deleted > DELETEDLIFETIME) {
else if (time(NULL) - LastRemoveCheck > REMOVECHECKDELTA) {
// Make sure only one instance of VDR does this: // Make sure only one instance of VDR does this:
cLockFile LockFile(VideoDirectory); cLockFile LockFile(VideoDirectory);
if (!LockFile.Lock()) if (LockFile.Lock()) {
return; r->Remove();
// Remove the oldest file that has been "deleted": DeletedRecordings.Del(r);
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(); RemoveEmptyVideoDirectories();
LastRemoveCheck += REMOVELATENCY;
return;
} }
} }
else }
DeletedRecordings.Update();
LastRemoveCheck = time(NULL); LastRemoveCheck = time(NULL);
} }
} }
@ -401,6 +385,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
fileName = NULL; fileName = NULL;
name = NULL; name = NULL;
fileSizeMB = -1; // unknown fileSizeMB = -1; // unknown
deleted = 0;
// set up the actual name: // set up the actual name:
const char *Title = Event ? Event->Title() : NULL; const char *Title = Event ? Event->Title() : NULL;
const char *Subtitle = Event ? Event->ShortText() : NULL; const char *Subtitle = Event ? Event->ShortText() : NULL;
@ -455,6 +440,7 @@ cRecording::cRecording(const char *FileName)
{ {
resume = RESUME_NOT_INITIALIZED; resume = RESUME_NOT_INITIALIZED;
fileSizeMB = -1; // unknown fileSizeMB = -1; // unknown
deleted = 0;
titleBuffer = NULL; titleBuffer = NULL;
sortBuffer = NULL; sortBuffer = NULL;
fileName = strdup(FileName); fileName = strdup(FileName);
@ -816,8 +802,10 @@ void cRecordings::ScanVideoDir(const char *DirName, bool Foreground)
Add(r); Add(r);
ChangeState(); ChangeState();
Unlock(); Unlock();
if (deleted) if (deleted) {
r->fileSizeMB = DirSizeMB(buffer); r->fileSizeMB = DirSizeMB(buffer);
r->deleted = time(NULL);
}
} }
else else
delete r; delete r;
@ -893,6 +881,7 @@ void cRecordings::DelByName(const char *FileName)
if (ext) { if (ext) {
strncpy(ext, DELEXT, strlen(ext)); strncpy(ext, DELEXT, strlen(ext));
recording->fileSizeMB = DirSizeMB(recording->FileName()); recording->fileSizeMB = DirSizeMB(recording->FileName());
recording->deleted = time(NULL);
DeletedRecordings.Add(recording); DeletedRecordings.Add(recording);
} }
else else

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.47 2005/12/17 13:30:50 kls Exp $ * $Id: recording.h 1.48 2005/12/18 11:26:51 kls Exp $
*/ */
#ifndef __RECORDING_H #ifndef __RECORDING_H
@ -71,6 +71,7 @@ public:
time_t start; time_t start;
int priority; int priority;
int lifetime; int lifetime;
time_t deleted;
cRecording(cTimer *Timer, const cEvent *Event); cRecording(cTimer *Timer, const cEvent *Event);
cRecording(const char *FileName); cRecording(const char *FileName);
virtual ~cRecording(); virtual ~cRecording();