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

RemoveEmptyDirectories() now ignores dot files

This commit is contained in:
Klaus Schmidinger 2012-08-21 10:42:01 +02:00
parent da26141015
commit 3f03cfa14d
2 changed files with 24 additions and 1 deletions

View File

@ -7198,3 +7198,7 @@ Video Disk Recorder Revision History
(thanks to Mehdi Karamnejad for reporting a problem with garbled UTF-8 EPG data (thanks to Mehdi Karamnejad for reporting a problem with garbled UTF-8 EPG data
and helping to debug it). and helping to debug it).
- Updated the Finnish OSD texts (thanks to Rolf Ahrenberg). - Updated the Finnish OSD texts (thanks to Rolf Ahrenberg).
- When checking whether a video directory is empty, file names that start with a
dot ('.') are now ignored and will be implicitly removed if the directory contains
no other files. This fixes the leftover ".sort" files that were introduced in
version 1.7.29.

21
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 2.24 2012/05/12 13:29:20 kls Exp $ * $Id: tools.c 2.25 2012/08/21 10:34:37 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -435,6 +435,7 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis) bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
{ {
bool HasDotFiles = false;
cReadDir d(DirName); cReadDir d(DirName);
if (d.Ok()) { if (d.Ok()) {
bool empty = true; bool empty = true;
@ -448,6 +449,8 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
if (!RemoveEmptyDirectories(buffer, true)) if (!RemoveEmptyDirectories(buffer, true))
empty = false; empty = false;
} }
else if (*e->d_name == '.') // "dot files" don't count
HasDotFiles = true;
else else
empty = false; empty = false;
} }
@ -458,6 +461,22 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
} }
} }
if (RemoveThis && empty) { if (RemoveThis && empty) {
if (HasDotFiles) {
cReadDir d(DirName);
if (d.Ok()) {
struct dirent *e;
while ((e = d.Next()) != NULL) {
if (*e->d_name == '.') { // for safety - should always be true
cString buffer = AddDirectory(DirName, e->d_name);
dsyslog("removing %s", *buffer);
if (remove(buffer) < 0) {
LOG_ERROR_STR(*buffer);
return false;
}
}
}
}
}
dsyslog("removing %s", DirName); dsyslog("removing %s", DirName);
if (remove(DirName) < 0) { if (remove(DirName) < 0) {
LOG_ERROR_STR(DirName); LOG_ERROR_STR(DirName);