Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
imagecache: calculate sha1 for old entries, too
  • Loading branch information
perexg committed Sep 27, 2015
1 parent cac5ce3 commit 78aea5c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/imagecache.c
Expand Up @@ -174,6 +174,25 @@ imagecache_image_add ( imagecache_image_t *img )
}
}

static int
imagecache_update_sha1 ( imagecache_image_t *img,
const char *path )
{
int fd;
uint8_t sha1[20];
sbuf_t sb;

sbuf_init(&sb);
if ((fd = tvh_open(path, O_RDONLY, 0)) < 0)
return 0;
while (sbuf_read(&sb, fd) < 0 && ERRNO_AGAIN(errno));
close(fd);
sha1_calc(sha1, sb.sb_data, sb.sb_ptr, NULL, 0);
memcpy(img->sha1, sha1, 20);
sbuf_free(&sb);
return 1;
}

static int
imagecache_new_contents ( imagecache_image_t *img,
const char *tpath, char *path,
Expand All @@ -185,6 +204,8 @@ imagecache_new_contents ( imagecache_image_t *img,

sha1_calc(sha1, data, dsize, NULL, 0);
empty = sha1_empty(img->sha1);
if (empty && imagecache_update_sha1(img, path))
empty = 0;
if (!empty && memcmp(sha1, img->sha1, 20) == 0)
return 0; /* identical */

Expand Down

0 comments on commit 78aea5c

Please sign in to comment.