Exemple #1
0
static void tags_cache_add (struct tags_cache *c, const char *file,
                                  DBT *key, struct file_tags *tags)
{
	char *serialized_cache_rec;
	int serial_len;
	struct cache_record rec;
	DBT data;
	int ret;

	assert (tags != NULL);

	debug ("Adding/updating cache object");

	rec.mod_time = get_mtime (file);
	rec.atime = time (NULL);
	rec.tags = tags;

	serialized_cache_rec = cache_record_serialize (&rec, &serial_len);
	if (!serialized_cache_rec)
		return;

	memset (&data, 0, sizeof(data));
	data.data = serialized_cache_rec;
	data.size = serial_len;

	tags_cache_gc (c);

	ret = c->db->put (c->db, NULL, key, &data, 0);
	if (ret)
		error ("DB put error: %s", db_strerror (ret));

	tags_cache_sync (c);

	free (serialized_cache_rec);
}
Exemple #2
0
/* Add this tags object for the file to the cache. */
static void tags_cache_add (struct tags_cache *c, const char *file,
		struct file_tags *tags)
{
	char *serialized_cache_rec;
	int serial_len;
	struct cache_record rec;
	DBT key;
	DBT data;
	int ret;

	assert (c != NULL);
	assert (tags != NULL);
	assert (file != NULL);

	rec.mod_time = get_mtime (file);
	rec.atime = time (NULL);
	rec.tags = tags;

	serialized_cache_rec = cache_record_serialize (&rec, &serial_len);
	if (!serialized_cache_rec)
		return;

	memset (&key, 0, sizeof(key));
	memset (&data, 0, sizeof(data));

	key.data = (void *)file;
	key.size = strlen(file);

	data.data = serialized_cache_rec;
	data.size = serial_len;

	tags_cache_gc  (c);

	ret = c->db->put (c->db, NULL, &key, &data, 0);
	if (ret) {
		logit ("DB put error: %s", db_strerror(ret));
	}

	free (serialized_cache_rec);
}