summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2001-02-11 14:53:44 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2001-02-11 14:53:44 +0100
commit80a42f130003dabf7c70de35f446f4dbcf1ea3cf (patch)
treea008421d972a9c4eefd20d81dfb0cddbd7802b9e
parentc0ed9649a3f32b4510eddb47dfd82bcc860eac70 (diff)
downloadvdr-80a42f130003dabf7c70de35f446f4dbcf1ea3cf.tar.gz
vdr-80a42f130003dabf7c70de35f446f4dbcf1ea3cf.tar.bz2
Removing empty directories
-rw-r--r--HISTORY2
-rw-r--r--recording.c3
-rw-r--r--tools.c44
-rw-r--r--tools.h3
-rw-r--r--vdr.c15
-rw-r--r--videodir.c12
-rw-r--r--videodir.h3
7 files changed, 73 insertions, 9 deletions
diff --git a/HISTORY b/HISTORY
index e97ac697..4c93cb71 100644
--- a/HISTORY
+++ b/HISTORY
@@ -389,3 +389,5 @@ Video Disk Recorder Revision History
- The "Green" button in the "Recordings" menu can now be used to rewind a
recording and play it from the very beginning.
- Fixed handling ':' in timer filenames and '\n' in timer summaries (see FORMATS).
+- When removing recordings empty directories are now removed from the video
+ directory.
diff --git a/recording.c b/recording.c
index 72b3135f..5bc66b76 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.26 2001/02/11 10:47:31 kls Exp $
+ * $Id: recording.c 1.27 2001/02/11 14:53:44 kls Exp $
*/
#define _GNU_SOURCE
@@ -53,6 +53,7 @@ void RemoveDeletedRecordings(void)
}
if (r0 && time(NULL) - r0->start > DELETEDLIFETIME * 60) {
r0->Remove();
+ RemoveEmptyVideoDirectories();
LastRemoveCheck += REMOVELATENCY;
return;
}
diff --git a/tools.c b/tools.c
index bc82a407..a3b27e5a 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.29 2001/02/11 11:18:45 kls Exp $
+ * $Id: tools.c 1.30 2001/02/11 14:44:22 kls Exp $
*/
#define _GNU_SOURCE
@@ -249,6 +249,48 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
return true;
}
+bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
+{
+ DIR *d = opendir(DirName);
+ if (d) {
+ bool empty = true;
+ struct dirent *e;
+ while ((e = readdir(d)) != NULL) {
+ if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..") && strcmp(e->d_name, "lost+found")) {
+ char *buffer;
+ asprintf(&buffer, "%s/%s", DirName, e->d_name);
+ struct stat st;
+ if (stat(buffer, &st) == 0) {
+ if (S_ISDIR(st.st_mode)) {
+ if (!RemoveEmptyDirectories(buffer, true))
+ empty = false;
+ }
+ else
+ empty = false;
+ }
+ else {
+ LOG_ERROR_STR(buffer);
+ delete buffer;
+ return false;
+ }
+ delete buffer;
+ }
+ }
+ closedir(d);
+ if (RemoveThis && empty) {
+ dsyslog(LOG_INFO, "removing %s", DirName);
+ if (remove(DirName) < 0) {
+ LOG_ERROR_STR(DirName);
+ return false;
+ }
+ }
+ return empty;
+ }
+ else
+ LOG_ERROR_STR(DirName);
+ return false;
+}
+
char *ReadLink(const char *FileName)
{
char RealName[_POSIX_PATH_MAX];
diff --git a/tools.h b/tools.h
index 539dba01..96d09826 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.23 2001/01/13 15:36:00 kls Exp $
+ * $Id: tools.h 1.24 2001/02/11 13:39:40 kls Exp $
*/
#ifndef __TOOLS_H
@@ -48,6 +48,7 @@ uint FreeDiskSpaceMB(const char *Directory);
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);
char *ReadLink(const char *FileName);
class cFile {
diff --git a/vdr.c b/vdr.c
index ead90e5b..4fb33a9c 100644
--- a/vdr.c
+++ b/vdr.c
@@ -22,7 +22,7 @@
*
* The project's page is at http://www.cadsoft.de/people/kls/vdr
*
- * $Id: vdr.c 1.52 2001/02/04 19:41:24 kls Exp $
+ * $Id: vdr.c 1.53 2001/02/11 14:51:44 kls Exp $
*/
#include <getopt.h>
@@ -44,6 +44,8 @@
#define KEYS_CONF "keys.conf"
#endif
+#define ACTIVITYTIMEOUT 60 // seconds before starting housekeeping
+
static int Interrupted = 0;
static void SignalHandler(int signum)
@@ -218,6 +220,7 @@ int main(int argc, char *argv[])
cReplayControl *ReplayControl = NULL;
int LastChannel = -1;
int PreviousChannel = cDvbApi::CurrentChannel();
+ time_t LastActivity = time(NULL);
while (!Interrupted) {
// Channel display:
@@ -324,8 +327,14 @@ int main(int argc, char *argv[])
EITScanner.Process();
cVideoCutter::Active();
}
- if (!*Interact && !cRecordControls::Active())
- RemoveDeletedRecordings();
+ if (!*Interact && !cRecordControls::Active()) {
+ if (time(NULL) - LastActivity > ACTIVITYTIMEOUT) {
+ RemoveDeletedRecordings();
+ LastActivity = time(NULL);
+ }
+ }
+ else
+ LastActivity = time(NULL);
}
isyslog(LOG_INFO, "caught signal %d", Interrupted);
Setup.CurrentChannel = cDvbApi::CurrentChannel();
diff --git a/videodir.c b/videodir.c
index 4d5c2572..2824d04e 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.3 2000/12/24 12:51:41 kls Exp $
+ * $Id: videodir.c 1.4 2001/02/11 13:48:30 kls Exp $
*/
#include "videodir.h"
@@ -28,7 +28,7 @@ public:
cVideoDirectory(void);
~cVideoDirectory();
uint FreeMB(void);
- const char *Name(void) { return name; }
+ const char *Name(void) { return name ? name : VideoDirectory; }
const char *Stored(void) { return stored; }
int Length(void) { return length; }
bool IsDistributed(void) { return name != NULL; }
@@ -197,3 +197,11 @@ const char *PrefixVideoFileName(const char *FileName, char Prefix)
return PrefixedName;
}
+void RemoveEmptyVideoDirectories(void)
+{
+ cVideoDirectory Dir;
+ do {
+ RemoveEmptyDirectories(Dir.Name());
+ } while (Dir.Next());
+}
+
diff --git a/videodir.h b/videodir.h
index 0716a284..0197de30 100644
--- a/videodir.h
+++ b/videodir.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: videodir.h 1.2 2000/12/24 12:41:10 kls Exp $
+ * $Id: videodir.h 1.3 2001/02/11 13:12:50 kls Exp $
*/
#ifndef __VIDEODIR_H
@@ -18,5 +18,6 @@ bool RenameVideoFile(const char *OldName, const char *NewName);
bool RemoveVideoFile(const char *FileName);
bool VideoFileSpaceAvailable(unsigned int SizeMB);
const char *PrefixVideoFileName(const char *FileName, char Prefix);
+void RemoveEmptyVideoDirectories(void);
#endif //__VIDEODIR_H