diff options
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r-- | apps/tagcache.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index b91195813e..a297bc7353 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -422,19 +422,17 @@ static ssize_t ecwrite_index_entry(int fd, struct index_entry *buf) | |||
422 | static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) | 422 | static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) |
423 | { | 423 | { |
424 | int fd; | 424 | int fd; |
425 | char buf[MAX_PATH]; | ||
426 | const int bufsz = sizeof(buf); | ||
427 | int rc; | 425 | int rc; |
428 | 426 | ||
429 | if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) | 427 | if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) |
430 | return -1; | 428 | return -1; |
431 | 429 | ||
432 | snprintf(buf, bufsz, TAGCACHE_FILE_INDEX, tag); | 430 | fd = open_pathfmt(write ? O_RDWR : O_RDONLY, TAGCACHE_FILE_INDEX, tag); |
433 | 431 | ||
434 | fd = open(buf, write ? O_RDWR : O_RDONLY); | ||
435 | if (fd < 0) | 432 | if (fd < 0) |
436 | { | 433 | { |
437 | logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); | 434 | logf("tag file open failed: tag=%d write=%d file= " TAGCACHE_FILE_INDEX, |
435 | tag, write, tag); | ||
438 | tc_stat.ready = false; | 436 | tc_stat.ready = false; |
439 | return fd; | 437 | return fd; |
440 | } | 438 | } |
@@ -805,10 +803,7 @@ static bool open_files(struct tagcache_search *tcs, int tag) | |||
805 | { | 803 | { |
806 | if (tcs->idxfd[tag] < 0) | 804 | if (tcs->idxfd[tag] < 0) |
807 | { | 805 | { |
808 | char fn[MAX_PATH]; | 806 | tcs->idxfd[tag] = open_pathfmt(O_RDONLY, TAGCACHE_FILE_INDEX, tag); |
809 | |||
810 | snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); | ||
811 | tcs->idxfd[tag] = open(fn, O_RDONLY); | ||
812 | } | 807 | } |
813 | 808 | ||
814 | if (tcs->idxfd[tag] < 0) | 809 | if (tcs->idxfd[tag] < 0) |
@@ -1588,12 +1583,9 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, | |||
1588 | } | 1583 | } |
1589 | 1584 | ||
1590 | if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) | 1585 | if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) |
1591 | { | 1586 | { |
1592 | char buf[MAX_PATH]; | 1587 | tcs->idxfd[clause->tag] = open_pathfmt(O_RDONLY, |
1593 | const int bufsz = sizeof(buf); | 1588 | TAGCACHE_FILE_INDEX, clause->tag); |
1594 | |||
1595 | snprintf(buf, bufsz, TAGCACHE_FILE_INDEX, clause->tag); | ||
1596 | tcs->idxfd[clause->tag] = open(buf, O_RDONLY); | ||
1597 | } | 1589 | } |
1598 | } | 1590 | } |
1599 | 1591 | ||
@@ -2751,11 +2743,11 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2751 | * Creating new index file to store the tags. No need to preload | 2743 | * Creating new index file to store the tags. No need to preload |
2752 | * anything whether the index type is sorted or not. | 2744 | * anything whether the index type is sorted or not. |
2753 | */ | 2745 | */ |
2754 | snprintf(buf, bufsz, TAGCACHE_FILE_INDEX, index_type); | 2746 | fd = open_pathfmt(O_WRONLY | O_CREAT | O_TRUNC, |
2755 | fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 2747 | TAGCACHE_FILE_INDEX, index_type); |
2756 | if (fd < 0) | 2748 | if (fd < 0) |
2757 | { | 2749 | { |
2758 | logf("%s open fail", buf); | 2750 | logf(TAGCACHE_FILE_INDEX " open fail", index_type); |
2759 | return -2; | 2751 | return -2; |
2760 | } | 2752 | } |
2761 | 2753 | ||
@@ -4408,12 +4400,11 @@ static bool check_deleted_files(void) | |||
4408 | struct tagfile_entry tfe; | 4400 | struct tagfile_entry tfe; |
4409 | 4401 | ||
4410 | logf("reverse scan..."); | 4402 | logf("reverse scan..."); |
4411 | snprintf(buf, bufsz, TAGCACHE_FILE_INDEX, tag_filename); | ||
4412 | fd = open(buf, O_RDONLY); | ||
4413 | 4403 | ||
4404 | fd = open_pathfmt(O_RDONLY, TAGCACHE_FILE_INDEX, tag_filename); | ||
4414 | if (fd < 0) | 4405 | if (fd < 0) |
4415 | { | 4406 | { |
4416 | logf("%s open fail", buf); | 4407 | logf(TAGCACHE_FILE_INDEX " open fail", tag_filename); |
4417 | return false; | 4408 | return false; |
4418 | } | 4409 | } |
4419 | 4410 | ||