mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Removing empty directories
This commit is contained in:
parent
c0ed9649a3
commit
80a42f1300
2
HISTORY
2
HISTORY
@ -389,3 +389,5 @@ Video Disk Recorder Revision History
|
|||||||
- The "Green" button in the "Recordings" menu can now be used to rewind a
|
- The "Green" button in the "Recordings" menu can now be used to rewind a
|
||||||
recording and play it from the very beginning.
|
recording and play it from the very beginning.
|
||||||
- Fixed handling ':' in timer filenames and '\n' in timer summaries (see FORMATS).
|
- Fixed handling ':' in timer filenames and '\n' in timer summaries (see FORMATS).
|
||||||
|
- When removing recordings empty directories are now removed from the video
|
||||||
|
directory.
|
||||||
|
@ -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.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
|
#define _GNU_SOURCE
|
||||||
@ -53,6 +53,7 @@ void RemoveDeletedRecordings(void)
|
|||||||
}
|
}
|
||||||
if (r0 && time(NULL) - r0->start > DELETEDLIFETIME * 60) {
|
if (r0 && time(NULL) - r0->start > DELETEDLIFETIME * 60) {
|
||||||
r0->Remove();
|
r0->Remove();
|
||||||
|
RemoveEmptyVideoDirectories();
|
||||||
LastRemoveCheck += REMOVELATENCY;
|
LastRemoveCheck += REMOVELATENCY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
44
tools.c
44
tools.c
@ -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.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
|
#define _GNU_SOURCE
|
||||||
@ -249,6 +249,48 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
|
|||||||
return true;
|
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 *ReadLink(const char *FileName)
|
||||||
{
|
{
|
||||||
char RealName[_POSIX_PATH_MAX];
|
char RealName[_POSIX_PATH_MAX];
|
||||||
|
3
tools.h
3
tools.h
@ -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.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
|
#ifndef __TOOLS_H
|
||||||
@ -48,6 +48,7 @@ uint FreeDiskSpaceMB(const char *Directory);
|
|||||||
bool DirectoryOk(const char *DirName, bool LogErrors = false);
|
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);
|
||||||
char *ReadLink(const char *FileName);
|
char *ReadLink(const char *FileName);
|
||||||
|
|
||||||
class cFile {
|
class cFile {
|
||||||
|
15
vdr.c
15
vdr.c
@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
* The project's page is at http://www.cadsoft.de/people/kls/vdr
|
* 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>
|
#include <getopt.h>
|
||||||
@ -44,6 +44,8 @@
|
|||||||
#define KEYS_CONF "keys.conf"
|
#define KEYS_CONF "keys.conf"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ACTIVITYTIMEOUT 60 // seconds before starting housekeeping
|
||||||
|
|
||||||
static int Interrupted = 0;
|
static int Interrupted = 0;
|
||||||
|
|
||||||
static void SignalHandler(int signum)
|
static void SignalHandler(int signum)
|
||||||
@ -218,6 +220,7 @@ int main(int argc, char *argv[])
|
|||||||
cReplayControl *ReplayControl = NULL;
|
cReplayControl *ReplayControl = NULL;
|
||||||
int LastChannel = -1;
|
int LastChannel = -1;
|
||||||
int PreviousChannel = cDvbApi::CurrentChannel();
|
int PreviousChannel = cDvbApi::CurrentChannel();
|
||||||
|
time_t LastActivity = time(NULL);
|
||||||
|
|
||||||
while (!Interrupted) {
|
while (!Interrupted) {
|
||||||
// Channel display:
|
// Channel display:
|
||||||
@ -324,8 +327,14 @@ int main(int argc, char *argv[])
|
|||||||
EITScanner.Process();
|
EITScanner.Process();
|
||||||
cVideoCutter::Active();
|
cVideoCutter::Active();
|
||||||
}
|
}
|
||||||
if (!*Interact && !cRecordControls::Active())
|
if (!*Interact && !cRecordControls::Active()) {
|
||||||
RemoveDeletedRecordings();
|
if (time(NULL) - LastActivity > ACTIVITYTIMEOUT) {
|
||||||
|
RemoveDeletedRecordings();
|
||||||
|
LastActivity = time(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LastActivity = time(NULL);
|
||||||
}
|
}
|
||||||
isyslog(LOG_INFO, "caught signal %d", Interrupted);
|
isyslog(LOG_INFO, "caught signal %d", Interrupted);
|
||||||
Setup.CurrentChannel = cDvbApi::CurrentChannel();
|
Setup.CurrentChannel = cDvbApi::CurrentChannel();
|
||||||
|
12
videodir.c
12
videodir.c
@ -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.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"
|
#include "videodir.h"
|
||||||
@ -28,7 +28,7 @@ public:
|
|||||||
cVideoDirectory(void);
|
cVideoDirectory(void);
|
||||||
~cVideoDirectory();
|
~cVideoDirectory();
|
||||||
uint FreeMB(void);
|
uint FreeMB(void);
|
||||||
const char *Name(void) { return name; }
|
const char *Name(void) { return name ? name : VideoDirectory; }
|
||||||
const char *Stored(void) { return stored; }
|
const char *Stored(void) { return stored; }
|
||||||
int Length(void) { return length; }
|
int Length(void) { return length; }
|
||||||
bool IsDistributed(void) { return name != NULL; }
|
bool IsDistributed(void) { return name != NULL; }
|
||||||
@ -197,3 +197,11 @@ const char *PrefixVideoFileName(const char *FileName, char Prefix)
|
|||||||
return PrefixedName;
|
return PrefixedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RemoveEmptyVideoDirectories(void)
|
||||||
|
{
|
||||||
|
cVideoDirectory Dir;
|
||||||
|
do {
|
||||||
|
RemoveEmptyDirectories(Dir.Name());
|
||||||
|
} while (Dir.Next());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -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.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
|
#ifndef __VIDEODIR_H
|
||||||
@ -18,5 +18,6 @@ bool RenameVideoFile(const char *OldName, const char *NewName);
|
|||||||
bool RemoveVideoFile(const char *FileName);
|
bool RemoveVideoFile(const char *FileName);
|
||||||
bool VideoFileSpaceAvailable(unsigned int SizeMB);
|
bool VideoFileSpaceAvailable(unsigned int SizeMB);
|
||||||
const char *PrefixVideoFileName(const char *FileName, char Prefix);
|
const char *PrefixVideoFileName(const char *FileName, char Prefix);
|
||||||
|
void RemoveEmptyVideoDirectories(void);
|
||||||
|
|
||||||
#endif //__VIDEODIR_H
|
#endif //__VIDEODIR_H
|
||||||
|
Loading…
Reference in New Issue
Block a user