enum file_lock_method lock_method;
char *path;
+ char *home_dir;
+ bool dict_path_checked;
HASH_TABLE(char *, char *) hash;
int fd;
.use_io_notify = TRUE
};
+static int
+file_dict_ensure_path_home_dir(struct file_dict *dict, const char *home_dir,
+ const char **error_r)
+{
+ if (null_strcmp(dict->home_dir, home_dir) == 0)
+ return 0;
+
+ if (dict->dict_path_checked) {
+ *error_r = t_strdup_printf("home_dir changed from %s to %s "
+ "(requested dict was: %s)", dict->home_dir,
+ home_dir, dict->path);
+ return -1;
+ }
+
+ char *_p = dict->path;
+ dict->path = i_strdup(home_expand_tilde(dict->path, home_dir));
+ dict->home_dir = i_strdup(home_dir);
+ i_free(_p);
+ dict->dict_path_checked = TRUE;
+ return 0;
+}
+
static int
file_dict_init(struct dict *driver, const char *uri,
const struct dict_settings *set ATTR_UNUSED,
return -1;
}
}
+
+ /* keep the path for now, later in dict operations check if home_dir
+ should be prepended. */
+ dict->path = i_strdup(path);
+
dict->dict = *driver;
dict->hash_pool = pool_alloconly_create("file dict", 1024);
hash_table_create(&dict->hash, dict->hash_pool, 0, str_hash, strcmp);
hash_table_destroy(&dict->hash);
pool_unref(&dict->hash_pool);
i_free(dict->path);
+ i_free(dict->home_dir);
i_free(dict);
}
}
static int file_dict_lookup(struct dict *_dict,
- const struct dict_op_settings *set ATTR_UNUSED,
+ const struct dict_op_settings *set,
pool_t pool, const char *key,
const char **value_r, const char **error_r)
{
struct file_dict *dict = (struct file_dict *)_dict;
+ if (file_dict_ensure_path_home_dir(dict, set->home_dir, error_r) < 0)
+ return -1;
+
if (file_dict_refresh(dict, error_r) < 0)
return -1;
ctx->path_len = strlen(path);
ctx->flags = flags;
- if (file_dict_refresh(dict, &error) < 0)
+ if (file_dict_ensure_path_home_dir(dict, set->home_dir, &error) < 0 ||
+ file_dict_refresh(dict, &error) < 0)
ctx->error = p_strdup(pool, error);
ctx->iter = hash_table_iterate_init(dict->hash);
*atomic_inc_not_found_r = FALSE;
+ if (file_dict_ensure_path_home_dir(dict, ctx->ctx.set.home_dir, error_r) < 0)
+ return -1;
+
switch (dict->lock_method) {
case FILE_LOCK_METHOD_FCNTL:
case FILE_LOCK_METHOD_FLOCK: