Fixed issue #37

If a cache file already exists, the download segment size is set
to the size set by the metadata. The user specified download
segment size is ignored for existing cache files.
This commit is contained in:
Fufu Fang 2019-07-21 17:53:35 +01:00
parent 6aa180db5e
commit ee2d3edcbf
2 changed files with 10 additions and 4 deletions

View File

@ -193,6 +193,10 @@ blksz: %d, segbc: %ld\n", cf->path, cf->content_length, cf->blksz, cf->segbc);
return EZERO;
}
if (cf->blksz != DATA_BLK_SZ) {
fprintf(stderr, "Meta_read(): Warning: cf->blksz != DATA_BLK_SZ\n");
}
/* Allocate some memory for the segment */
if (cf->segbc > MAX_SEGBC) {
fprintf(stderr, "Meta_read(): Error: segbc: %ld\n", cf->segbc);
@ -804,7 +808,7 @@ static void *Cache_bgdl(void *arg)
{
Cache *cf = (Cache *) arg;
pthread_mutex_lock(&cf->rw_lock);
uint8_t *recv_buf = calloc(DATA_BLK_SZ, sizeof(uint8_t));
uint8_t *recv_buf = calloc(cf->blksz, sizeof(uint8_t));
fprintf(stderr, "Cache_bgdl(): ");
long recv = path_download(cf->path, (char *) recv_buf, cf->blksz,
cf->next_offset);
@ -863,7 +867,7 @@ long Cache_read(Cache *cf, char *output_buf, off_t len, off_t offset)
/* ------------------------Download the segment -------------------------*/
uint8_t *recv_buf = calloc(DATA_BLK_SZ, sizeof(uint8_t));
uint8_t *recv_buf = calloc(cf->blksz, sizeof(uint8_t));
fprintf(stderr, "Cache_read(): ");
long recv = path_download(cf->path, (char *) recv_buf, cf->blksz,
dl_offset);

View File

@ -259,8 +259,10 @@ static void print_http_options()
--cache Enable cache, by default this is disabled\n\
--cache-location Set a custom cache location, by default it is \n\
located in ${XDG_CACHE_HOME}/httpdirfs \n\
--dl-seg-size The size of each download segment in MB,\n\
default to 8MB.\n\
--dl-seg-size The download segment size in MB for the cache,\n\
default to 8MB. Note that specifying download\n\
segment size for existing cache file will not be\n\
honoured. \n\
--max-seg-count The maximum number of download segments a file\n\
can have. By default it is set to 128*1024. This\n\
means the maximum memory usage per file is 128KB.\n\