src/lib/cache.c
changeset 8 400ddf1e7aa9
parent 7 997906f5fd2d
child 9 a31048ff76a2
equal deleted inserted replaced
7:997906f5fd2d 8:400ddf1e7aa9
    53     *cache_ptr = cache;
    53     *cache_ptr = cache;
    54 
    54 
    55     return 0;
    55     return 0;
    56 }
    56 }
    57 
    57 
    58 int pt_cache_stale (struct pt_cache *cache, const char *img_path)
    58 int pt_cache_status (struct pt_cache *cache, const char *img_path)
    59 {
    59 {
    60     struct stat st_img, st_cache;
    60     struct stat st_img, st_cache;
    61     
    61     
    62     // test original file
    62     // test original file
    63     if (stat(img_path, &st_img) < 0)
    63     if (stat(img_path, &st_img) < 0)
    65     
    65     
    66     // test cache file
    66     // test cache file
    67     if (stat(cache->path, &st_cache) < 0) {
    67     if (stat(cache->path, &st_cache) < 0) {
    68         // always stale if it doesn't exist yet
    68         // always stale if it doesn't exist yet
    69         if (errno == ENOENT)
    69         if (errno == ENOENT)
    70             return 1;
    70             return PT_CACHE_NONE;
    71         else
    71         else
    72             return -1;
    72             return -1;
    73     }
    73     }
    74 
    74 
    75     // compare mtime
    75     // compare mtime
    76     return (st_img.st_mtime > st_cache.st_mtime);
    76     if (st_img.st_mtime > st_cache.st_mtime)
       
    77         return PT_CACHE_STALE;
       
    78 
       
    79     else
       
    80         return PT_CACHE_FRESH;
    77 }
    81 }
    78 
    82 
    79 /**
    83 /**
    80  * Abort any incomplete open operation, cleaning up
    84  * Abort any incomplete open operation, cleaning up
    81  */
    85  */