Guard against invalid cache file in a couple more places
This commit is contained in:
parent
f64b4e0e56
commit
f3364cfdc0
@ -165,9 +165,12 @@ size_of_cache_file(DiskCache *self) {
|
|||||||
|
|
||||||
size_t
|
size_t
|
||||||
disk_cache_size_on_disk(PyObject *self) {
|
disk_cache_size_on_disk(PyObject *self) {
|
||||||
|
if (((DiskCache*)self)->cache_file_fd > -1) {
|
||||||
off_t ans = size_of_cache_file((DiskCache*)self);
|
off_t ans = size_of_cache_file((DiskCache*)self);
|
||||||
return MAX(0, ans);
|
return MAX(0, ans);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t hash_key[MAX_KEY_SIZE];
|
uint8_t hash_key[MAX_KEY_SIZE];
|
||||||
@ -362,7 +365,9 @@ write_loop(void *data) {
|
|||||||
continue;
|
continue;
|
||||||
} else if (!count) {
|
} else if (!count) {
|
||||||
mutex(lock);
|
mutex(lock);
|
||||||
|
if (self->cache_file_fd > -1) {
|
||||||
if (ftruncate(self->cache_file_fd, 0) == 0) lseek(self->cache_file_fd, 0, SEEK_END);
|
if (ftruncate(self->cache_file_fd, 0) == 0) lseek(self->cache_file_fd, 0, SEEK_END);
|
||||||
|
}
|
||||||
mutex(unlock);
|
mutex(unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user