Skip to content

Commit

Permalink
Data_read() no longer gives warning messages when reaching the end of…
Browse files Browse the repository at this point in the history
… the cache file.
  • Loading branch information
fangfufu committed Sep 2, 2019
1 parent 127c4ce commit ee397d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.o
*.kate-swp
html
mnt
httpdirfs
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ opened.
- This problem only occurred during the first time you download a file.
During subsequent accesses, when you are only reading from the cache, this
problem did not occur.
- Cache system: Previously it was possible for cache_bgdl()'s download offset
- Cache system: Previously it was possible for Cache_bgdl()'s download offset
to be modified by the parent thread after the child thread had been
launched. This used to cause permanent cache file corruption.
- Cache system: cache_bgdl() no longer prefetches beyond EOF.
- Cache system: Cache_bgdl() no longer prefetches beyond EOF.
- Cache system: Data_read() no longer gives warning messages when reaching the
end of the cache file.

## [1.1.8] - 2019-08-24
### Changed
Expand Down
34 changes: 18 additions & 16 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,23 @@ static long Data_read(Cache *cf, uint8_t *buf, off_t len, off_t offset)
#endif
PTHREAD_MUTEX_LOCK(&cf->seek_lock);

long byte_read = 0;

if (fseeko(cf->dfp, offset, SEEK_SET)) {
/* fseeko failed */
fprintf(stderr, "Data_read(): fseeko(): %s\n", strerror(errno));
byte_read = -EIO;
goto end;
}

#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_read(): thread %lu: unlocking seek_lock;\n",
pthread_self());
#endif
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);

return -EIO;
if (offset + len > cf->content_length) {
len -= offset + len - cf->content_length;
if (len < 0) {
goto end;
}
}

long byte_read = fread(buf, sizeof(uint8_t), len, cf->dfp);
byte_read = fread(buf, sizeof(uint8_t), len, cf->dfp);
if (byte_read != len) {
fprintf(stderr,
"Data_read(): fread(): requested %ld, returned %ld!\n",
Expand All @@ -390,6 +393,7 @@ static long Data_read(Cache *cf, uint8_t *buf, off_t len, off_t offset)
}
}

end:
#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_read(): thread %lu: unlocking seek_lock;\n",
pthread_self());
Expand Down Expand Up @@ -424,19 +428,16 @@ static long Data_write(Cache *cf, const uint8_t *buf, off_t len,
#endif
PTHREAD_MUTEX_LOCK(&cf->seek_lock);

long byte_written = 0;

if (fseeko(cf->dfp, offset, SEEK_SET)) {
/* fseeko failed */
fprintf(stderr, "Data_write(): fseeko(): %s\n", strerror(errno));

#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_write(): thread %lu: unlocking seek_lock;\n",
pthread_self());
#endif
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);
return -EIO;
byte_written = -EIO;
goto end;
}

long byte_written = fwrite(buf, sizeof(uint8_t), len, cf->dfp);
byte_written = fwrite(buf, sizeof(uint8_t), len, cf->dfp);
if (byte_written != len) {
fprintf(stderr,
"Data_write(): fwrite(): requested %ld, returned %ld!\n",
Expand All @@ -448,6 +449,7 @@ static long Data_write(Cache *cf, const uint8_t *buf, off_t len,
}
}

end:
#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_write(): thread %lu: unlocking seek_lock;\n",
pthread_self());
Expand Down

0 comments on commit ee397d1

Please sign in to comment.