Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve readdir speed #1116

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void checkMCFolder(void);
int openFile(char *path, int mode);
void *readFile(char *path, int align, int *size);
int listDir(char *path, const char *separator, int maxElem,
int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned int mode));
int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned char d_type));

typedef struct
{
Expand Down
3 changes: 1 addition & 2 deletions pc/iso2opl/src/iso2opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,14 @@ void scan_dir(int isBigEndian)
char *name;
char fullname[512];
char newname[512];
struct stat buf;

DIR *rep = opendir(".");
if (rep != NULL) {
while ((ent = readdir(rep)) != NULL) {
name = ent->d_name;
size = strlen(name);
sprintf(fullname, "./%s", name);
if (!stat(fullname, &buf) && !S_ISDIR(buf.st_mode)) {
if (ent->d_type != DT_DIR) {
if (strstr(name, ".iso")) {
if ((size >= 17) && (name[4] == '_') && (name[8] == '.') && (name[11] == '.')) {
printf("%s seems to be correctly named\n", fullname);
Expand Down
4 changes: 2 additions & 2 deletions src/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ char *lngGetValue(void)
return guiLangNames[guiLangID];
}

static int lngReadEntry(int index, const char *path, const char *separator, const char *name, unsigned int mode)
static int lngReadEntry(int index, const char *path, const char *separator, const char *name, unsigned char d_type)
{
if (!S_ISDIR(mode)) {
if (d_type != DT_DIR) {
if (strstr(name, ".lng") || strstr(name, ".LNG")) {

language_t *currLang = &languages[nLanguages + index];
Expand Down
5 changes: 1 addition & 4 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void
{
struct dirent *pdirent;
DIR *pdir;
struct stat st;
int i, count, ret;
item_list_t *listSupport;
config_set_t *appConfig;
Expand All @@ -499,9 +498,7 @@ int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void
continue;

snprintf(dir, sizeof(dir), "%s/%s", appsPath, pdirent->d_name);
if (stat(dir, &st) < 0)
continue;
if (!S_ISDIR(st.st_mode))
if (pdirent->d_type != DT_DIR)
continue;

snprintf(path, sizeof(path), "%s/%s", dir, APP_TITLE_CONFIG_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,9 @@ static void thmFree(theme_t *theme)
}
}

static int thmReadEntry(int index, const char *path, const char *separator, const char *name, unsigned int mode)
static int thmReadEntry(int index, const char *path, const char *separator, const char *name, unsigned char d_type)
{
if (S_ISDIR(mode) && strstr(name, "thm_")) {
if (d_type == DT_DIR && strstr(name, "thm_")) {
theme_file_t *currTheme = &themes[nThemes + index];

int length = strlen(name) - 4 + 1;
Expand Down
10 changes: 3 additions & 7 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ void *readFile(char *path, int align, int *size)
}

int listDir(char *path, const char *separator, int maxElem,
int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned int mode))
int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned char d_type))
{
int index = 0;
struct stat st;
char filename[128];

if (checkFile(path, O_RDONLY)) {
Expand All @@ -221,8 +220,7 @@ int listDir(char *path, const char *separator, int maxElem,
if (dir != NULL) {
while (index < maxElem && (dirent = readdir(dir)) != NULL) {
snprintf(filename, 128, "%s/%s", path, dirent->d_name);
stat(filename, &st);
index = readEntry(index, path, separator, dirent->d_name, st.st_mode);
index = readEntry(index, path, separator, dirent->d_name, dirent->d_type);
}

closedir(dir);
Expand Down Expand Up @@ -589,7 +587,6 @@ int sysDeleteFolder(const char *folder)
char *path;
struct dirent *dirent;
DIR *dir;
struct stat st;
struct DirentToDelete *head, *start;

result = 0;
Expand All @@ -602,9 +599,8 @@ int sysDeleteFolder(const char *folder)

path = malloc(strlen(folder) + strlen(dirent->d_name) + 2);
sprintf(path, "%s/%s", folder, dirent->d_name);
stat(path, &st);

if (S_ISDIR(st.st_mode)) {
if (dirent->d_type == DT_DIR) {
/* Recursive, delete all subfolders */
result = sysDeleteFolder(path);
free(path);
Expand Down
Loading