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

When displaying the amount of free disk space, the space consumed by "deleted" recordings is now taken into account

This commit is contained in:
Klaus Schmidinger 2005-12-18 10:41:26 +01:00
parent db35165e25
commit 579719a7f2
8 changed files with 92 additions and 11 deletions

View File

@ -1551,3 +1551,7 @@ Maarten Wisse <Maarten.Wisse@urz.uni-hd.de>
Holger Brunn <holger.brunn@stud.uni-karlsruhe.de>
for adding a copy constructor to cString and fixing its assignment operator
Christian Vogt <c.v@nexgo.de>
for suggesting to take deleted recordings into account when displaying the
amount of free disk space

View File

@ -3963,7 +3963,7 @@ Video Disk Recorder Revision History
commands may now be executed at any time, and the message will be displayed
(no more "pending message").
2005-12-16: Version 1.3.38
2005-12-18: Version 1.3.38
- Fixed handling second audio and Dolby Digital PIDs for encrypted channels
(was broken in version 1.3.37).
@ -3976,3 +3976,6 @@ Video Disk Recorder Revision History
useful value on NPTL systems (suggested by Johannes Stezenbach).
- Fixed the RCU remote control handling to avoid problems with NPTL (thanks
to Andreas Share for reporting a lockup with the RCU on NPTL systems).
- When displaying the amount of free disk space, the space consumed by
recordings that have been "deleted" but not yet actually "removed" is now
taken into account (suggested by Christian Vogt).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: recording.c 1.124 2005/11/04 14:19:44 kls Exp $
* $Id: recording.c 1.125 2005/12/17 13:30:50 kls Exp $
*/
#include "recording.h"
@ -60,7 +60,7 @@
bool VfatFileSystem = false;
static cRecordings DeletedRecordings(true);
cRecordings DeletedRecordings(true);
void RemoveDeletedRecordings(void)
{
@ -400,6 +400,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
sortBuffer = NULL;
fileName = NULL;
name = NULL;
fileSizeMB = -1; // unknown
// set up the actual name:
const char *Title = Event ? Event->Title() : NULL;
const char *Subtitle = Event ? Event->ShortText() : NULL;
@ -453,6 +454,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
cRecording::cRecording(const char *FileName)
{
resume = RESUME_NOT_INITIALIZED;
fileSizeMB = -1; // unknown
titleBuffer = NULL;
sortBuffer = NULL;
fileName = strdup(FileName);
@ -714,7 +716,7 @@ bool cRecording::Delete(void)
bool result = true;
char *NewName = strdup(FileName());
char *ext = strrchr(NewName, '.');
if (strcmp(ext, RECEXT) == 0) {
if (ext && strcmp(ext, RECEXT) == 0) {
strncpy(ext, DELEXT, strlen(ext));
if (access(NewName, F_OK) == 0) {
// the new name already exists, so let's remove that one first:
@ -814,6 +816,8 @@ void cRecordings::ScanVideoDir(const char *DirName, bool Foreground)
Add(r);
ChangeState();
Unlock();
if (deleted)
r->fileSizeMB = DirSizeMB(buffer);
}
else
delete r;
@ -883,12 +887,32 @@ void cRecordings::DelByName(const char *FileName)
LOCK_THREAD;
cRecording *recording = GetByName(FileName);
if (recording) {
Del(recording);
cThreadLock DeletedRecordingsLock(&DeletedRecordings);
Del(recording, false);
char *ext = strrchr(recording->FileName(), '.');
if (ext) {
strncpy(ext, DELEXT, strlen(ext));
recording->fileSizeMB = DirSizeMB(recording->FileName());
DeletedRecordings.Add(recording);
}
else
delete recording;
ChangeState();
TouchUpdate();
}
}
int cRecordings::TotalFileSizeMB(void)
{
int size = 0;
LOCK_THREAD;
for (cRecording *recording = First(); recording; recording = Next(recording)) {
if (recording->fileSizeMB > 0)
size += recording->fileSizeMB;
}
return size;
}
void cRecordings::ResetResume(const char *ResumeFileName)
{
LOCK_THREAD;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: recording.h 1.46 2005/10/31 12:27:12 kls Exp $
* $Id: recording.h 1.47 2005/12/17 13:30:50 kls Exp $
*/
#ifndef __RECORDING_H
@ -55,12 +55,14 @@ public:
};
class cRecording : public cListObject {
friend class cRecordings;
private:
mutable int resume;
mutable char *titleBuffer;
mutable char *sortBuffer;
mutable char *fileName;
mutable char *name;
mutable int fileSizeMB;
cRecordingInfo *info;
static char *StripEpisodeName(char *s);
char *SortName(void) const;
@ -126,9 +128,11 @@ public:
cRecording *GetByName(const char *FileName);
void AddByName(const char *FileName);
void DelByName(const char *FileName);
int TotalFileSizeMB(void); ///< Only for deleted recordings!
};
extern cRecordings Recordings;
extern cRecordings DeletedRecordings;
class cMark : public cListObject {
public:

38
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 1.104 2005/11/26 14:12:31 kls Exp $
* $Id: tools.c 1.105 2005/12/18 10:33:04 kls Exp $
*/
#include "tools.h"
@ -421,6 +421,42 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
return false;
}
int DirSizeMB(const char *DirName)
{
cReadDir d(DirName);
if (d.Ok()) {
int size = 0;
struct dirent *e;
while (size >= 0 && (e = d.Next()) != NULL) {
if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
char *buffer;
asprintf(&buffer, "%s/%s", DirName, e->d_name);
struct stat st;
if (stat(buffer, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
int n = DirSizeMB(buffer);
if (n >= 0)
size += n;
else
size = -1;
}
else
size += st.st_size / MEGABYTE(1);
}
else {
LOG_ERROR_STR(buffer);
size = -1;
}
free(buffer);
}
}
return size;
}
else
LOG_ERROR_STR(DirName);
return -1;
}
char *ReadLink(const char *FileName)
{
char RealName[PATH_MAX];

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.h 1.84 2005/11/26 14:03:47 kls Exp $
* $Id: tools.h 1.85 2005/12/17 11:09:37 kls Exp $
*/
#ifndef __TOOLS_H
@ -110,6 +110,7 @@ bool DirectoryOk(const char *DirName, bool LogErrors = false);
bool MakeDirs(const char *FileName, bool IsDirectory = false);
bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false);
bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false);
int DirSizeMB(const char *DirName); ///< returns the total size of the files in the given directory, or -1 in case of an error
char *ReadLink(const char *FileName); ///< returns a new string allocated on the heap, which the caller must delete (or NULL in case of an error)
bool SpinUpDisk(const char *FileName);
void TouchFile(const char *FileName);

7
vdr.c
View File

@ -22,7 +22,7 @@
*
* The project's page is at http://www.cadsoft.de/vdr
*
* $Id: vdr.c 1.220 2005/11/27 15:56:18 kls Exp $
* $Id: vdr.c 1.221 2005/12/18 10:33:37 kls Exp $
*/
#include <getopt.h>
@ -434,6 +434,7 @@ int main(int argc, char *argv[])
// Recordings:
Recordings.Update();
DeletedRecordings.Update();
// EPG data:
@ -667,8 +668,10 @@ int main(int argc, char *argv[])
TimerInVpsMargin = true;
}
}
if (!Menu && Recordings.NeedsUpdate())
if (!Menu && Recordings.NeedsUpdate()) {
Recordings.Update();
DeletedRecordings.Update();
}
// CAM control:
if (!Menu && !cOsd::IsOpen()) {
Menu = CamControl();

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: videodir.c 1.13 2005/10/31 12:07:41 kls Exp $
* $Id: videodir.c 1.14 2005/12/18 10:33:20 kls Exp $
*/
#include "videodir.h"
@ -16,6 +16,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "recording.h"
#include "tools.h"
const char *VideoDirectory = VIDEODIR;
@ -185,12 +186,17 @@ bool VideoFileSpaceAvailable(int SizeMB)
int VideoDiskSpace(int *FreeMB, int *UsedMB)
{
int free = 0, used = 0;
int deleted = DeletedRecordings.TotalFileSizeMB();
cVideoDirectory Dir;
do {
int u;
free += Dir.FreeMB(&u);
used += u;
} while (Dir.Next());
if (deleted > used)
deleted = used; // let's not get beyond 100%
free += deleted;
used -= deleted;
if (FreeMB)
*FreeMB = free;
if (UsedMB)