summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kukla <roolku@rockbox.org>2007-11-21 21:28:27 +0000
committerRobert Kukla <roolku@rockbox.org>2007-11-21 21:28:27 +0000
commitd87b037efe7d001902c0cde992e1633ff9f70061 (patch)
treeddea298e51d73443aad0d31fca7d59311444efab
parenta2ad8537af659972b2e859c99c0ff75e374b73f9 (diff)
downloadrockbox-d87b037efe7d001902c0cde992e1633ff9f70061.tar.gz
rockbox-d87b037efe7d001902c0cde992e1633ff9f70061.zip
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
-rw-r--r--apps/misc.c32
-rw-r--r--apps/misc.h4
-rw-r--r--apps/plugin.c3
-rw-r--r--apps/plugin.h6
-rw-r--r--apps/plugins/shortcuts/shortcuts.h3
-rw-r--r--apps/plugins/shortcuts/shortcuts_append.c4
-rw-r--r--apps/plugins/shortcuts/shortcuts_common.c32
-rw-r--r--apps/plugins/shortcuts/shortcuts_view.c4
-rw-r--r--apps/recorder/albumart.c21
-rw-r--r--apps/tagcache.c6
10 files changed, 50 insertions, 65 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 4af97afb5e..a8710c312f 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1092,3 +1092,35 @@ char* strrsplt(char* str, int c)
1092 return s; 1092 return s;
1093} 1093}
1094 1094
1095/* Test file existence, using dircache of possible */
1096bool file_exists(const char *file)
1097{
1098 int fd;
1099
1100 if (!file || strlen(file) <= 0)
1101 return false;
1102
1103#ifdef HAVE_DIRCACHE
1104 if (dircache_is_enabled())
1105 return (dircache_get_entry_ptr(file) != NULL);
1106#endif
1107
1108 fd = open(file, O_RDONLY);
1109 if (fd < 0)
1110 return false;
1111 close(fd);
1112 return true;
1113}
1114
1115bool dir_exists(const char *path)
1116{
1117 DIR* d = opendir(path);
1118 bool retval;
1119 if (d != NULL) {
1120 closedir(d);
1121 retval = true;
1122 } else {
1123 retval = false;
1124 }
1125 return retval;
1126}
diff --git a/apps/misc.h b/apps/misc.h
index ab0e592aa0..590ccf013f 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -115,4 +115,8 @@ int hex_to_rgb(const char* hex);
115 115
116char* strrsplt(char* str, int c); 116char* strrsplt(char* str, int c);
117 117
118bool file_exists(const char *file);
119bool dir_exists(const char *path);
120
121
118#endif /* MISC_H */ 122#endif /* MISC_H */
diff --git a/apps/plugin.c b/apps/plugin.c
index 145d30b41b..9b620b1280 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -522,6 +522,9 @@ static const struct plugin_api rockbox_api = {
522#ifdef PROC_NEEDS_CACHEALIGN 522#ifdef PROC_NEEDS_CACHEALIGN
523 align_buffer, 523 align_buffer,
524#endif 524#endif
525
526 file_exists,
527 dir_exists,
525}; 528};
526 529
527int plugin_load(const char* plugin, void* parameter) 530int plugin_load(const char* plugin, void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index 9123af44ec..0aacd4e5fa 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -113,7 +113,7 @@
113#define PLUGIN_MAGIC 0x526F634B /* RocK */ 113#define PLUGIN_MAGIC 0x526F634B /* RocK */
114 114
115/* increase this every time the api struct changes */ 115/* increase this every time the api struct changes */
116#define PLUGIN_API_VERSION 89 116#define PLUGIN_API_VERSION 90
117 117
118/* update this to latest version if a change to the api struct breaks 118/* update this to latest version if a change to the api struct breaks
119 backwards compatibility (and please take the opportunity to sort in any 119 backwards compatibility (and please take the opportunity to sort in any
@@ -645,6 +645,10 @@ struct plugin_api {
645#ifdef PROC_NEEDS_CACHEALIGN 645#ifdef PROC_NEEDS_CACHEALIGN
646 size_t (*align_buffer)(void **start, size_t size, size_t align); 646 size_t (*align_buffer)(void **start, size_t size, size_t align);
647#endif 647#endif
648
649 bool (*file_exists)(const char *file);
650 bool (*dir_exists)(const char *path);
651
648}; 652};
649 653
650/* plugin header */ 654/* plugin header */
diff --git a/apps/plugins/shortcuts/shortcuts.h b/apps/plugins/shortcuts/shortcuts.h
index 6ccb320a36..34f200d193 100644
--- a/apps/plugins/shortcuts/shortcuts.h
+++ b/apps/plugins/shortcuts/shortcuts.h
@@ -79,9 +79,6 @@ bool remove_entry(sc_file_t *file, int entry_idx);
79/* Checks whether the index is a valid one for the file. */ 79/* Checks whether the index is a valid one for the file. */
80bool is_valid_index(sc_file_t *file, int entry_idx); 80bool is_valid_index(sc_file_t *file, int entry_idx);
81 81
82bool file_exists(char *filename); /* Does the specified file exist? */
83bool dir_exists(char *path); /* Does the specified dir exist? */
84
85 82
86#ifdef SC_DEBUG 83#ifdef SC_DEBUG
87void print_file(sc_file_t *file); 84void print_file(sc_file_t *file);
diff --git a/apps/plugins/shortcuts/shortcuts_append.c b/apps/plugins/shortcuts/shortcuts_append.c
index bc287234dd..afd03929ae 100644
--- a/apps/plugins/shortcuts/shortcuts_append.c
+++ b/apps/plugins/shortcuts/shortcuts_append.c
@@ -70,9 +70,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* void_parameter)
70 * if it's a dir and then file (not vice versa) since 70 * if it's a dir and then file (not vice versa) since
71 * open() can also open a dir */ 71 * open() can also open a dir */
72 found = true; 72 found = true;
73 if (dir_exists(parameter)) { 73 if (rb->dir_exists(parameter)) {
74 its_a_dir = true; 74 its_a_dir = true;
75 } else if (file_exists(parameter)) { 75 } else if (rb->file_exists(parameter)) {
76 its_a_dir = false; 76 its_a_dir = false;
77 } else { 77 } else {
78 found = false; 78 found = false;
diff --git a/apps/plugins/shortcuts/shortcuts_common.c b/apps/plugins/shortcuts/shortcuts_common.c
index 4a097f0a0d..91e3084e10 100644
--- a/apps/plugins/shortcuts/shortcuts_common.c
+++ b/apps/plugins/shortcuts/shortcuts_common.c
@@ -360,35 +360,3 @@ void write_entry_to_file(int fd, sc_entry_t *entry)
360 } 360 }
361 rb->fdprintf(fd, "\n"); 361 rb->fdprintf(fd, "\n");
362} 362}
363
364
365bool file_exists(char *filename)
366{
367 int fd = rb->open(filename, O_RDONLY);
368 bool retval;
369 if (fd >= 0) {
370 rb->close(fd);
371 retval = true;
372 } else {
373 retval = false;
374 }
375 DEBUGF("Checked existence of the file '%s': %s\n",
376 filename, (retval ? "found" : "NOT FOUND"));
377 return retval;
378}
379
380
381bool dir_exists(char *path)
382{
383 DIR* d = rb->opendir(path);
384 bool retval;
385 if (d != NULL) {
386 rb->closedir(d);
387 retval = true;
388 } else {
389 retval = false;
390 }
391 DEBUGF("Checked existence of the dir '%s': %s\n",
392 path, (retval ? "found" : "NOT FOUND"));
393 return retval;
394}
diff --git a/apps/plugins/shortcuts/shortcuts_view.c b/apps/plugins/shortcuts/shortcuts_view.c
index f61177f37a..4ef1bbc816 100644
--- a/apps/plugins/shortcuts/shortcuts_view.c
+++ b/apps/plugins/shortcuts/shortcuts_view.c
@@ -166,10 +166,10 @@ bool goto_entry(char *file_or_dir)
166 char *what; 166 char *what;
167 if (is_dir) { 167 if (is_dir) {
168 what = "Directory"; 168 what = "Directory";
169 exists = dir_exists(file_or_dir); 169 exists = rb->dir_exists(file_or_dir);
170 } else { 170 } else {
171 what = "File"; 171 what = "File";
172 exists = file_exists(file_or_dir); 172 exists = rb->file_exists(file_or_dir);
173 } 173 }
174 174
175 if (!exists) { 175 if (!exists) {
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c
index d99280ce85..6aaf3885d7 100644
--- a/apps/recorder/albumart.c
+++ b/apps/recorder/albumart.c
@@ -26,6 +26,7 @@
26#include "buffering.h" 26#include "buffering.h"
27#include "dircache.h" 27#include "dircache.h"
28#include "debug.h" 28#include "debug.h"
29#include "misc.h"
29 30
30 31
31/* Strip filename from a full path 32/* Strip filename from a full path
@@ -89,26 +90,6 @@ static char* strip_extension(char* buf, int buf_size, const char* file)
89 return buf; 90 return buf;
90} 91}
91 92
92/* Test file existence, using dircache of possible */
93static bool file_exists(const char *file)
94{
95 int fd;
96
97 if (!file || strlen(file) <= 0)
98 return false;
99
100#ifdef HAVE_DIRCACHE
101 if (dircache_is_enabled())
102 return (dircache_get_entry_ptr(file) != NULL);
103#endif
104
105 fd = open(file, O_RDONLY);
106 if (fd < 0)
107 return false;
108 close(fd);
109 return true;
110}
111
112/* Make sure part of path only contain chars valid for a FAT32 long name. 93/* Make sure part of path only contain chars valid for a FAT32 long name.
113 * Double quotes are replaced with single quotes, other unsupported chars 94 * Double quotes are replaced with single quotes, other unsupported chars
114 * are replaced with an underscore. 95 * are replaced with an underscore.
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 91220a3517..2882aa8b00 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -3807,12 +3807,8 @@ static bool check_dir(const char *dirname)
3807 3807
3808 /* check for a database.ignore file */ 3808 /* check for a database.ignore file */
3809 snprintf(newpath, MAX_PATH, "%s/database.ignore", dirname); 3809 snprintf(newpath, MAX_PATH, "%s/database.ignore", dirname);
3810 len = open(newpath, O_RDONLY); 3810 if(file_exists(newpath))
3811 if (len >= 0)
3812 {
3813 close(len);
3814 return false; 3811 return false;
3815 }
3816 3812
3817 /* Recursively scan the dir. */ 3813 /* Recursively scan the dir. */
3818#ifdef __PCTOOL__ 3814#ifdef __PCTOOL__