* mu-store-read.cc: use realpath when determining path, getting rid of
e.g. /foo//bar double slashes
This commit is contained in:
@ -26,6 +26,9 @@
|
|||||||
#include <xapian.h>
|
#include <xapian.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "mu-store.h"
|
#include "mu-store.h"
|
||||||
#include "mu-store-priv.hh" /* _MuStore */
|
#include "mu-store-priv.hh" /* _MuStore */
|
||||||
@ -46,20 +49,30 @@ _MuStore::get_uid_term (const char* path)
|
|||||||
{
|
{
|
||||||
// combination of DJB, BKDR hash functions to get a 64 bit
|
// combination of DJB, BKDR hash functions to get a 64 bit
|
||||||
// value
|
// value
|
||||||
|
|
||||||
unsigned djbhash, bkdrhash, bkdrseed;
|
unsigned djbhash, bkdrhash, bkdrseed;
|
||||||
unsigned u;
|
unsigned u;
|
||||||
|
|
||||||
|
char real_path[PATH_MAX + 1];
|
||||||
static char hex[18];
|
static char hex[18];
|
||||||
static const char uid_prefix =
|
static const char uid_prefix =
|
||||||
mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_UID);
|
mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_UID);
|
||||||
|
|
||||||
|
/* check profile to see if realpath is expensive; we need
|
||||||
|
* realpath here (and in mu-msg-file) to ensure that the same
|
||||||
|
* messages are only considered ones (ignore e.g. symlinks and
|
||||||
|
* '//' in paths) */
|
||||||
|
if (!realpath (path, real_path)) {
|
||||||
|
g_warning ("realpath() failed: %s", strerror (errno));
|
||||||
|
strcpy (real_path, path); /* ignore errors */
|
||||||
|
}
|
||||||
|
|
||||||
djbhash = 5381;
|
djbhash = 5381;
|
||||||
bkdrhash = 0;
|
bkdrhash = 0;
|
||||||
bkdrseed = 1313;
|
bkdrseed = 1313;
|
||||||
|
|
||||||
for(u = 0; path[u]; ++u) {
|
for(u = 0; real_path[u]; ++u) {
|
||||||
djbhash = ((djbhash << 5) + djbhash) + path[u];
|
djbhash = ((djbhash << 5) + djbhash) + real_path[u];
|
||||||
bkdrhash = bkdrhash * bkdrseed + path[u];
|
bkdrhash = bkdrhash * bkdrseed + real_path[u];
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf (hex, sizeof(hex), "%c%08x%08x",
|
snprintf (hex, sizeof(hex), "%c%08x%08x",
|
||||||
|
|||||||
Reference in New Issue
Block a user