git-svn: trunk@3458
Trog authored on 2007/12/27 23:58:32... | ... |
@@ -419,7 +419,7 @@ static int prepare_file(int fd, chm_metadata_t *metadata) |
419 | 419 |
{ |
420 | 420 |
uint64_t name_len, section; |
421 | 421 |
|
422 |
- while (metadata->chunk_entries--) { |
|
422 |
+ while (metadata->chunk_entries != 0) { |
|
423 | 423 |
if (metadata->chunk_current >= metadata->chunk_end) { |
424 | 424 |
return CL_EFORMAT; |
425 | 425 |
} |
... | ... |
@@ -433,7 +433,8 @@ static int prepare_file(int fd, chm_metadata_t *metadata) |
433 | 433 |
metadata->chunk_current += name_len; |
434 | 434 |
section = read_enc_int(&metadata->chunk_current, metadata->chunk_end); |
435 | 435 |
metadata->file_offset = read_enc_int(&metadata->chunk_current, metadata->chunk_end); |
436 |
- metadata->file_length = read_enc_int(&metadata->chunk_current, metadata->chunk_end); |
|
436 |
+ metadata->file_length = read_enc_int(&metadata->chunk_current, metadata->chunk_end); |
|
437 |
+ metadata->chunk_entries--; |
|
437 | 438 |
if (section == 1) { |
438 | 439 |
return CL_SUCCESS; |
439 | 440 |
} |
... | ... |
@@ -836,16 +837,20 @@ int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata) |
836 | 836 |
|
837 | 837 |
cli_dbgmsg("in cli_chm_prepare_file\n"); |
838 | 838 |
|
839 |
- if (metadata->chunk_entries == 0) { |
|
840 |
- if (metadata->num_chunks == 0) { |
|
841 |
- return CL_BREAK; |
|
842 |
- } |
|
843 |
- if ((retval = read_chunk(metadata, fd)) != CL_SUCCESS) { |
|
844 |
- return retval; |
|
839 |
+ do { |
|
840 |
+ if (metadata->chunk_entries == 0) { |
|
841 |
+ if (metadata->num_chunks == 0) { |
|
842 |
+ return CL_BREAK; |
|
843 |
+ } |
|
844 |
+ if ((retval = read_chunk(metadata, fd)) != CL_SUCCESS) { |
|
845 |
+ return retval; |
|
846 |
+ } |
|
847 |
+ metadata->num_chunks--; |
|
848 |
+ metadata->chunk_offset += metadata->itsp_hdr.block_len; |
|
845 | 849 |
} |
846 |
- } |
|
847 |
- |
|
848 |
- return prepare_file(fd, metadata); |
|
850 |
+ retval = prepare_file(fd, metadata); |
|
851 |
+ } while (retval == CL_BREAK); /* Ran out of chunk entries before finding a file */ |
|
852 |
+ return retval; |
|
849 | 853 |
} |
850 | 854 |
|
851 | 855 |
int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata) |