diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-03 13:08:08 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-03 13:13:16 +0000 |
commit | 879b5dae3983441d60b5860a3924cf3248284a03 (patch) | |
tree | c51ddd9f436bafe15c721081e317bc2e2163bac8 | |
parent | 3957aa87205e8263384f7b50ed18c1df0de0b057 (diff) | |
download | rockbox-879b5dae3983441d60b5860a3924cf3248284a03.tar.gz rockbox-879b5dae3983441d60b5860a3924cf3248284a03.zip |
Fix red 8f582c90de
global_settings is not defined when building the database tool.
Add a path buffer in tc_stat to fix this. This also avoids race
conditions that may occur if changing the path setting at runtime.
Change-Id: Ib2ca92c2e34929c79b19ef145fd7ccdcd62c8d04
-rw-r--r-- | apps/tagcache.c | 22 | ||||
-rw-r--r-- | apps/tagcache.h | 2 |
2 files changed, 15 insertions, 9 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 228b7cb751..c853c9d5e8 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -484,12 +484,12 @@ static int NO_INLINE open_db_fd(const char* filename, int mode) | |||
484 | 484 | ||
485 | if(mode & O_CREAT) | 485 | if(mode & O_CREAT) |
486 | { | 486 | { |
487 | if (mkdir(global_settings.tagcache_db_path) < 0 && errno != EEXIST) | 487 | if (mkdir(tc_stat.db_path) < 0 && errno != EEXIST) |
488 | return -1; | 488 | return -1; |
489 | } | 489 | } |
490 | 490 | ||
491 | return open_pathfmt(buf, sizeof(buf), mode, "%s/%s", | 491 | return open_pathfmt(buf, sizeof(buf), mode, "%s/%s", |
492 | global_settings.tagcache_db_path, filename); | 492 | tc_stat.db_path, filename); |
493 | } | 493 | } |
494 | 494 | ||
495 | static int NO_INLINE remove_db_file(const char* filename) | 495 | static int NO_INLINE remove_db_file(const char* filename) |
@@ -497,7 +497,7 @@ static int NO_INLINE remove_db_file(const char* filename) | |||
497 | char buf[MAX_PATH]; | 497 | char buf[MAX_PATH]; |
498 | 498 | ||
499 | snprintf(buf, sizeof(buf), "%s/%s", | 499 | snprintf(buf, sizeof(buf), "%s/%s", |
500 | global_settings.tagcache_db_path, filename); | 500 | tc_stat.db_path, filename); |
501 | 501 | ||
502 | return remove(buf); | 502 | return remove(buf); |
503 | } | 503 | } |
@@ -513,7 +513,7 @@ static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) | |||
513 | 513 | ||
514 | fd = open_pathfmt(fname, sizeof(fname), | 514 | fd = open_pathfmt(fname, sizeof(fname), |
515 | write ? O_RDWR : O_RDONLY, "%s/" TAGCACHE_FILE_INDEX, | 515 | write ? O_RDWR : O_RDONLY, "%s/" TAGCACHE_FILE_INDEX, |
516 | global_settings.tagcache_db_path, tag); | 516 | tc_stat.db_path, tag); |
517 | if (fd < 0) | 517 | if (fd < 0) |
518 | { | 518 | { |
519 | logf("tag file open failed: tag=%d write=%d file= " TAGCACHE_FILE_INDEX, | 519 | logf("tag file open failed: tag=%d write=%d file= " TAGCACHE_FILE_INDEX, |
@@ -891,7 +891,7 @@ static bool open_files(struct tagcache_search *tcs, int tag) | |||
891 | char fname[MAX_PATH]; | 891 | char fname[MAX_PATH]; |
892 | tcs->idxfd[tag] = open_pathfmt(fname, sizeof(fname), | 892 | tcs->idxfd[tag] = open_pathfmt(fname, sizeof(fname), |
893 | O_RDONLY, "%s/" TAGCACHE_FILE_INDEX, | 893 | O_RDONLY, "%s/" TAGCACHE_FILE_INDEX, |
894 | global_settings.tagcache_db_path, tag); | 894 | tc_stat.db_path, tag); |
895 | } | 895 | } |
896 | 896 | ||
897 | if (tcs->idxfd[tag] < 0) | 897 | if (tcs->idxfd[tag] < 0) |
@@ -1516,7 +1516,7 @@ static void remove_files(void) | |||
1516 | continue; | 1516 | continue; |
1517 | 1517 | ||
1518 | snprintf(buf, bufsz, "%s/" TAGCACHE_FILE_INDEX, | 1518 | snprintf(buf, bufsz, "%s/" TAGCACHE_FILE_INDEX, |
1519 | global_settings.tagcache_db_path, i); | 1519 | tc_stat.db_path, i); |
1520 | remove(buf); | 1520 | remove(buf); |
1521 | } | 1521 | } |
1522 | } | 1522 | } |
@@ -1676,7 +1676,7 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, | |||
1676 | char fname[MAX_PATH]; | 1676 | char fname[MAX_PATH]; |
1677 | tcs->idxfd[clause->tag] = open_pathfmt(fname, sizeof(fname), O_RDONLY, | 1677 | tcs->idxfd[clause->tag] = open_pathfmt(fname, sizeof(fname), O_RDONLY, |
1678 | "%s/" TAGCACHE_FILE_INDEX, | 1678 | "%s/" TAGCACHE_FILE_INDEX, |
1679 | global_settings.tagcache_db_path, clause->tag); | 1679 | tc_stat.db_path, clause->tag); |
1680 | } | 1680 | } |
1681 | } | 1681 | } |
1682 | 1682 | ||
@@ -2830,7 +2830,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2830 | */ | 2830 | */ |
2831 | fd = open_pathfmt(buf, bufsz, O_WRONLY | O_CREAT | O_TRUNC, | 2831 | fd = open_pathfmt(buf, bufsz, O_WRONLY | O_CREAT | O_TRUNC, |
2832 | "%s/" TAGCACHE_FILE_INDEX, | 2832 | "%s/" TAGCACHE_FILE_INDEX, |
2833 | global_settings.tagcache_db_path, index_type); | 2833 | tc_stat.db_path, index_type); |
2834 | if (fd < 0) | 2834 | if (fd < 0) |
2835 | { | 2835 | { |
2836 | logf(TAGCACHE_FILE_INDEX " open fail", index_type); | 2836 | logf(TAGCACHE_FILE_INDEX " open fail", index_type); |
@@ -4487,7 +4487,7 @@ static bool check_deleted_files(void) | |||
4487 | 4487 | ||
4488 | logf("reverse scan..."); | 4488 | logf("reverse scan..."); |
4489 | fd = open_pathfmt(buf, bufsz, O_RDONLY, "%s/" TAGCACHE_FILE_INDEX, | 4489 | fd = open_pathfmt(buf, bufsz, O_RDONLY, "%s/" TAGCACHE_FILE_INDEX, |
4490 | global_settings.tagcache_db_path, tag_filename); | 4490 | tc_stat.db_path, tag_filename); |
4491 | if (fd < 0) | 4491 | if (fd < 0) |
4492 | { | 4492 | { |
4493 | logf(TAGCACHE_FILE_INDEX " open fail", tag_filename); | 4493 | logf(TAGCACHE_FILE_INDEX " open fail", tag_filename); |
@@ -5126,6 +5126,8 @@ void tagcache_init(void) | |||
5126 | write_lock = read_lock = 0; | 5126 | write_lock = read_lock = 0; |
5127 | 5127 | ||
5128 | #ifndef __PCTOOL__ | 5128 | #ifndef __PCTOOL__ |
5129 | strmemccpy(tc_stat.db_path, global_settings.tagcache_db_path, | ||
5130 | sizeof(tc_stat.db_path)); | ||
5129 | mutex_init(&command_queue_mutex); | 5131 | mutex_init(&command_queue_mutex); |
5130 | queue_init(&tagcache_queue, true); | 5132 | queue_init(&tagcache_queue, true); |
5131 | create_thread(tagcache_thread, tagcache_stack, | 5133 | create_thread(tagcache_thread, tagcache_stack, |
@@ -5133,6 +5135,8 @@ void tagcache_init(void) | |||
5133 | IF_PRIO(, PRIORITY_BACKGROUND) | 5135 | IF_PRIO(, PRIORITY_BACKGROUND) |
5134 | IF_COP(, CPU)); | 5136 | IF_COP(, CPU)); |
5135 | #else | 5137 | #else |
5138 | /* use default DB path */ | ||
5139 | strcpy(tc_stat.db_path, ROCKBOX_DIR); | ||
5136 | tc_stat.initialized = true; | 5140 | tc_stat.initialized = true; |
5137 | allocate_tempbuf(); | 5141 | allocate_tempbuf(); |
5138 | commit(); | 5142 | commit(); |
diff --git a/apps/tagcache.h b/apps/tagcache.h index 11d58c01bd..b3baba0f30 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "config.h" | 25 | #include "config.h" |
26 | #include "system.h" | 26 | #include "system.h" |
27 | #include "metadata.h" | 27 | #include "metadata.h" |
28 | #include "settings.h" | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | Note: When adding new tags, make sure to update index_entry_ec and tags_str in | 31 | Note: When adding new tags, make sure to update index_entry_ec and tags_str in |
@@ -89,6 +90,7 @@ struct tagcache_stat { | |||
89 | *curentry; /* Path of the current entry being scanned. */ | 90 | *curentry; /* Path of the current entry being scanned. */ |
90 | volatile bool syncscreen;/* Synchronous operation with debug screen? */ | 91 | volatile bool syncscreen;/* Synchronous operation with debug screen? */ |
91 | // const char *uimessage; /* Pending error message. Implement soon. */ | 92 | // const char *uimessage; /* Pending error message. Implement soon. */ |
93 | char db_path[MAX_PATHNAME+1]; /* Path to DB root directory */ | ||
92 | }; | 94 | }; |
93 | 95 | ||
94 | enum source_type {source_constant, | 96 | enum source_type {source_constant, |