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> Holger Brunn <holger.brunn@stud.uni-karlsruhe.de>
for adding a copy constructor to cString and fixing its assignment operator 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 commands may now be executed at any time, and the message will be displayed
(no more "pending message"). (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 - Fixed handling second audio and Dolby Digital PIDs for encrypted channels
(was broken in version 1.3.37). (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). useful value on NPTL systems (suggested by Johannes Stezenbach).
- Fixed the RCU remote control handling to avoid problems with NPTL (thanks - 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). 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 * 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.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" #include "recording.h"
@ -60,7 +60,7 @@
bool VfatFileSystem = false; bool VfatFileSystem = false;
static cRecordings DeletedRecordings(true); cRecordings DeletedRecordings(true);
void RemoveDeletedRecordings(void) void RemoveDeletedRecordings(void)
{ {
@ -400,6 +400,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
sortBuffer = NULL; sortBuffer = NULL;
fileName = NULL; fileName = NULL;
name = NULL; name = NULL;
fileSizeMB = -1; // unknown
// 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;
@ -453,6 +454,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
cRecording::cRecording(const char *FileName) cRecording::cRecording(const char *FileName)
{ {
resume = RESUME_NOT_INITIALIZED; resume = RESUME_NOT_INITIALIZED;
fileSizeMB = -1; // unknown
titleBuffer = NULL; titleBuffer = NULL;
sortBuffer = NULL; sortBuffer = NULL;
fileName = strdup(FileName); fileName = strdup(FileName);
@ -714,7 +716,7 @@ bool cRecording::Delete(void)
bool result = true; bool result = true;
char *NewName = strdup(FileName()); char *NewName = strdup(FileName());
char *ext = strrchr(NewName, '.'); char *ext = strrchr(NewName, '.');
if (strcmp(ext, RECEXT) == 0) { if (ext && strcmp(ext, RECEXT) == 0) {
strncpy(ext, DELEXT, strlen(ext)); strncpy(ext, DELEXT, strlen(ext));
if (access(NewName, F_OK) == 0) { if (access(NewName, F_OK) == 0) {
// the new name already exists, so let's remove that one first: // 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); Add(r);
ChangeState(); ChangeState();
Unlock(); Unlock();
if (deleted)
r->fileSizeMB = DirSizeMB(buffer);
} }
else else
delete r; delete r;
@ -883,12 +887,32 @@ void cRecordings::DelByName(const char *FileName)
LOCK_THREAD; LOCK_THREAD;
cRecording *recording = GetByName(FileName); cRecording *recording = GetByName(FileName);
if (recording) { 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(); ChangeState();
TouchUpdate(); 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) void cRecordings::ResetResume(const char *ResumeFileName)
{ {
LOCK_THREAD; LOCK_THREAD;

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.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 #ifndef __RECORDING_H
@ -55,12 +55,14 @@ public:
}; };
class cRecording : public cListObject { class cRecording : public cListObject {
friend class cRecordings;
private: private:
mutable int resume; mutable int resume;
mutable char *titleBuffer; mutable char *titleBuffer;
mutable char *sortBuffer; mutable char *sortBuffer;
mutable char *fileName; mutable char *fileName;
mutable char *name; mutable char *name;
mutable int fileSizeMB;
cRecordingInfo *info; cRecordingInfo *info;
static char *StripEpisodeName(char *s); static char *StripEpisodeName(char *s);
char *SortName(void) const; char *SortName(void) const;
@ -126,9 +128,11 @@ public:
cRecording *GetByName(const char *FileName); cRecording *GetByName(const char *FileName);
void AddByName(const char *FileName); void AddByName(const char *FileName);
void DelByName(const char *FileName); void DelByName(const char *FileName);
int TotalFileSizeMB(void); ///< Only for deleted recordings!
}; };
extern cRecordings Recordings; extern cRecordings Recordings;
extern cRecordings DeletedRecordings;
class cMark : public cListObject { class cMark : public cListObject {
public: public:

38
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.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" #include "tools.h"
@ -421,6 +421,42 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
return false; 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 *ReadLink(const char *FileName)
{ {
char RealName[PATH_MAX]; char RealName[PATH_MAX];

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.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 #ifndef __TOOLS_H
@ -110,6 +110,7 @@ bool DirectoryOk(const char *DirName, bool LogErrors = false);
bool MakeDirs(const char *FileName, bool IsDirectory = false); bool MakeDirs(const char *FileName, bool IsDirectory = false);
bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false); bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false);
bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = 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) 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); bool SpinUpDisk(const char *FileName);
void TouchFile(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 * 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> #include <getopt.h>
@ -434,6 +434,7 @@ int main(int argc, char *argv[])
// Recordings: // Recordings:
Recordings.Update(); Recordings.Update();
DeletedRecordings.Update();
// EPG data: // EPG data:
@ -667,8 +668,10 @@ int main(int argc, char *argv[])
TimerInVpsMargin = true; TimerInVpsMargin = true;
} }
} }
if (!Menu && Recordings.NeedsUpdate()) if (!Menu && Recordings.NeedsUpdate()) {
Recordings.Update(); Recordings.Update();
DeletedRecordings.Update();
}
// CAM control: // CAM control:
if (!Menu && !cOsd::IsOpen()) { if (!Menu && !cOsd::IsOpen()) {
Menu = CamControl(); Menu = CamControl();

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: 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" #include "videodir.h"
@ -16,6 +16,7 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "recording.h"
#include "tools.h" #include "tools.h"
const char *VideoDirectory = VIDEODIR; const char *VideoDirectory = VIDEODIR;
@ -185,12 +186,17 @@ bool VideoFileSpaceAvailable(int SizeMB)
int VideoDiskSpace(int *FreeMB, int *UsedMB) int VideoDiskSpace(int *FreeMB, int *UsedMB)
{ {
int free = 0, used = 0; int free = 0, used = 0;
int deleted = DeletedRecordings.TotalFileSizeMB();
cVideoDirectory Dir; cVideoDirectory Dir;
do { do {
int u; int u;
free += Dir.FreeMB(&u); free += Dir.FreeMB(&u);
used += u; used += u;
} while (Dir.Next()); } while (Dir.Next());
if (deleted > used)
deleted = used; // let's not get beyond 100%
free += deleted;
used -= deleted;
if (FreeMB) if (FreeMB)
*FreeMB = free; *FreeMB = free;
if (UsedMB) if (UsedMB)