Changeset 109

Show
Ignore:
Timestamp:
02/05/06 09:23:32 (3 years ago)
Author:
conrad
Message:

check if the cachefile is stale before using, remove if stale

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fastphoto/trunk/src/cache.c

    r108 r109  
    4545 
    4646static int 
    47 cache_check (fastphoto_t * params, char * cachefile) 
     47file_check (char * filename, time_t * mtime) 
    4848{ 
    4949    struct stat statbuf; 
    5050 
    51     if (stat (cachefile, &statbuf) == -1) { 
     51    if (stat (filename, &statbuf) == -1) { 
    5252        switch (errno) { 
    5353            case ENOENT: 
    5454                return 0; 
    5555            default: 
    56                 fprintf (stderr, "fastphoto: Error checking %s; %s\n", cachefile, strerror (errno)); 
     56                fprintf (stderr, "fastphoto: Error checking %s: %s\n", filename, strerror (errno)); 
    5757                return -1; 
    5858        } 
     59    } 
     60 
     61    *mtime = statbuf.st_mtime; 
     62 
     63    return 1; 
     64} 
     65 
     66static int 
     67cache_check (fastphoto_t * params, char * cachefile) 
     68{ 
     69    time_t orig_mtime, cache_mtime; 
     70    int ret; 
     71 
     72    if ((ret = file_check (cachefile, &cache_mtime)) != 1) { 
     73        return ret; 
     74    } 
     75 
     76    if ((ret = file_check (params->infile, &orig_mtime)) != 1) { 
     77        return ret; 
     78    } 
     79 
     80    if (orig_mtime > cache_mtime) { 
     81        fprintf (stderr, "fastphoto: Removing stale cachefile %s\n", cachefile); 
     82        unlink (cachefile); 
     83        return 0; 
    5984    } 
    6085