summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/tools.c b/tools.c
index 778c4639..145af7af 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 2.20 2012/01/11 11:21:43 kls Exp $
+ * $Id: tools.c 2.21 2012/02/17 13:58:49 kls Exp $
*/
#include "tools.h"
@@ -384,37 +384,35 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
if (d.Ok()) {
struct dirent *e;
while ((e = d.Next()) != NULL) {
- if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
- cString buffer = AddDirectory(FileName, e->d_name);
- if (FollowSymlinks) {
- struct stat st2;
- if (lstat(buffer, &st2) == 0) {
- if (S_ISLNK(st2.st_mode)) {
- int size = st2.st_size + 1;
- char *l = MALLOC(char, size);
- int n = readlink(buffer, l, size - 1);
- if (n < 0) {
- if (errno != EINVAL)
- LOG_ERROR_STR(*buffer);
- }
- else {
- l[n] = 0;
- dsyslog("removing %s", l);
- if (remove(l) < 0)
- LOG_ERROR_STR(l);
- }
- free(l);
+ cString buffer = AddDirectory(FileName, e->d_name);
+ if (FollowSymlinks) {
+ struct stat st2;
+ if (lstat(buffer, &st2) == 0) {
+ if (S_ISLNK(st2.st_mode)) {
+ int size = st2.st_size + 1;
+ char *l = MALLOC(char, size);
+ int n = readlink(buffer, l, size - 1);
+ if (n < 0) {
+ if (errno != EINVAL)
+ LOG_ERROR_STR(*buffer);
}
+ else {
+ l[n] = 0;
+ dsyslog("removing %s", l);
+ if (remove(l) < 0)
+ LOG_ERROR_STR(l);
+ }
+ free(l);
}
- else if (errno != ENOENT) {
- LOG_ERROR_STR(FileName);
- return false;
- }
}
- dsyslog("removing %s", *buffer);
- if (remove(buffer) < 0)
- LOG_ERROR_STR(*buffer);
+ else if (errno != ENOENT) {
+ LOG_ERROR_STR(FileName);
+ return false;
+ }
}
+ dsyslog("removing %s", *buffer);
+ if (remove(buffer) < 0)
+ LOG_ERROR_STR(*buffer);
}
}
else {
@@ -442,7 +440,7 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
bool empty = true;
struct dirent *e;
while ((e = d.Next()) != NULL) {
- if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..") && strcmp(e->d_name, "lost+found")) {
+ if (strcmp(e->d_name, "lost+found")) {
cString buffer = AddDirectory(DirName, e->d_name);
struct stat st;
if (stat(buffer, &st) == 0) {
@@ -480,24 +478,22 @@ int DirSizeMB(const char *DirName)
int size = 0;
struct dirent *e;
while (size >= 0 && (e = d.Next()) != NULL) {
- if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
- cString buffer = AddDirectory(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;
- }
+ cString buffer = AddDirectory(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 += st.st_size / MEGABYTE(1);
- }
- else {
- LOG_ERROR_STR(*buffer);
- size = -1;
+ size = -1;
}
+ else
+ size += st.st_size / MEGABYTE(1);
+ }
+ else {
+ LOG_ERROR_STR(*buffer);
+ size = -1;
}
}
return size;
@@ -1320,7 +1316,13 @@ cReadDir::~cReadDir()
struct dirent *cReadDir::Next(void)
{
- return directory && readdir_r(directory, &u.d, &result) == 0 ? result : NULL;
+ if (directory) {
+ while (readdir_r(directory, &u.d, &result) == 0 && result) {
+ if (strcmp(result->d_name, ".") && strcmp(result->d_name, ".."))
+ return result;
+ }
+ }
+ return NULL;
}
// --- cStringList -----------------------------------------------------------
@@ -1362,16 +1364,14 @@ bool cFileNameList::Load(const char *Directory, bool DirsOnly)
struct dirent *e;
if (d.Ok()) {
while ((e = d.Next()) != NULL) {
- if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
- if (DirsOnly) {
- struct stat ds;
- if (stat(AddDirectory(Directory, e->d_name), &ds) == 0) {
- if (!S_ISDIR(ds.st_mode))
- continue;
- }
+ if (DirsOnly) {
+ struct stat ds;
+ if (stat(AddDirectory(Directory, e->d_name), &ds) == 0) {
+ if (!S_ISDIR(ds.st_mode))
+ continue;
}
- Append(strdup(e->d_name));
}
+ Append(strdup(e->d_name));
}
Sort();
return true;