Skip to content

Commit

Permalink
lib-fs: Added internal fs_metadata_find() helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Oct 17, 2016
1 parent c4fc984 commit e11fd32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/lib-fs/fs-api-private.h
Expand Up @@ -168,6 +168,8 @@ void fs_metadata_init(struct fs_file *file);
void fs_metadata_init_or_clear(struct fs_file *file);
void fs_default_set_metadata(struct fs_file *file,
const char *key, const char *value);
const char *fs_metadata_find(const ARRAY_TYPE(fs_metadata) *metadata,
const char *key);
int fs_default_copy(struct fs_file *src, struct fs_file *dest);

void fs_file_timing_end(struct fs_file *file, enum fs_op op);
Expand Down
26 changes: 17 additions & 9 deletions src/lib-fs/fs-api.c
Expand Up @@ -323,6 +323,21 @@ void fs_default_set_metadata(struct fs_file *file,
metadata->value = p_strdup(file->metadata_pool, value);
}

const char *fs_metadata_find(const ARRAY_TYPE(fs_metadata) *metadata,
const char *key)
{
const struct fs_metadata *md;

if (array_is_created(metadata))
return NULL;

array_foreach(metadata, md) {
if (strcmp(md->key, key) == 0)
return md->value;
}
return NULL;
}

void fs_set_metadata(struct fs_file *file, const char *key, const char *value)
{
i_assert(key != NULL);
Expand Down Expand Up @@ -403,18 +418,11 @@ int fs_lookup_metadata(struct fs_file *file, const char *key,
const char **value_r)
{
const ARRAY_TYPE(fs_metadata) *metadata;
const struct fs_metadata *md;

if (fs_get_metadata(file, &metadata) < 0)
return -1;
array_foreach(metadata, md) {
if (strcmp(md->key, key) == 0) {
*value_r = md->value;
return 1;
}
}
*value_r = NULL;
return 0;
*value_r = fs_metadata_find(metadata, key);
return *value_r != NULL ? 1 : 0;
}

const char *fs_file_path(struct fs_file *file)
Expand Down

0 comments on commit e11fd32

Please sign in to comment.