forked from len0rd/rockbox
consolidate the 3 file_exists() functions into one; use the version that explicitly uses dircache; give dir_exists() the same treatment for consistency
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15742 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a2ad8537af
commit
d87b037efe
10 changed files with 50 additions and 65 deletions
32
apps/misc.c
32
apps/misc.c
|
@ -1092,3 +1092,35 @@ char* strrsplt(char* str, int c)
|
|||
return s;
|
||||
}
|
||||
|
||||
/* Test file existence, using dircache of possible */
|
||||
bool file_exists(const char *file)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!file || strlen(file) <= 0)
|
||||
return false;
|
||||
|
||||
#ifdef HAVE_DIRCACHE
|
||||
if (dircache_is_enabled())
|
||||
return (dircache_get_entry_ptr(file) != NULL);
|
||||
#endif
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dir_exists(const char *path)
|
||||
{
|
||||
DIR* d = opendir(path);
|
||||
bool retval;
|
||||
if (d != NULL) {
|
||||
closedir(d);
|
||||
retval = true;
|
||||
} else {
|
||||
retval = false;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -115,4 +115,8 @@ int hex_to_rgb(const char* hex);
|
|||
|
||||
char* strrsplt(char* str, int c);
|
||||
|
||||
bool file_exists(const char *file);
|
||||
bool dir_exists(const char *path);
|
||||
|
||||
|
||||
#endif /* MISC_H */
|
||||
|
|
|
@ -522,6 +522,9 @@ static const struct plugin_api rockbox_api = {
|
|||
#ifdef PROC_NEEDS_CACHEALIGN
|
||||
align_buffer,
|
||||
#endif
|
||||
|
||||
file_exists,
|
||||
dir_exists,
|
||||
};
|
||||
|
||||
int plugin_load(const char* plugin, void* parameter)
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
#define PLUGIN_MAGIC 0x526F634B /* RocK */
|
||||
|
||||
/* increase this every time the api struct changes */
|
||||
#define PLUGIN_API_VERSION 89
|
||||
#define PLUGIN_API_VERSION 90
|
||||
|
||||
/* update this to latest version if a change to the api struct breaks
|
||||
backwards compatibility (and please take the opportunity to sort in any
|
||||
|
@ -645,6 +645,10 @@ struct plugin_api {
|
|||
#ifdef PROC_NEEDS_CACHEALIGN
|
||||
size_t (*align_buffer)(void **start, size_t size, size_t align);
|
||||
#endif
|
||||
|
||||
bool (*file_exists)(const char *file);
|
||||
bool (*dir_exists)(const char *path);
|
||||
|
||||
};
|
||||
|
||||
/* plugin header */
|
||||
|
|
|
@ -79,9 +79,6 @@ bool remove_entry(sc_file_t *file, int entry_idx);
|
|||
/* Checks whether the index is a valid one for the file. */
|
||||
bool is_valid_index(sc_file_t *file, int entry_idx);
|
||||
|
||||
bool file_exists(char *filename); /* Does the specified file exist? */
|
||||
bool dir_exists(char *path); /* Does the specified dir exist? */
|
||||
|
||||
|
||||
#ifdef SC_DEBUG
|
||||
void print_file(sc_file_t *file);
|
||||
|
|
|
@ -70,9 +70,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* void_parameter)
|
|||
* if it's a dir and then file (not vice versa) since
|
||||
* open() can also open a dir */
|
||||
found = true;
|
||||
if (dir_exists(parameter)) {
|
||||
if (rb->dir_exists(parameter)) {
|
||||
its_a_dir = true;
|
||||
} else if (file_exists(parameter)) {
|
||||
} else if (rb->file_exists(parameter)) {
|
||||
its_a_dir = false;
|
||||
} else {
|
||||
found = false;
|
||||
|
|
|
@ -360,35 +360,3 @@ void write_entry_to_file(int fd, sc_entry_t *entry)
|
|||
}
|
||||
rb->fdprintf(fd, "\n");
|
||||
}
|
||||
|
||||
|
||||
bool file_exists(char *filename)
|
||||
{
|
||||
int fd = rb->open(filename, O_RDONLY);
|
||||
bool retval;
|
||||
if (fd >= 0) {
|
||||
rb->close(fd);
|
||||
retval = true;
|
||||
} else {
|
||||
retval = false;
|
||||
}
|
||||
DEBUGF("Checked existence of the file '%s': %s\n",
|
||||
filename, (retval ? "found" : "NOT FOUND"));
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
bool dir_exists(char *path)
|
||||
{
|
||||
DIR* d = rb->opendir(path);
|
||||
bool retval;
|
||||
if (d != NULL) {
|
||||
rb->closedir(d);
|
||||
retval = true;
|
||||
} else {
|
||||
retval = false;
|
||||
}
|
||||
DEBUGF("Checked existence of the dir '%s': %s\n",
|
||||
path, (retval ? "found" : "NOT FOUND"));
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -166,10 +166,10 @@ bool goto_entry(char *file_or_dir)
|
|||
char *what;
|
||||
if (is_dir) {
|
||||
what = "Directory";
|
||||
exists = dir_exists(file_or_dir);
|
||||
exists = rb->dir_exists(file_or_dir);
|
||||
} else {
|
||||
what = "File";
|
||||
exists = file_exists(file_or_dir);
|
||||
exists = rb->file_exists(file_or_dir);
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "buffering.h"
|
||||
#include "dircache.h"
|
||||
#include "debug.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
/* Strip filename from a full path
|
||||
|
@ -89,26 +90,6 @@ static char* strip_extension(char* buf, int buf_size, const char* file)
|
|||
return buf;
|
||||
}
|
||||
|
||||
/* Test file existence, using dircache of possible */
|
||||
static bool file_exists(const char *file)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!file || strlen(file) <= 0)
|
||||
return false;
|
||||
|
||||
#ifdef HAVE_DIRCACHE
|
||||
if (dircache_is_enabled())
|
||||
return (dircache_get_entry_ptr(file) != NULL);
|
||||
#endif
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Make sure part of path only contain chars valid for a FAT32 long name.
|
||||
* Double quotes are replaced with single quotes, other unsupported chars
|
||||
* are replaced with an underscore.
|
||||
|
|
|
@ -3807,12 +3807,8 @@ static bool check_dir(const char *dirname)
|
|||
|
||||
/* check for a database.ignore file */
|
||||
snprintf(newpath, MAX_PATH, "%s/database.ignore", dirname);
|
||||
len = open(newpath, O_RDONLY);
|
||||
if (len >= 0)
|
||||
{
|
||||
close(len);
|
||||
if(file_exists(newpath))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Recursively scan the dir. */
|
||||
#ifdef __PCTOOL__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue