summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2005-12-18 10:41:26 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2005-12-18 10:41:26 +0100
commit579719a7f24079bc36939c6b7757030b7299ba29 (patch)
tree4c9ba173f8e58d16e96c993f3b561fb14a898c03
parentdb35165e25974df8719d253cde398831877c526d (diff)
downloadvdr-579719a7f24079bc36939c6b7757030b7299ba29.tar.gz
vdr-579719a7f24079bc36939c6b7757030b7299ba29.tar.bz2
When displaying the amount of free disk space, the space consumed by "deleted" recordings is now taken into account
-rw-r--r--CONTRIBUTORS4
-rw-r--r--HISTORY5
-rw-r--r--recording.c32
-rw-r--r--recording.h6
-rw-r--r--tools.c38
-rw-r--r--tools.h3
-rw-r--r--vdr.c7
-rw-r--r--videodir.c8
8 files changed, 92 insertions, 11 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 1da9a259..4ba1ac57 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -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
diff --git a/HISTORY b/HISTORY
index b04886c9..b89584f8 100644
--- a/HISTORY
+++ b/HISTORY
@@ -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).
diff --git a/recording.c b/recording.c
index 7a81d776..bf66fcfe 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.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;
diff --git a/recording.h b/recording.h
index 28a1cd25..80ee8112 100644
--- a/recording.h
+++ b/recording.h
@@ -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:
diff --git a/tools.c b/tools.c
index 4a4a3aa6..5937d857 100644
--- a/tools.c
+++ b/tools.c
@@ -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];
diff --git a/tools.h b/tools.h
index 833ba847..64c18238 100644
--- a/tools.h
+++ b/tools.h
@@ -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);
diff --git a/vdr.c b/vdr.c
index 8b206f97..a467fbcc 100644
--- a/vdr.c
+++ b/vdr.c
@@ -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();
diff --git a/videodir.c b/videodir.c
index 5206d0c7..a07ed28e 100644
--- a/videodir.c
+++ b/videodir.c
@@ -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)