diff options
| author | Thomas Martitz <kugel@rockbox.org> | 2010-12-06 22:26:31 +0000 |
|---|---|---|
| committer | Thomas Martitz <kugel@rockbox.org> | 2010-12-06 22:26:31 +0000 |
| commit | 2c2416094f426972c9e2e96d25058311bbe82f97 (patch) | |
| tree | 449b4e12e01c3c5c4afa2ae6a8cd396df82b5a38 /apps/tagcache.c | |
| parent | c35b43b0f54bd607d38908544446caaa02f148a3 (diff) | |
| download | rockbox-2c2416094f426972c9e2e96d25058311bbe82f97.zip rockbox-2c2416094f426972c9e2e96d25058311bbe82f97.tar.gz rockbox-2c2416094f426972c9e2e96d25058311bbe82f97.tar.bz2 rockbox-2c2416094f426972c9e2e96d25058311bbe82f97.tar.xz | |
Get rid of get_user_file_path and do the path handling in wrappers for open() and friends.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28752 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tagcache.c')
| -rw-r--r-- | apps/tagcache.c | 145 |
1 files changed, 45 insertions, 100 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 679d7cb..5b175c4 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -73,9 +73,9 @@ #include "buffer.h" #include "crc32.h" #include "misc.h" -#include "filefuncs.h" #include "settings.h" #include "dir.h" +#include "filefuncs.h" #include "structec.h" #ifndef __PCTOOL__ @@ -293,17 +293,15 @@ static bool is_dircache_intact(void) static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) { int fd; - char buf[MAX_PATH], path[MAX_PATH]; - const char * file; + char buf[MAX_PATH]; int rc; if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) return -1; snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - fd = open(file, write ? O_RDWR : O_RDONLY); + fd = open(buf, write ? O_RDWR : O_RDONLY); if (fd < 0) { logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); @@ -328,12 +326,8 @@ static int open_master_fd(struct master_header *hdr, bool write) { int fd; int rc; - char path[MAX_PATH]; - fd = open(get_user_file_path(TAGCACHE_FILE_MASTER, - IS_FILE|NEED_WRITE, - path, sizeof(path)), - write ? O_RDWR : O_RDONLY); + fd = open(TAGCACHE_FILE_MASTER, write ? O_RDWR : O_RDONLY); if (fd < 0) { logf("master file open failed for R/W"); @@ -675,12 +669,10 @@ static bool open_files(struct tagcache_search *tcs, int tag) { if (tcs->idxfd[tag] < 0) { - char fn[MAX_PATH], path[MAX_PATH]; - const char *file; + char fn[MAX_PATH]; snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); - file = get_user_file_path(fn, IS_FILE | NEED_WRITE, path, sizeof(path)); - tcs->idxfd[tag] = open(file, O_RDONLY); + tcs->idxfd[tag] = open(fn, O_RDONLY); } if (tcs->idxfd[tag] < 0) @@ -1218,17 +1210,14 @@ static void remove_files(void) tc_stat.ready = false; tc_stat.ramcache = false; tc_stat.econ = false; - remove(get_user_file_path(TAGCACHE_FILE_MASTER, NEED_WRITE|IS_FILE, - buf, sizeof(buf))); + remove(TAGCACHE_FILE_MASTER); for (i = 0; i < TAG_COUNT; i++) { - char buf2[MAX_PATH]; if (TAGCACHE_IS_NUMERIC(i)) continue; - - /* database_%d.tcd -> database_0.tcd */ + snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i); - remove(get_user_file_path(buf, NEED_WRITE | IS_FILE, buf2, sizeof(buf2))); + remove(buf); } } @@ -1379,11 +1368,10 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) { - char buf[MAX_PATH], path[MAX_PATH]; - const char *file; - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - tcs->idxfd[clause->tag] = open(file, O_RDONLY); + char buf[MAX_PATH]; + + snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); + tcs->idxfd[clause->tag] = open(buf, O_RDONLY); } tcs->clause[tcs->clause_count] = clause; @@ -2407,8 +2395,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) struct master_header tcmh; struct index_entry idxbuf[IDX_BUF_DEPTH]; int idxbuf_pos; - char buf[TAG_MAXLEN+32], path[MAX_PATH]; - const char *file; + char buf[TAG_MAXLEN+32]; int fd = -1, masterfd; bool error = false; int init; @@ -2556,8 +2543,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) * anything whether the index type is sorted or not. */ snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { logf("%s open fail", buf); @@ -2577,21 +2563,18 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) } } - file = get_user_file_path(TAGCACHE_FILE_MASTER, - IS_FILE|NEED_WRITE, - buf, sizeof(buf)); /* Loading the tag lookup file as "master file". */ logf("Loading index file"); - masterfd = open(file, O_RDWR); + masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR); if (masterfd < 0) { logf("Creating new DB"); - masterfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (masterfd < 0) { - logf("Failure to create index file (%s)", file); + logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER); close(fd); return -2; } @@ -2899,8 +2882,6 @@ static bool commit(void) { struct tagcache_header tch; struct master_header tcmh; - char path[MAX_PATH]; - const char *file; int i, len, rc; int tmpfd; int masterfd; @@ -2914,10 +2895,7 @@ static bool commit(void) while (write_lock) sleep(1); - file = get_user_file_path(TAGCACHE_FILE_TEMP, - IS_FILE|NEED_WRITE, path, sizeof(path)); - - tmpfd = open(file, O_RDONLY); + tmpfd = open(TAGCACHE_FILE_TEMP, O_RDONLY); if (tmpfd < 0) { logf("nothing to commit"); @@ -2933,7 +2911,7 @@ static bool commit(void) { logf("incorrect tmpheader"); close(tmpfd); - remove(file); + remove(TAGCACHE_FILE_TEMP); return false; } @@ -2941,7 +2919,7 @@ static bool commit(void) { logf("nothing to commit"); close(tmpfd); - remove(file); + remove(TAGCACHE_FILE_TEMP); return true; } @@ -2949,8 +2927,7 @@ static bool commit(void) tc_stat.ready = check_all_headers(); #ifdef HAVE_EEPROM_SETTINGS - remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path))); + remove(TAGCACHE_STATEFILE); #endif /* At first be sure to unload the ramcache! */ @@ -3040,7 +3017,7 @@ static bool commit(void) } close(tmpfd); - remove(file); + remove(TAGCACHE_FILE_TEMP); tc_stat.commit_step = 0; @@ -3458,18 +3435,15 @@ bool tagcache_import_changelog(void) struct tagcache_header tch; int clfd; long masterfd; - char buf[MAX(MAX_PATH, 2048)]; - const char *file; + char buf[2048]; if (!tc_stat.ready) return false; while (read_lock) sleep(1); - - file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, - IS_FILE|NEED_WRITE, buf, sizeof(buf)); - clfd = open(file, O_RDONLY); + + clfd = open(TAGCACHE_FILE_CHANGELOG, O_RDONLY); if (clfd < 0) { logf("failure to open changelog"); @@ -3511,8 +3485,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) { struct master_header myhdr; struct index_entry idx; - const char *file; - char buf[MAX(TAG_MAXLEN+32, MAX_PATH)]; + char buf[TAG_MAXLEN+32]; char temp[32]; int clfd; int i, j; @@ -3524,9 +3497,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) return false; /* Initialize the changelog */ - file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, IS_FILE | NEED_WRITE, - buf, sizeof(buf)); - clfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (clfd < 0) { logf("failure to open changelog"); @@ -3844,15 +3815,11 @@ static bool allocate_tagcache(void) static bool tagcache_dumpload(void) { struct statefile_header shdr; - char path[MAX_PATH]; - const char *file; int fd, rc; long offpos; int i; - - file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path)); - fd = open(file, O_RDONLY); + + fd = open(TAGCACHE_STATEFILE, O_RDONLY); if (fd < 0) { logf("no tagcache statedump"); @@ -3898,16 +3865,12 @@ static bool tagcache_dumpload(void) static bool tagcache_dumpsave(void) { struct statefile_header shdr; - char path[MAX_PATH]; - const char *file; int fd; if (!tc_stat.ramcache) return false; - file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path)); - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { logf("failed to create a statedump"); @@ -3933,8 +3896,7 @@ static bool load_tagcache(void) long bytesleft = tc_stat.ramcache_allocated; struct index_entry *idx; int rc, fd; - char *p, path[MAX_PATH]; - const char *file; + char *p; int i, tag; # ifdef HAVE_DIRCACHE @@ -3945,11 +3907,8 @@ static bool load_tagcache(void) # endif logf("loading tagcache to ram..."); - - file = get_user_file_path(TAGCACHE_FILE_MASTER, - IS_FILE|NEED_WRITE, - path, sizeof(path)); - fd = open(file, O_RDONLY); + + fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); if (fd < 0) { logf("tagcache open failed"); @@ -4159,14 +4118,12 @@ static bool load_tagcache(void) static bool check_deleted_files(void) { int fd; - char buf[TAG_MAXLEN+32], path[MAX_PATH]; - const char *file; + char buf[TAG_MAXLEN+32]; struct tagfile_entry tfe; logf("reverse scan..."); snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename); - file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); - fd = open(file, O_RDONLY); + fd = open(buf, O_RDONLY); if (fd < 0) { @@ -4326,8 +4283,6 @@ void tagcache_build(const char *path) { struct tagcache_header header; bool ret; - char buf[MAX_PATH]; - const char *file; curpath[0] = '\0'; data_size = 0; @@ -4340,21 +4295,19 @@ void tagcache_build(const char *path) #endif logf("updating tagcache"); - - file = get_user_file_path(TAGCACHE_FILE_TEMP, - IS_FILE|NEED_WRITE, buf, sizeof(buf)); - - if (file_exists(file)) + cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); + if (cachefd >= 0) { logf("skipping, cache already waiting for commit"); + close(cachefd); return ; } - cachefd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0666); + cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666); if (cachefd < 0) { - logf("master file open failed: %s", file); + logf("master file open failed: %s", TAGCACHE_FILE_TEMP); return ; } @@ -4398,7 +4351,7 @@ void tagcache_build(const char *path) #endif if (commit()) { - remove(file); + remove(TAGCACHE_FILE_TEMP); logf("tagcache built!"); } #ifdef __PCTOOL__ @@ -4443,12 +4396,7 @@ void tagcache_unload_ramcache(void) { tc_stat.ramcache = false; /* Just to make sure there is no statefile present. */ - -#if 0 - char path[MAX_PATH]; - remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path))); -#endif + // remove(TAGCACHE_STATEFILE); } #endif @@ -4457,7 +4405,6 @@ static void tagcache_thread(void) { struct queue_event ev; bool check_done = false; - char path[MAX_PATH]; /* If the previous cache build/update was interrupted, commit * the changes first in foreground. */ @@ -4474,8 +4421,7 @@ static void tagcache_thread(void) check_done = tagcache_dumpload(); } - remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, - path, sizeof(path))); + remove(TAGCACHE_STATEFILE); # endif /* Allocate space for the tagcache if found on disk. */ @@ -4508,8 +4454,7 @@ static void tagcache_thread(void) case Q_REBUILD: remove_files(); - remove(get_user_file_path(TAGCACHE_FILE_TEMP, - IS_FILE|NEED_WRITE, path, sizeof(path))); + remove(TAGCACHE_FILE_TEMP); tagcache_build("/"); break; |