Changeset 5115:8082e4c9f524

Show
Ignore:
Timestamp:
2007-04-10 17:40:11 (21 months ago)
Author:
Brendan Cully <brendan@…>
Branch:
HEAD
Message:

Make IMAP header cache layout match body cache.
You can now make them point to the same directory. Each folder will
have a folder.hcache file for the header cache.

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • hcache.c

    r5114 r5115  
    468468                       hcache_namer_t namer) 
    469469{ 
    470   static char mutt_hcache_per_folder_path[_POSIX_PATH_MAX]; 
    471   struct stat path_stat; 
     470  static char hcpath[_POSIX_PATH_MAX]; 
     471  struct stat sb; 
    472472  MD5_CTX md5; 
    473473  unsigned char md5sum[16]; 
    474   int ret; 
    475  
    476   ret = stat(path, &path_stat); 
    477   if (ret < 0) 
     474  char* s; 
     475  int ret, plen; 
     476 
     477  plen = mutt_strlen (path); 
     478 
     479  ret = stat(path, &sb); 
     480  if (ret < 0 && path[plen-1] != '/') 
    478481    return path; 
    479482 
    480   if (!S_ISDIR(path_stat.st_mode)) 
     483  if (ret >= 0 && !S_ISDIR(sb.st_mode)) 
    481484    return path; 
    482485 
    483   MD5Init(&md5); 
    484   MD5Update(&md5, (unsigned char *) folder, strlen(folder)); 
    485   MD5Final(md5sum, &md5); 
    486  
    487   ret = snprintf(mutt_hcache_per_folder_path, _POSIX_PATH_MAX, 
    488                  "%s/%02x%02x%02x%02x%02x%02x%02x%02x" 
    489                  "%02x%02x%02x%02x%02x%02x%02x%02x", 
    490                  path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], 
    491                  md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], 
    492                  md5sum[9], md5sum[10], md5sum[11], md5sum[12], 
    493                  md5sum[13], md5sum[14], md5sum[15]); 
    494  
     486  if (namer) 
     487  { 
     488    snprintf (hcpath, sizeof (hcpath), "%s%s", path, 
     489              path[plen-1] == '/' ? "" : "/"); 
     490    if (path[plen-1] != '/') 
     491      plen++; 
     492 
     493    ret = namer (folder, hcpath + plen, sizeof (hcpath) - plen); 
     494  } 
     495  else 
     496  { 
     497    MD5Init(&md5); 
     498    MD5Update(&md5, (unsigned char *) folder, strlen(folder)); 
     499    MD5Final(md5sum, &md5); 
     500 
     501    ret = snprintf(hcpath, _POSIX_PATH_MAX, 
     502                   "%s/%02x%02x%02x%02x%02x%02x%02x%02x" 
     503                   "%02x%02x%02x%02x%02x%02x%02x%02x", 
     504                   path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], 
     505                   md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], 
     506                   md5sum[9], md5sum[10], md5sum[11], md5sum[12], 
     507                   md5sum[13], md5sum[14], md5sum[15]); 
     508  } 
     509   
    495510  if (ret <= 0) 
    496511    return path; 
    497512 
    498   return mutt_hcache_per_folder_path; 
     513  s = strchr (hcpath + 1, '/'); 
     514  while (s) 
     515  { 
     516    /* create missing path components */ 
     517    *s = '\0'; 
     518    if (stat (hcpath, &sb) < 0 && (errno != ENOENT || mkdir (hcpath, 0777) < 0)) 
     519      return path; 
     520    *s = '/'; 
     521    s = strchr (s + 1, '/'); 
     522  } 
     523 
     524  return hcpath; 
    499525} 
    500526 
  • imap/imap.c

    r5114 r5115  
    250250 
    251251#ifdef USE_HCACHE 
    252   imap_hcache_open (idata); 
     252  idata->hcache = imap_hcache_open (idata, NULL); 
    253253#endif 
    254254 
     
    11471147 
    11481148#if USE_HCACHE 
    1149   imap_hcache_open (idata); 
     1149  idata->hcache = imap_hcache_open (idata, NULL); 
    11501150#endif 
    11511151 
     
    15701570  ciss_url_t url; 
    15711571  char urlstr[LONG_STRING]; 
     1572  char cpath[LONG_STRING]; 
    15721573  unsigned int *uidvalidity = NULL; 
    15731574  unsigned int *uidnext = NULL; 
     
    15951596 
    15961597#ifdef USE_HCACHE 
    1597   mutt_account_tourl (&idata->conn->account, &url); 
    1598   url.path = (char*)mbox; 
    1599   url_ciss_tostring (&url, urlstr, sizeof (urlstr), 0); 
    1600   hc = mutt_hcache_open (HeaderCache, urlstr, NULL); 
     1598  hc = imap_hcache_open (idata, mbox); 
    16011599  if (hc) 
    16021600  { 
  • imap/imap_private.h

    r5112 r5115  
    260260/* util.c */ 
    261261#ifdef USE_HCACHE 
    262 int imap_hcache_open (IMAP_DATA* idata); 
     262header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path); 
    263263void imap_hcache_close (IMAP_DATA* idata); 
    264264HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid); 
     
    273273char* imap_fix_path (IMAP_DATA* idata, char* mailbox, char* path,  
    274274  size_t plen); 
     275void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, 
     276                    size_t dlen); 
    275277int imap_get_literal_count (const char* buf, long* bytes); 
    276278char* imap_get_qualifier (char* buf); 
  • imap/message.c

    r5112 r5115  
    120120 
    121121#if USE_HCACHE 
    122   imap_hcache_open (idata); 
     122  idata->hcache = imap_hcache_open (idata, NULL); 
    123123 
    124124  if (idata->hcache && !msgbegin) 
     
    848848static body_cache_t *msg_cache_open (IMAP_DATA *idata) 
    849849{ 
    850   char *s; 
    851   char *p = idata->mailbox; 
    852850  char mailbox[_POSIX_PATH_MAX]; 
    853   size_t mlen = sizeof (mailbox); 
    854851 
    855852  if (idata->bcache) 
    856853    return idata->bcache; 
    857854 
    858   mailbox[0] = '\0'; 
    859  
    860   for (s = mailbox; p && *p && mlen; mlen--) 
    861   { 
    862     if (*p == idata->delim) 
    863     { 
    864       *s = '/'; 
    865       /* simple way to avoid collisions with UIDs */ 
    866       if (*(p + 1) >= '0' && *(p + 1) <= '9') 
    867       { 
    868         mlen--; 
    869         if (mlen) 
    870           *++s = '_'; 
    871       } 
    872     } 
    873     else 
    874       *s = *p; 
    875     p++; 
    876     s++; 
    877   } 
    878   *s = '\0'; 
     855  imap_cachepath (idata, idata->mailbox, mailbox, sizeof (mailbox)); 
    879856 
    880857  return mutt_bcache_open (&idata->conn->account, mailbox); 
  • imap/util.c

    r5114 r5115  
    7272 
    7373#ifdef USE_HCACHE 
    74 int imap_hcache_open (IMAP_DATA* idata) 
     74static int imap_hcache_namer (const char* path, char* dest, size_t dlen) 
     75{ 
     76  return snprintf (dest, dlen, "%s.hcache", path); 
     77} 
     78 
     79header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path) 
    7580{ 
    7681  IMAP_MBOX mx; 
    7782  ciss_url_t url; 
    7883  char cachepath[LONG_STRING]; 
     84  char mbox[LONG_STRING]; 
    7985 
    8086  if (imap_parse_path (idata->ctx->path, &mx) < 0) 
    8187    return -1; 
    8288 
     89  if (path) 
     90    imap_cachepath (idata, path, mbox, sizeof (mbox)); 
     91  else 
     92  { 
     93    imap_cachepath (idata, mx.mbox, mbox, sizeof (mbox)); 
     94    FREE (&mx.mbox); 
     95  } 
     96 
    8397  mutt_account_tourl (&idata->conn->account, &url); 
    84   url.path = mx.mbox; 
    85   url_ciss_tostring (&url, cachepath, sizeof (cachepath), 0); 
    86   FREE (&mx.mbox); 
    87  
    88   idata->hcache = mutt_hcache_open (HeaderCache, cachepath, NULL); 
    89  
    90   return idata->hcache != NULL ? 0 : -1; 
     98  url.path = mbox; 
     99  url_ciss_tostring (&url, cachepath, sizeof (cachepath), U_PATH); 
     100 
     101  return mutt_hcache_open (HeaderCache, cachepath, imap_hcache_namer); 
    91102} 
    92103 
     
    397408 
    398409  return path; 
     410} 
     411 
     412void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, 
     413                    size_t dlen) 
     414{ 
     415  char* s; 
     416  const char* p = mailbox; 
     417 
     418  for (s = dest; p && *p && dlen; dlen--) 
     419  { 
     420    if (*p == idata->delim) 
     421    { 
     422      *s = '/'; 
     423      /* simple way to avoid collisions with UIDs */ 
     424      if (*(p + 1) >= '0' && *(p + 1) <= '9') 
     425      { 
     426        if (--dlen) 
     427          *++s = '_'; 
     428      } 
     429    } 
     430    else 
     431      *s = *p; 
     432    p++; 
     433    s++; 
     434  } 
     435  *s = '\0'; 
    399436} 
    400437