mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
cReadDir::Next() now skips directory entries "." and ".."
This commit is contained in:
parent
f1eecdeb1c
commit
882691e32f
1
HISTORY
1
HISTORY
@ -6884,3 +6884,4 @@ Video Disk Recorder Revision History
|
||||
- The DVB device adapters/frontends are now probed by scanning the /dev/dvb directory
|
||||
instead of looping through adapter/frontend numbers. This allows for "holes" in the
|
||||
device numbering.
|
||||
- cReadDir::Next() now skips directory entries "." and "..".
|
||||
|
@ -63,3 +63,7 @@ VDR Plugin 'pictures' Revision History
|
||||
2012-01-08:
|
||||
|
||||
- Added option -o to pic2mpg.
|
||||
|
||||
2012-02-17:
|
||||
|
||||
- cReadDir::Next() now skips directory entries "." and "..".
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: entry.c 1.3 2008/02/17 13:42:34 kls Exp $
|
||||
* $Id: entry.c 2.1 2012/02/17 14:00:28 kls Exp $
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
@ -48,13 +48,11 @@ void cPictureEntry::Load(void) const
|
||||
if (d.Ok()) {
|
||||
struct dirent *e;
|
||||
while ((e = d.Next()) != NULL) {
|
||||
if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
|
||||
struct stat ds;
|
||||
if (stat(AddDirectory(Directory, e->d_name), &ds) == 0) {
|
||||
if (!entries)
|
||||
entries = new cList<cPictureEntry>;
|
||||
entries->Add(new cPictureEntry(e->d_name, this, S_ISDIR(ds.st_mode)));
|
||||
}
|
||||
struct stat ds;
|
||||
if (stat(AddDirectory(Directory, e->d_name), &ds) == 0) {
|
||||
if (!entries)
|
||||
entries = new cList<cPictureEntry>;
|
||||
entries->Add(new cPictureEntry(e->d_name, this, S_ISDIR(ds.st_mode)));
|
||||
}
|
||||
}
|
||||
if (entries)
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: pictures.c 2.3 2011/02/20 16:50:01 kls Exp $
|
||||
* $Id: pictures.c 2.4 2012/02/17 14:00:48 kls Exp $
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
@ -11,7 +11,7 @@
|
||||
#include "menu.h"
|
||||
#include "player.h"
|
||||
|
||||
static const char *VERSION = "0.1.0";
|
||||
static const char *VERSION = "0.1.1";
|
||||
static const char *DESCRIPTION = trNOOP("A simple picture viewer");
|
||||
static const char *MAINMENUENTRY = trNOOP("Pictures");
|
||||
|
||||
|
58
recording.c
58
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 2.48 2012/02/16 11:53:13 kls Exp $
|
||||
* $Id: recording.c 2.49 2012/02/17 13:57:05 kls Exp $
|
||||
*/
|
||||
|
||||
#include "recording.h"
|
||||
@ -1109,40 +1109,38 @@ void cRecordings::ScanVideoDir(const char *DirName, bool Foreground, int LinkLev
|
||||
cReadDir d(DirName);
|
||||
struct dirent *e;
|
||||
while ((Foreground || Running()) && (e = d.Next()) != NULL) {
|
||||
if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
|
||||
cString buffer = AddDirectory(DirName, e->d_name);
|
||||
struct stat st;
|
||||
if (lstat(buffer, &st) == 0) {
|
||||
int Link = 0;
|
||||
if (S_ISLNK(st.st_mode)) {
|
||||
if (LinkLevel > MAX_LINK_LEVEL) {
|
||||
isyslog("max link level exceeded - not scanning %s", *buffer);
|
||||
continue;
|
||||
}
|
||||
Link = 1;
|
||||
if (stat(buffer, &st) != 0)
|
||||
continue;
|
||||
cString buffer = AddDirectory(DirName, e->d_name);
|
||||
struct stat st;
|
||||
if (lstat(buffer, &st) == 0) {
|
||||
int Link = 0;
|
||||
if (S_ISLNK(st.st_mode)) {
|
||||
if (LinkLevel > MAX_LINK_LEVEL) {
|
||||
isyslog("max link level exceeded - not scanning %s", *buffer);
|
||||
continue;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if (endswith(buffer, deleted ? DELEXT : RECEXT)) {
|
||||
cRecording *r = new cRecording(buffer);
|
||||
if (r->Name()) {
|
||||
r->NumFrames(); // initializes the numFrames member
|
||||
Lock();
|
||||
Add(r);
|
||||
ChangeState();
|
||||
Unlock();
|
||||
if (deleted) {
|
||||
r->fileSizeMB = DirSizeMB(buffer);
|
||||
r->deleted = time(NULL);
|
||||
}
|
||||
Link = 1;
|
||||
if (stat(buffer, &st) != 0)
|
||||
continue;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if (endswith(buffer, deleted ? DELEXT : RECEXT)) {
|
||||
cRecording *r = new cRecording(buffer);
|
||||
if (r->Name()) {
|
||||
r->NumFrames(); // initializes the numFrames member
|
||||
Lock();
|
||||
Add(r);
|
||||
ChangeState();
|
||||
Unlock();
|
||||
if (deleted) {
|
||||
r->fileSizeMB = DirSizeMB(buffer);
|
||||
r->deleted = time(NULL);
|
||||
}
|
||||
else
|
||||
delete r;
|
||||
}
|
||||
else
|
||||
ScanVideoDir(buffer, Foreground, LinkLevel + Link);
|
||||
delete r;
|
||||
}
|
||||
else
|
||||
ScanVideoDir(buffer, Foreground, LinkLevel + Link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
60
themes.c
60
themes.c
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: themes.c 2.1 2011/02/25 14:45:18 kls Exp $
|
||||
* $Id: themes.c 2.2 2012/02/17 13:57:32 kls Exp $
|
||||
*/
|
||||
|
||||
#include "themes.h"
|
||||
@ -243,37 +243,35 @@ bool cThemes::Load(const char *SkinName)
|
||||
cReadDir d(themesDirectory);
|
||||
struct dirent *e;
|
||||
while ((e = d.Next()) != NULL) {
|
||||
if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
|
||||
if (strstr(e->d_name, SkinName) == e->d_name && e->d_name[strlen(SkinName)] == '-') {
|
||||
cString FileName = AddDirectory(themesDirectory, e->d_name);
|
||||
cTheme Theme;
|
||||
if (Theme.Load(*FileName, true)) {
|
||||
if (char **NewBuffer = (char **)realloc(names, (numThemes + 1) * sizeof(char *))) {
|
||||
names = NewBuffer;
|
||||
names[numThemes] = strdup(Theme.Name());
|
||||
}
|
||||
else {
|
||||
esyslog("ERROR: out of memory");
|
||||
break;
|
||||
}
|
||||
if (char **NewBuffer = (char **)realloc(fileNames, (numThemes + 1) * sizeof(char *))) {
|
||||
fileNames = NewBuffer;
|
||||
fileNames[numThemes] = strdup(*FileName);
|
||||
}
|
||||
else {
|
||||
esyslog("ERROR: out of memory");
|
||||
break;
|
||||
}
|
||||
if (char **NewBuffer = (char **)realloc(descriptions, (numThemes + 1) * sizeof(char *))) {
|
||||
descriptions = NewBuffer;
|
||||
descriptions[numThemes] = strdup(Theme.Description());
|
||||
}
|
||||
else {
|
||||
esyslog("ERROR: out of memory");
|
||||
break;
|
||||
}
|
||||
numThemes++;
|
||||
if (strstr(e->d_name, SkinName) == e->d_name && e->d_name[strlen(SkinName)] == '-') {
|
||||
cString FileName = AddDirectory(themesDirectory, e->d_name);
|
||||
cTheme Theme;
|
||||
if (Theme.Load(*FileName, true)) {
|
||||
if (char **NewBuffer = (char **)realloc(names, (numThemes + 1) * sizeof(char *))) {
|
||||
names = NewBuffer;
|
||||
names[numThemes] = strdup(Theme.Name());
|
||||
}
|
||||
else {
|
||||
esyslog("ERROR: out of memory");
|
||||
break;
|
||||
}
|
||||
if (char **NewBuffer = (char **)realloc(fileNames, (numThemes + 1) * sizeof(char *))) {
|
||||
fileNames = NewBuffer;
|
||||
fileNames[numThemes] = strdup(*FileName);
|
||||
}
|
||||
else {
|
||||
esyslog("ERROR: out of memory");
|
||||
break;
|
||||
}
|
||||
if (char **NewBuffer = (char **)realloc(descriptions, (numThemes + 1) * sizeof(char *))) {
|
||||
descriptions = NewBuffer;
|
||||
descriptions[numThemes] = strdup(Theme.Description());
|
||||
}
|
||||
else {
|
||||
esyslog("ERROR: out of memory");
|
||||
break;
|
||||
}
|
||||
numThemes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
108
tools.c
108
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 if (errno != ENOENT) {
|
||||
LOG_ERROR_STR(FileName);
|
||||
return false;
|
||||
else {
|
||||
l[n] = 0;
|
||||
dsyslog("removing %s", l);
|
||||
if (remove(l) < 0)
|
||||
LOG_ERROR_STR(l);
|
||||
}
|
||||
free(l);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user